Remove Old Kernels on Red Hat

  Linux

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
kernel-3.10.0-327.el7.x86_64
kernel-3.10.0-514.16.1.el7.x86_64
kernel-3.10.0-514.21.1.el7.x86_64

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
kernel-3.10.0-514.16.1.el7.x86_64
kernel-3.10.0-514.21.1.el7.x86_64

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

installonly_limit=2

 

 

LEAVE A COMMENT