REMOVE OLD UNUSED KERNELS ON CENTOS LINUX

unused kernels
Under normal circumstances, the number of installed and unused kernels does not affect the server’s performance. However, removing old unused kernels will free some disk space. If your server is configured with a separate /boot partition and you run into an issue with low disk space, removing unused kernels will provide a remedy.

Check for current Kernel

First, check what kernel is currently used by your server:

# uname -a
Linux localhost.localdomain 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

List all installed kernels

In this step we will list all currently installed kernels:

# rpm -q kernel
kernel-3.10.0-327.36.3.el7.x86_64
kernel-3.10.0-514.2.2.el7.x86_64
kernel-3.10.0-693.5.2.el7.x86_64

Kernelkernel-3.10.0-693.5.2.el7.x86_64 is currently loaded and used. based on the about output this is the latest version.

Remove old kernels manually

At this stage we can use yum command to manually remove unused Linux kernels:

Remove old unused kernel automatically

Using package-cleanup command which is a part of yum-utilspackage we can uninstall any number of old kernels automatically. As an example using --oldkernels --count=2option with package-cleanup command the command will remove all unused kernel while keeping last three most recent kernel versions installed.

Let’s remove all kernels expect the latest currently loaded kernel:

Configure yum to auto-remove old kernels

By default, CentOS will keep last 5 kernels installed on your system. This behavior is defined by installonly_limit=5 line within /etc/yum.conffile. Update the /etc/yum.conf configuration file appropriately to keep desired number of old kernels on your system after update. The minimum value to be set is 2. Example of the /etc/yum.confconfiguration file to keep only last two kernel versions:

Leave a Reply

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