Skip to main content

Raymii.org Logo (IEC resistor symbol) logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Remove unused CentOS/Red Hat kernels

Published: 18-01-2014 | Author: Remy van Elst | Text only version of this article


Table of Contents


This small article will show you how to remove unused kernels in Red Hat or CentOS. This is sometimes necessary because the /boot partition can fill up.

Are you running Ubuntu and want to clean up kernels? See this article: https://raymii.org/s/snippets/Remove Old Ubuntu_Kernels.html

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get $100 credit for 60 days). (referral link)

You can check which kernels you have installed using the rpm -q kernel command:

$ rpm -q kernel
kernel-2.6.18-348.16.1.el5
kernel-2.6.18-348.18.1.el5
kernel-2.6.18-371.el5
kernel-2.6.18-371.1.2.el5
kernel-2.6.18-371.3.1.el5

As you can see this is a CentOS 5 box.

In the yum-utils package there is the package-cleanup command. This command, among other things, lets you remove older kernels very simple. First install it:

yum install yum-utils

With the following command you can clean up all old kernels and keep just two. The current one and the previous one:

package-cleanup --oldkernels --count=2

The Fedora Documentation has more info and various good examples on the package-cleanup command: https://docs.fedoraproject.org/en- US/Fedora/14/html/Software Management Guide/ch07s03.html

Tags: bash , centos , kernel , rhel , snippets , yum