How to remove old kernels in Debian

Debian Stretch

Users who have and use Debian for a long time will have noticed how in their operating system asked for kernel update or if they want to remove kernels. Many of you will be puzzled by such a situation and others will wonder if their operating system will stop working if they remove an old kernel.

With this article we want to help you solve these doubts as well as optimize your Debian distribution, removing packages that are not necessary within the distribution and that may cause future problems with new programs or packages.

The foundation of every Gnu / Linux distribution is the Linux kernel. Hence the name is Linux and not just GNU. Every so often, distributions update or release a new kernel version that fixes a bug or is the latest version that the Kernel team has released. When we install the latest version, Debian leaves the old kernel and loads the new kernel.

As time goes by, we can get to have ten or twenty new versions of the kernel that only takes up space on your hard drive and may cause future problems. Usually we only need one kernel version, although for security, there are usually two versions, one that works without any problem and the latest version.

To eliminate the old kernels, first we have to know which version we use, for this we open the terminal and write the following:

uname -sr

This will tell us the version of the kernel we are using. Now we have to look at how many kernels we have installed in our Debian, for this we write the following in the terminal:

dpkg -l | grep linux-image | awk '{print$2}'

Esto it will show us all the installed kernels. Now we have to choose the kernels to remove and do it as follows:

sudo apt remove --purge linux-image-X.XX-X-generic
sudo update-grub2
sudo reboot

This will be with each version of the kernel that we want to remove. If we want to do it automatically, there is a program called byobu which will do it automatically. To do this, we must first install it as follows:

sudo apt install byobu

And then run it as follows:

sudo purge-old-kernels --keep 2

This will remove all old kernels and leave only two versions for safety. As you can see, the system is simple and will not only improve the performance of the distribution but also you will have more space for your packages or files.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

5 comments, leave yours

Leave a Comment

Your email address will not be published.



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Chaparral said

    I only have one kernel on my Debian system: uname -sr
    Linux 4.9.0-3-amd64.
    I installed Debian kde a few weeks ago (lsb_release -a
    No LSB Modules ARE Available.
    Distributor ID: Debian
    Description: Debian GNU / Linux 9.1 (stretch)
    Release: 9.1
    Codename: stretch) and it works perfectly. It is not updated and it is not necessary either. I see that there are already systems with kernel 4.12 but Debian is impassive and works with very short but very safe steps.

    In any case, the information in the post is excellent to take it into account when the precise circumstances arise, for which I thank its author.

  2.   joseph said

    The same would apply to a fedora ?. Thanks

  3.   Gerson said

    I would like to know your opinion about MX_Linux, the distribution that is making a big difference.

  4.   VM said

    Thank you very good article

  5.   Rafa said

    Try to uninstall a kernel as you explain it with byobu and you will see that it does nothing at all. You would know if you had taken the time to test it and not just copy it from another page where they explain it the same, and it doesn't work anyway. You do a lot of damage to Linux with this.

bool (true)