Remove Old Kernels on CentOS

Keeping a few Linux kernels installed is not a bad idea.  If you install a new kernel and for some reason it breaks something else you may have installed or it corrupts itself, having another kernel on hand to revert to can be a huge help.  There is a simple way to uninstall unused and undesirable kernels as well as keep the number that will be kept to a lower limit.

To see how many kernels are presently installed on your system.

[jhudgins@p2vm-sys-ppmail ~]$ rpm -q kernel

The yum-utils package will allow you to quickly remove unnecessary kernels.

[jhudgins@p2vm-sys-ppmail ~]$ sudo yum install yum-utils

I want to always have two working kernels installed on my machines.  In order to keep two, I would use the following command to remove all but the two latest kernels.

[jhudgins@p2vm-sys-ppmail ~]$ sudo package-cleanup --oldkernels --count=2

And to verify I only have two installed kernels.

[jhudgins@p2vm-sys-ppmail ~]$ rpm -q kernel

To permanently adjust the number of kernels to be installed on your machine you can modify the /etc/yum.conf file as follows.




jhudgins has written 31 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>