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.