≡ Menu

Safely Remove / Delete Old Linux Kernel from a Linux Server

We have four different versions of Linux kernel installed by the yum command under CentOS Linux. Currently, I am using only latest version 2.6.18-53.1.4.el5. What is proper and suggested method to remove old kernels from a CemtOS / Debian Linux server?

Most Linux distro keeps old kernel files so that you can revert in case of emergency pop up due to hardware or software incompatibility issues. A kernel is nothing but a set of files on Linux box. Following is the suggested way to remove old kernels safely on Linux based system.

Step # 1: Find the current kernel version

uname -r
Sample outputs:


Step #2: List all installed kernels

Use the rpm command or dpkg command on Linux:
# rpm -q kernel
Sample outputs (from RPM based distro such as CentOS/RHEL):


Debian / Ubuntu Linux user, enter:
$ dpkg --list 'linux-image*'
Sample outputs:

| 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

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
Please note that on newer system all obsolete kernels and headers should automatically be flagged as no more needed, and thus can be purged with the following single command:
$ sudo apt-get --purge autoremove
Sample outputs:

Fig.01: Deleting all older kernels on an Ubuntu server

Fig.01: Deleting all older kernels on an Ubuntu server

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 29 comments… add one }
  • blink4blog January 8, 2008, 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

    • suranjan September 25, 2010, 12:02 pm

      you should write like
      rpm -e kernel “packagename”.
      first check which do you want to uninstall by writing uname -r.

  • Casper Pedersen January 8, 2008, 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.

  • Nilesh January 9, 2008, 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.

  • nixCraft January 9, 2008, 9:48 am


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

  • Nilesh January 9, 2008, 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. :)

  • nixCraft January 9, 2008, 2:32 pm

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

  • reckless2k2 January 9, 2008, 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

  • Sadicote December 27, 2008, 10:02 am

    Hi, for your kind information:

    sade@sade-desktop:~$ dpkg --list 'linux-image*'
    | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
    ||/ Name           Version        Description
    un  linux-image             (no description available)
    un  linux-image-2.          (no description available)
    ii  linux-image-2. 2.6.27-7.16    Linux kernel image for version 2.6.27 on x86
    ii  linux-image-2. 2.6.27-9.19    Linux kernel image for version 2.6.27 on x86
    ii  linux-image-ge    Generic Linux kernel image
    sade@sade-desktop:~$ sudo apt-get remove linux-image-2. 2.6.27-7.16
    [sudo] password for sade: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Couldn't find package linux-image-2.
    sade@sade-desktop:~$ sudo apt-get remove linux-image 2.6.27-7.16
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package linux-image is not installed, so not removed
    E: Couldn't find package 2.6.27-7.16
  • Chris March 14, 2009, 5:55 am

    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 March 14, 2009, 5:56 am

    PS – I booted from DVD with: linux rescue

  • Shibu January 27, 2010, 12:26 pm

    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?

  • dude May 11, 2010, 10:21 am

    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

  • excogitation November 3, 2010, 6:22 pm

    @Shibu: dpkg –purge linux-image-2. 2.6.28-11.42

  • Ahmad October 1, 2011, 3:57 pm

    This command removes all the old kernels:

    dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
    • Simon May 7, 2013, 9:24 pm

      Ahmad – thanks for this command, brilliant!

    • DanielS May 16, 2013, 11:07 pm

      This works a treat! Thanks a ton!
      I really do need to teach myself some sed love…

    • Piffo April 9, 2015, 5:24 am

      A wonderful command. However in my situation some kernels were “not empty so not removed” which means I have still ten old kernels taking 150 Mb a piece. I will keep looking for a solution and get back to you all if I find it.

  • Yousaf October 14, 2011, 7:04 pm

    i have the following problem

    [root@yousaf Yousaf]# uname
    [root@yousaf Yousaf]# uname -r
    [root@yousaf Yousaf]# rpm -q kernel
    [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

    • Nas Iwuede December 13, 2011, 2:37 pm

      use this cmd
      rpm -r kernel-
      yum remove kernel-

      besure to install previous version of kernel

  • thiyagi November 14, 2011, 9:25 am


  • Alexandr February 22, 2013, 10:42 am

    yum list installed | grep kernel-*
    yum remove (or erase) kernel-*

    then check your all rest kernels…

  • Kenny June 3, 2013, 6:41 am

    I think this is exactly what I’m looking for. However, I have the problem that when I try:

    sudo apt-get remove linux-image-3.5.0-17-generic

    I get:

    The following packages have unmet dependencies:
    linux-image-extra-3.5.0-17-generic : Depends: linux-image-3.5.0-17-generic but it is not going to be installed
    linux-image-extra-3.5.0-32-generic : Depends: linux-image-3.5.0-32-generic but it is not going to be installed
    linux-image-generic : Depends: linux-image-3.5.0-32-generic but it is not going to be installed
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

    Of course, sudo apt-get -f install fails with the following message:

    dpkg: error processing /var/cache/apt/archives/linux-image-3.5.0-32-generic_3.5.0-32.53_amd64.deb (–unpack):
    cannot copy extracted data for ‘./boot/System.map-3.5.0-32-generic’ to ‘/boot/System.map-3.5.0-32-generic.dpkg-new’: failed to write (No space left on device)
    No apport report written because the error message indicates a disk full error

    Apparently my boot partition is too full for me to run sudo apt-get -f install, which I need to run in order to clean up my boot partition! Any thoughts?

    • LaVaughn May 19, 2015, 2:08 pm

      I am having the same issue on my Ubuntu 12.04 LTS machine. Any suggestions or help is appreciated.

      • John Ward September 22, 2015, 12:32 pm

        Try this. Check what you are currently running:
        $ uname -r

        Go into root shell:
        $ sudo -s

        List some of the init files in the /boot directory; cd into /boot and run:
        # ls init*

        initrd.img-3.13.0-45-generic initrd.img-3.13.0-46-generic initrd.img-3.13.0-48-generic initrd.img-3.13.0-49-generic initrd.img-3.13.0-51-generic initrd.img-3.13.0-52-generic initrd.img-3.13.0-53-generic

        Clear some of the files you don’t need, without actually removing them:
        # echo “” > initrd.img-3.13.0-45-generic
        # echo “” > initrd.img-3.13.0-46-generic
        # echo “” > initrd.img-3.13.0-48-generic
        # echo “” > initrd.img-3.13.0-49-generic

        Exit the root shell. You should now have space to run:
        $ sudo apt-get -f install
        $ sudo apt-get autoremove

        • Juri April 13, 2016, 6:04 pm

          Thanks a lot! That worked for me!

  • Alexandr June 14, 2013, 9:03 am

    For Oracle Linux you have to do:
    rpm -qa kernel-uek
    rpm -e kernel-uek-

    Works only for Oracle kernels!

  • PixEye February 25, 2014, 9:56 am

    Hi, I wrote a shell script for GNU/Linux Debian base systems such as Ubuntu boxes.
    You can find it at github:
    Hope this helps.

  • Dixie October 13, 2016, 12:13 pm

    Why is it so hard to remove it.
    Why are they been kept (more than 1 for stability reasons) for so long?
    Why is linux so bad at everything?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , ,