About Linux FAQ

Browse More FAQs:

Safely Remove / Delete Old Linux Kernel from a Linux Server

Posted by Vivek Gite [Last updated: January 9, 2008]

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:

Discussion on This FAQ

  1. blink4blog Says:

    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

  2. Casper Pedersen Says:

    SuSE does not leave old kernels behind (as long as nothing have been modified), it updates the kernel. Where as RedHat does an install.

  3. Nilesh Says:

    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.

  4. vivek Says:

    Nilesh,

    apt-get only works on Debian / Ubuntu and other Debian based distro. For fedora, use yum or rpm command.

  5. Nilesh Says:

    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. :)

  6. vivek Says:

    Nilesh, yup, it was a typo. Thanks for the heads up and your post. :)

  7. reckless2k2 Says:

    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

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!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.