Q. We have 4 different versions of Linux kernel installed by yum command under CentOS Linux. Currently I'm using only latest version 2.6.18-53.1.4.el5. What is the proper and suggested method to remove old kernels from a CemtOS / Debian Linux server?
A.Most Linux distro keeps old kernel files so that you can revert back in case of emergency pop up due to hardware / software incompatibility issues. Kernel is nothing but other files on Linux box. Following is the suggested way to remove old kernels.
Step # 1: Find current kernel version
uname -r
Output:
2.6.18-53.1.4.el5
Step #2: List all installed kernels
Use rpm or dpkg command:
# rpm -q kernel
Output:
kernel-2.6.12-1.el5 kernel-2.6.18-17.el5 kernel-2.6.18-53.el5 kernel-2.6.18-53.1.4.el5
Debian / Ubuntu Linux user, enter:
$ dpkg --list 'linux-image*'
Output:
Desired=Unknown/Install/Remove/Purge/Hold | 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 2.6.22.14.21 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 2.6.22.14.21 Generic Linux kernel image
Step #3: Remove all old kernels
WARNING! These examples may result into unstable system if not executed with care. Do not remove the kernel the system is currently running.Choose which kernel you want to uninstall from the list of those installed. Type the following command to remove the kernel package under RHEL / CentOS / Fedora Linux:
# rpm -e kernel-2.6.12-1.el5
Type the following command to remove the kernel package under Debian / Ubuntu Linux:
$ sudo apt-get remove linux-image-2.6.22-14-generic
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 21 comments… read them below or add one }
Hi there,
Does these commands work for SUSE 10.3? I tried
# rpm -q kernel
does not return the list, but message says:
package kernel is not installed
you should write like
rpm -e kernel “packagename”.
first check which do you want to uninstall by writing uname -r.
SuSE does not leave old kernels behind (as long as nothing have been modified), it updates the kernel. Where as RedHat does an install.
hey the method is wrong for Fedora.
$ sudo apt-get remove linux-image-2.6.22-14-generic
doesn’t usually work as default packman in Fedora is yum and there is no package like linux-image.
it simply called kernel in Fedora.
Nilesh,
apt-get only works on Debian / Ubuntu and other Debian based distro. For fedora, use yum or rpm command.
vivek, first you in the post said that remove old kernel using ur cmd on Fedora. Now you updated it and u r tellin
me now ?? lol. i know that’s why i suggested. :)
Nilesh, yup, it was a typo. Thanks for the heads up and your post. :)
I remove old kernels in CentOS using yum. I usually check the current running kernel:
#uname -r
query the list of kernels:
#rpm -qa kernel*
and then remove older kernels using yum:
#yum remove kernel-x
Hi, for your kind information:
Hi Vivek, keep up the great work!
I just removed all my kernels on accident. Now when I boot from DVD I do not have /dev/cdrom, nor /dev/scdX, and I cannot get to kernel rpm packages.
I also cannot chroot /mnt/sysimage
The error is: cannot run command ‘/bin/sh’: No such file or directory
Please suggest how to restore this system.
Best regards,
Chris
PS – I booted from DVD with: linux rescue
I used sudo apt-get remove linux-image-2.6.28-11-generic and removed the old kernel. But the configuration files are not removed. It shows
rc linux-image-2. 2.6.28-11.42 Linux kernel image for version 2.6.28 on x86
Is there any way to clean up the configuration files also of the removed kernel?
None of this worked for 9.04, 9.10 or 10.04.
Guess i start using something else then Ubuntu since they allways have to rename functions
@Shibu: dpkg –purge linux-image-2. 2.6.28-11.42
This command removes all the old kernels:
Ahmad – thanks for this command, brilliant!
This works a treat! Thanks a ton!
I really do need to teach myself some sed love…
i have the following problem
{
[root@yousaf Yousaf]# uname
Linux
[root@yousaf Yousaf]# uname -r
2.6.33.3-85.fc13.i686
[root@yousaf Yousaf]# rpm -q kernel
kernel-2.6.33.3-85.fc13.i686
[root@yousaf Yousaf]# rpm -e kernel-2.6.33.-85.fc13.i686
error: package kernel-2.6.33.-85.fc13.i686 is not installed
[root@yousaf Yousaf]# sudo rpm -e kernel-2.6.33.-85.fc13.i686
error: package kernel-2.6.33.-85.fc13.i686 is not installed
}
What i do some problem i have face in many software when i want to remove that
use this cmd
rpm -r kernel-2.6.33.3-85.fc13.i686
or
yum remove kernel-2.6.33.3-85.fc13.i686
besure to install previous version of kernel
Nice,,
yum list installed | grep kernel-*
yum remove (or erase) kernel-*
then check your all rest kernels…