Yum remove old kernels on CentOS

By | November 16, 2015
ilovebash

ilovebash

Yum remove old kernels on CentOS

Here is a quick guide to managing and automatically tidying your kernels on CentOS.

Background

It is generally accepted that keeping up to date with the latest releases of kernel is one of the best ways to ensure security vulnerabilities are patched as fast as possible. Whether you then decide to automatically schedule kernel (and other packages) updates or not is up to you. Personally I take the view that I want to know exactly what has changed on my servers at any given time therefore any updates I will do manually.

On Centos yum is used to install, update or remove core packages and this is used to also control your old kernels.

Kernel updates are normally stored in your /boot filesystem. This maybe combined with your root filesystem, or fairly often you will see administrators build a small seperate /boot filesystem just for this purpose. One reason for this could just be for some cautious disk management. Whatever the case if you are experiencing space problems in boot partition then you will want to fix it!

Check Installed Kernels

To view your currently installed kernels do this :

# rpm -q kernel
kernel-2.6.32-358.18.1.el6.x86_64
kernel-2.6.32-431.3.1.el6.x86_64
kernel-2.6.32-431.17.1.el6.x86_64
kernel-2.6.32-504.8.1.el6.x86_64
kernel-2.6.32-504.16.2.el6.x86_64
#

Yum remove individual kernel

You can remove a specific kernel manually (if for example you know it affects your server badly in some way) like this :

yum remove kernel-2.6.32-431.17.1.el6.x86_64

Manually removing old kernels to keep a specific number

There is a yum utility that you can use to manually keep 2 newest kernels. First install it (if it is not there already) :

Check out -  How to stop people trying to hack your root logon

yum install yum-utils

Then you can tidy your old kernels for example to 2 using this :

package-cleanup --oldkernels --count=2

Automating removing old kernels

To further automate the process to only keep 2 old kernels you can make the amount of installed kernels permanent by editing /etc/yum.conf and set installonly_limit like this :

installonly_limit=2

If you found this tutorial useful then please share it on Facebook ok Twitter. Also check my other Linux tutorials which may also be of use to you HERE

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.