Contact
Site: US UK AU |
Nexcess Blog

Removing old Kernels on CentOS 4

July 15, 2011 0 Comments RSS Feed

Removing old kernels on CentOS 4

Kernels RPMs are install only packages but CentOS 4 has no limit on the number of install only packages it will keep around, so you can easily end up with years worth of kernels installed on your server. This doesn’t cause any harm but it can be annoying to have so many un-needed packages installed and they can take up space.

You can see all the kernels installed with the command below. The example below has 39 regular kernels and 39 SMP kernels installed.

$ rpm -qa | grep ^kernel | sort -rn

kernel-utils-2.4-23.el4
kernel-smp-2.6.9-89.35.1.EL
kernel-smp-2.6.9-89.33.1.EL
kernel-smp-2.6.9-89.31.1.EL
kernel-smp-2.6.9-89.29.1.EL
kernel-smp-2.6.9-89.0.9.EL
kernel-smp-2.6.9-89.0.7.EL
kernel-smp-2.6.9-89.0.29.EL
kernel-smp-2.6.9-89.0.28.EL
kernel-smp-2.6.9-89.0.25.EL
kernel-smp-2.6.9-89.0.23.EL
kernel-smp-2.6.9-89.0.20.EL
kernel-smp-2.6.9-89.0.19.EL
kernel-smp-2.6.9-89.0.18.EL
kernel-smp-2.6.9-89.0.16.EL
kernel-smp-2.6.9-89.0.15.EL
kernel-smp-2.6.9-89.0.11.EL
kernel-smp-2.6.9-78.0.8.EL
kernel-smp-2.6.9-78.0.5.EL
kernel-smp-2.6.9-78.0.22.EL
kernel-smp-2.6.9-78.0.1.EL
kernel-smp-2.6.9-78.0.17.EL
kernel-smp-2.6.9-78.0.13.EL
kernel-smp-2.6.9-67.EL
kernel-smp-2.6.9-67.0.7.EL
kernel-smp-2.6.9-67.0.4.EL
kernel-smp-2.6.9-67.0.22.EL
kernel-smp-2.6.9-67.0.20.EL
kernel-smp-2.6.9-67.0.1.EL
kernel-smp-2.6.9-67.0.15.EL
kernel-smp-2.6.9-55.EL
kernel-smp-2.6.9-55.0.9.EL
kernel-smp-2.6.9-55.0.2.EL
kernel-smp-2.6.9-55.0.12.EL
kernel-smp-2.6.9-42.0.8.EL
kernel-smp-2.6.9-42.0.3.EL
kernel-smp-2.6.9-42.0.2.EL
kernel-smp-2.6.9-42.0.10.EL
kernel-smp-2.6.9-34.EL
kernel-smp-2.6.9-100.EL
kernel-2.6.9-89.35.1.EL
kernel-2.6.9-89.33.1.EL
kernel-2.6.9-89.31.1.EL
kernel-2.6.9-89.29.1.EL
kernel-2.6.9-89.0.9.EL
kernel-2.6.9-89.0.7.EL
kernel-2.6.9-89.0.29.EL
kernel-2.6.9-89.0.28.EL
kernel-2.6.9-89.0.25.EL
kernel-2.6.9-89.0.23.EL
kernel-2.6.9-89.0.20.EL
kernel-2.6.9-89.0.19.EL
kernel-2.6.9-89.0.18.EL
kernel-2.6.9-89.0.16.EL
kernel-2.6.9-89.0.15.EL
kernel-2.6.9-89.0.11.EL
kernel-2.6.9-78.0.8.EL
kernel-2.6.9-78.0.5.EL
kernel-2.6.9-78.0.22.EL
kernel-2.6.9-78.0.1.EL
kernel-2.6.9-78.0.17.EL
kernel-2.6.9-78.0.13.EL
kernel-2.6.9-67.EL
kernel-2.6.9-67.0.7.EL
kernel-2.6.9-67.0.4.EL
kernel-2.6.9-67.0.22.EL
kernel-2.6.9-67.0.20.EL
kernel-2.6.9-67.0.1.EL
kernel-2.6.9-67.0.15.EL
kernel-2.6.9-55.EL
kernel-2.6.9-55.0.9.EL
kernel-2.6.9-55.0.2.EL
kernel-2.6.9-55.0.12.EL
kernel-2.6.9-42.0.8.EL
kernel-2.6.9-42.0.3.EL
kernel-2.6.9-42.0.2.EL
kernel-2.6.9-42.0.10.EL
kernel-2.6.9-34.EL
kernel-2.6.9-100.EL
$

Luckily removing them is easy but make sure you don’t remove the kernel you’re running. Usually I just remove all the kernels in a certain “series”, like if the kernel is running on some version of 2.6.9-89, I’ll remove everything below that ’89’ version but leave the all the ’89’ versions installed.

$ ### see what kernel we're on so we don't remove it
$ uname -r
2.6.9-89.29.1.ELsmp
$ ### we're using 2.6.9-89.29.1.ELsmp so let's remove all of the ones below the 2.6.9-89 kernel
$ yum remove kernel*2.6.9-{34,42,55,67,78}*

By removing those 44 kernels, we saved 1.3 gigs of space. If you want to be picky, you can remove more kernels that are part of 2.6.9-89 series, but CentOS 4 is reaching EOL in 7.5 months (February 29, 2012) so don’t waste too many keystrokes ;).

In CentOS 5 and above, you can set a limit on the number of install only packages in yum.conf with the ‘installonly_limit’ option to avoid this problem.

Posted in: Linux