Stack Engineer

Remove Old Kernels on CentOS

If you need to reduce disk usage by cleaning up your /boot partition, or limit the number of items in your boot list, you can remove old kernels, as well as stop yum from keeping old versions by following this simple tutorial.

Step 1 - List all Installed Linux Kernel Images

You can see a list of all currently installed kernel images and verify which kernel release you're using with the following commands.

rpm -q kernel
uname -r

Step 2 - Install yum-utils

The package yum-utils contains package-cleanup which will be used to uninstall old unused Linux kernel images.

sudo yum install yum-utils

Step 3 - Uninstall Old Kernels

Replace number with the maximum number of kernels you would like to keep.

package-cleanup --oldkernels --count=number

Step 4 - Modify Yum Configuration

Edit /etc/yum.conf file and change installonly_limit to the maximum number of kernel images you would like kept installed.

vi /etc/yum.conf