How to Safely Clean Old Kernels and Free Up Space on RHEL6/CentOS 6 /boot Partition


4 views

When your RHEL6/CentOS 6 system's /boot partition nears capacity (as shown by df -h reporting 86% usage), kernel cleanup becomes essential. The key challenge is identifying which kernels can be safely removed without breaking system stability.

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

First, determine your running kernel with uname -r, then list all installed kernels:

# uname -r
2.6.32-358.23.2.el6.x86_64

# rpm -qa kernel\\* | sort -V
kernel-2.6.32-358.el6.x86_64
kernel-2.6.32-358.11.1.el6.x86_64
kernel-2.6.32-358.23.2.el6.x86_64

Follow these rules for safe kernel cleanup:

  • Always keep the currently running kernel (shown by uname)
  • Keep at least one fallback kernel (usually the previous version)
  • Remove all older kernels that aren't dependencies

Method 1: Using package-cleanup (Recommended)

# yum install yum-utils
# package-cleanup --oldkernels --count=2

This keeps the latest 2 kernels (current + 1 fallback) and removes others.

Method 2: Manual RPM Removal

# rpm -e kernel-2.6.32-358.el6.x86_64 \
       kernel-2.6.32-358.11.1.el6.x86_64

After removal, regenerate GRUB config:

# grub2-mkconfig -o /boot/grub2/grub.cfg
# grep -P "submenu|^menuentry" /boot/grub2/grub.cfg

Add this to /etc/yum.conf to prevent future /boot filling:

installonly_limit=2
  • If you accidentally remove all kernels, boot from rescue media and reinstall
  • Always test the fallback kernel before removing others
  • Consider increasing /boot partition size (minimum 250MB recommended)

Running out of space on the /boot partition is a common issue in RHEL/CentOS 6 systems. The partition is typically small (around 100MB-500MB), and each kernel update consumes about 30-50MB. When multiple kernel versions accumulate, the partition fills up quickly.

First, check your current running kernel:

uname -r
# Example output: 2.6.32-358.23.2.el6.x86_64

List all installed kernels:

rpm -qa | grep kernel
# Sample output:
# kernel-2.6.32-358.el6.x86_64
# kernel-2.6.32-358.11.1.el6.x86_64
# kernel-2.6.32-358.23.2.el6.x86_64
# kernel-firmware-2.6.32-431.1.2.0.1.el6.noarch

Follow these guidelines:

  • Always keep the currently running kernel (shown by uname -r)
  • Keep at least one previous working kernel as a fallback
  • Remove all other older kernels

Use package-cleanup from the yum-utils package:

yum install yum-utils
package-cleanup --oldkernels --count=2

The --count=2 parameter keeps the current kernel plus one older version. To remove all except the current kernel:

package-cleanup --oldkernels --count=1

If package-cleanup isn't available, remove kernels manually:

rpm -e kernel-2.6.32-358.el6.x86_64 kernel-2.6.32-358.11.1.el6.x86_64

After removal, update GRUB:

grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

Add this to /etc/yum.conf to automatically keep only 2 kernels:

installonly_limit=2

Verify the freed space:

df -h /boot