Safely Remove / Delete Old Linux Kernel from a Linux Server
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
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Delete or remove a directory Linux command
- Linux or Unix find and remove files with one find command on fly
- Linux delete directory with rmdir command
- Howto: Linux command line utilities for removing blank lines from text files
- Ubuntu Linux: Uninstall / Remove Any Installed Software
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: debian delete old kernel, delete linux kernel, incompatibility issues, kernel files, kernel version, linux kernel image, remove linux kernel, remove linux package, removing linux kernel, rhel delete old kernel, ubuntu delete old kernel, uninstall linux kernel, unstable system, version description



January 8th, 2008 at 11:53 am
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
January 8th, 2008 at 12:16 pm
SuSE does not leave old kernels behind (as long as nothing have been modified), it updates the kernel. Where as RedHat does an install.
January 9th, 2008 at 1:04 am
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.
January 9th, 2008 at 9:48 am
Nilesh,
apt-get only works on Debian / Ubuntu and other Debian based distro. For fedora, use yum or rpm command.
January 9th, 2008 at 12:25 pm
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.
January 9th, 2008 at 2:32 pm
Nilesh, yup, it was a typo. Thanks for the heads up and your post.
January 9th, 2008 at 2:49 pm
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