I recently noticed that my /boot partition was at 95% full, so I investigated to see what was causing it. Apparently, it was filling up with older versions of the linux kernel as a result of upgrades.
Because my system has been very stable, I decided to keep only the current version of the kernel (duh) plus one previous version to fall back on. Following are the steps I used to remove the older kernels.
Step 1: Find the current kernel
It would be a very silly thing to try and remove the kernel you’re currently running, so show the current kernel with:
The output should look something like this:
The 188.8.131.52-170.2.117 is the kernel version number, the fc10 means I’m running Fedora Core 10, the i686 means I’m running the Intel 686 processor version, and the PAE means I’m running a PAE-enabled version of the kernel (so that I can run more than 4GB of RAM on a 32-bit OS). Remember the version number of your currently-running kernel, because we want to avoid it.
Step 2: Find the filename(s) you want to delete
The second step is to find the filename(s) of the old kernel(s). If you’re running a “standard” kernel, query the package manager for the filenames with:
rpm -q kernel
The output should show you the filenames of all installed packages that match. On a CentOS/RHEL 5 system it might look like this:
kernel-2.6.18-164.el5 kernel-2.6.18-164.6.1.el5 kernel-2.6.18-164.9.1.el5
If you get a message saying “package kernel is not installed,” then you may be running a PAE version of the kernel (like I am). Try:
rpm -q kernel-PAE
On a Fedora Core 10 system running a PAE kernel, the output will look something like this:
kernel-PAE-184.108.40.206-170.2.82.fc10.i686 kernel-PAE-220.127.116.11-170.2.113.fc10.i686 kernel-PAE-18.104.22.168-170.2.117.fc10.i686
If you still don’t get any output, then do:
yum list kernel-*
to give you an idea of what the what the package names are. The output will show the installed kernel’s package name in the first column (such as kernel.i686 or kernel-PAE.i686), and the version number in the second column (it will also show packages available to install, but ignore those for now). Take note of the first part of the package name (before any dots). That’s what you should use in your rpm -q command to query for installed pacakges.
Once you know the filename of the package(s) you want to uninstall, you can move to the final step.
Step 3: Remove the unwanted files
In my case, I had three kernels installed: the current and two older ones. I wanted to keep one older kernel around just in case I needed to revert back for any reason. Your needs may be different, but I recommend keeping at least one old kernel just to be safe.
Delete the old kernels one at a time. As root, do:
yum remove <kernel>
where the <kernel> is the old kernel you identified above. In my case, I did:
yum remove kernel-PAE-22.214.171.124-170.2.82.fc10.i686
Yum will ask you to confirm. Check one last time to verify this is a version you no longer need (and make double-sure it’s not the one you’re running) and press y to confirm.
Repeat as necessary for any other old kernel version you want to remove.
NOTE: Using yum for this procedure will automatically update your /boot/grub/menu.lst file and remove the entry for the removed kernel.