How to remove old kernels on CentOS 6 (to free up boot partition)? [duplicate]

How does one determine which kernels to remove in order to free up some space on /boot partition.

Here is a scenario (some background info).

1. Parititon info (in case it helps)

# df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/sda1        99M   81M   14M  86% /boot
...

2. Current kernel version

# uname -a
Linux serv.example.com 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

3. All kernel versions installed

# rpm -qa | grep kernel
abrt-addon-kerneloops-2.0.8-21.el6.centos.x86_64
kernel-firmware-2.6.32-431.1.2.0.1.el6.noarch
libreport-plugin-kerneloops-2.0.9-19.el6.centos.x86_64
kernel-headers-2.6.32-431.1.2.0.1.el6.x86_64
kernel-2.6.32-358.11.1.el6.x86_64
kernel-2.6.32-358.el6.x86_64
kernel-2.6.32-358.23.2.el6.x86_64
dracut-kernel-004-336.el6_5.2.noarch

So...

  1. Which kernel versions would one remove from the list above?
  2. How?
  3. A short explanation on the decision (why?) would help.

Taken from the following website

## Install yum utils ##
yum install yum-utils

## Package-cleanup set count as how many old kernels you want left ##
package-cleanup --oldkernels --count=2

This will remove all older kernels and keep only the two most recent kernels on centos 6.4 which is probably what you want since recent kernels contain bug fixes and you can always failover to the older kernels if the new ones fail to boot. The above command means that you don't have to go and say rpm -e xyz where xyz is your specific kernel since it automatically keeps the newest ones.

The command you ran

rpm -qa | grep kernel

Doesn't actually tell you what kernels are using space on your boot partition. dracut-kernel doesn't actually install a kernel on your system. You can query the rpm to confirm that.

[root@localhost]: rpm -ql dracut-kernel
/usr/share/doc/dracut-kernel-004
/usr/share/doc/dracut-kernel-004/README.kernel

I'd remove all but the most recent two. You need the one you're running right now, of course, but I think it's worth keeping one previous one in case there are some stability issues with the current one. You'd have something to go back to in a hurry if that were the case.

rpm -ev kernel-2.6.32-358

If you're confident of the stability of the current one, and you really want that space back, remove the second newest one with

rpm -ev kernel-2.6.32-358.11.1