purge-old-kernels – safe way to remove old kernels

purge-old-kernels - safe way to remove old kernels

Every month are new kernel updates, bug fixes and patches security system. If you regularly update your system, then your system gradually accumulates more the number of unused old kernels.

Thus, it is likely that the boot partition /boot on the hard drive will be filled in a certain period of time. If your /boot partition is full, you will not be able to upgrade, or can’t even do a kernel upgrade to any latest available version. In this case, it is very important to regularly update the kernel and software. For this you must have enough free space in the /boot partition. To system to function correctly, you must have enough free space on the /boot and /root partitions.
We can easily remove the accumulated system cache, unwanted packages and dependencies using the following commands:

sudo apt-get autoremove
sudo apt-get autoclean
But the problem is that this works only if the kernel was installed automatically, or if you installed them using the Update Manager. Using these commands will not delete the kernel manually installed. However, you can use some third-party programs such as Ubuntu Tweak (This project is no longer under maintenance) for the safe disposal of unused cores, packages and their dependencies that are no longer needed. But Ubuntu Tweak is a graphical program which cannot be used on servers without a graphical mode.
One of the developers of Ubuntu, Dustin Kirkland, responsible for the development and the product strategy was created utility purge-old-kernels, which is the safest way removes from the system the unused kernel packages of desktop and server systems, Ubuntu and therefore Linux Mint.
Installation latest version into Linux Mint:
sudo apt-get install -y bikeshed byobu
Now, to remove old, unused kernels, run in terminal the following command:
sudo purge-old-kernels

purge-old-kernels - safe way to remove old kernels

If there is no older kernels in your system, this utility will display the following message:

purge-old-kernels - safe way to remove old kernels

The safety of the use of this utility is that it will never remove the last installed kernel, or rather, utility purge-old-kernels removes all the unused kernels, except for the last TWO – the current and the previous. But the user can override this value using the option –keep.
For example, to remove all old kernels except the 3 last, run the following command:

sudo purge-old-kernels --keep 3 -qy
For more information about purge-old-kernels, see the user manual:
man purge-old-kernels
Good Luck!!!

Share to friends
Rate author
( 3 assessment, average 5 from 5 )
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
2022 years ago

Thanks, excellent.

technosoft gratis
technosoft gratis
2022 years ago

At least on my ubuntu server 16, you don't need bikeshed. I prefer:
sudo apt-get install byobu

"bikeshed" installs a lot of packages. "byobu" install less and "purge-old-kernels" is also included

2022 years ago

I install Mint 19, but bikeshed and byobu are not part of the software.

2022 years ago

@Bernard: I just installed byobu on Mint 18.3 and had a look at the purge-old-kernels script: cat $(which purge-old-kernels). I pasted it as a gitlab snippet here:


You don't need byobu to run this.

@Bernard hm.. I just found it elsewhere and it says, that it is not needed anymore, since apt autoremove now does the job: https://github.com/dustinkirkland/byobu/blob/0a44bf215883cedac2f555ad7c6cc6feb43b4063/usr/bin/purge-old-kernels