Clean up older installed kernels on CentOS

Clean up older installed kernels on CentOS

Linux (the Redhat flavor at least) generally keeps multiple versions of the kernel installed. This is done to maintain backwards stability and allow the selection of an older (tried and tested) kernel if the latest update fails in any way.

On a small system all these kernel versions can quickly add up and waste valuable space. In such case keeping only the needed versions (the latest and the one currently booted, if different) is an acceptable risk to take.

List installed kernels

One can easily list all installed kernel packages with:
yum list kernel

Yum underlines the kernel that’s currently running (and will not uninstall it).

Install the tools

To clean up we use a tool that’s not installed by default on most system but is available in the yum-utils package:

yum install yum-utils

Cleanup

Once this is done we can perform the cleanup. In this case we specify that we want to keep at most 2 different kernel releases:

package-cleanup --oldkernels --count=2

Think ahead

The limit of installed kernel packages can be made permanent by editing /etc/yum.conf to add (or modify if it already exists):

installonly_limit=2

Leave a Reply