Do you know that during the installation of a new kernel in Ubuntu, the old one is not deleted, but remains in the system? Over time, the number of old kernels increases and can take up quite a bit of the hard disk space. In some cases,
autoremove can help (that is:
sudo apt-get autoremove), it is intended to clean the system of unused packages, but it is not always effective with respect to kernel files.
autoremove command may not work for older kernels if you use the version of Ubuntu that is under development or the kernel you want to uninstall was installed manually. Also, you can find a bug when the kernels are not marked for automatic deletion.
You can, of course, use utilities such as Ubuntu Tweak or special commands of 150 characters (which you will never remember), but even with their use, no one is immune to errors. So is there any safe way to clean up Ubuntu from old kernels? Yes, this is purge-old-kernels script from Dustin Kirkland (one of the developers of the distribution).
According to the man page
purge-old-kernels is a program (script) that can safely clean Ubuntu from old kernels. By default, the program removes everything except the two most recent cores. Thus, in the event of any errors with one, you will be able to boot the system with a different kernel, more stable.
In Ubuntu 16.04 purge-old-kernels goes as part of the package
byobu so to use the script, you need to install this package:
sudo apt-get install byobu
In older versions of Ubuntu, the script is part of the
bikeshed package. Installation:
sudo apt-get install bikeshed
Now, in order to clean the system of old cores it is enough to enter in the terminal:
If you want to keep a different number of cores in the system, you need to use the
keep key to do this. For example, if I want 3 kernels to be left after cleaning, the command will look like this:
sudo purge-old-kernels --keep 3 -qy
That’s it. This is what I wanted to tell in this article. I hope you this information will help.