Removing Old Linux Kernels

Something many linux users will run across is after several times of running their favorite "yum update" command, they are suddenly out of room on the /boot partition of their drive and to make things worse yum update is spewing back error messages saying /boot is out of space every time they try to run. If you're like me perhaps the most annoying thing is that little update icon in the top right hand corner of the screen sitting there saying that it has kernel updates for you and no matter how many times you tell it to update and restart your machine it is still there, but I digress.

Step 1: Find Your Current Kernel Version

To find your current kernel version you can run the following command, but beware if you recently updated your kernel but have not yet restarted or kspliced, your system will show you the kernel that is in use, not necessarily the most recently downloaded. So rule of thumb before kernel updates is make sure you've restarted before removing old versions if possible.

Command: uname -r

Sample Output: 2.6.32-279.5.2.el6.x86_64

Step 2: List Installed Kernels

Depending on your operating system you can list your installed kernels by using the rpm or dpkg command.

Command for Debian/Ubuntu: dpkg --list 'linux-image*'

Sample Output:

| Status=Not/Installed/Config-f/Unpacked/Failed-cfg/Half-inst/t-aWait/T-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                          Version                       Description
ii  linux-image                           Generic Linux kernel image.
un  linux-image-2.6                                       (no description available)
rc  linux-image-2.6.20-15-generic 2.6.20-15.27                  Linux kernel image for version 2.6.20 on x86/x86_64
ii  linux-image-2.6.20-16-generic 2.6.20-16.32                  Linux kernel image for version 2.6.20 on x86/x86_64
ii  linux-image-2.6.22-14-generic 2.6.22-14.47                  Linux kernel image for version 2.6.22 on x86/x86_64
ii  linux-image-generic                   Generic Linux kernel image

Command for rpm based systems: rpm -q kernel

Sample Output:


Step 3: Removing Old Kernels

Finally the actual deleting. Be very careful not to remove the kernel the system is currently running; doing so may result in system problems and will cause you a great deal of headaches. Now that you've been warned pick the kernel from your list of the installed kernels that is not the one you are using and run the appropriate remove command below.

For RHEL / CentOS / Fedora (and any other RPM based system) use: rpm -e kernel-2.6.12-1.e15

For Debian / Ubuntu systems use: sudo apt-get remove linux-image-2.6.22-14-generic

Loading Conversation