How to: Linux delete or remove kernel

by on February 15, 2007 · 17 comments· LAST UPDATED October 2, 2007

in , ,

Q. I have multiple versions installed and I need to save disk space. I am using Cent OS Linux. How can I delete or remove a Linux kernel from my Linux distribution ?

A. Linux Kernel and related files are stored in following locations:
=> /boot - Stores actual kernel and related file such system man and initrd images,

=> /etc or /boot/grub - Stores grub.conf file (most distro use /boot/grub these days).

=> /iib/modules/KERNEL-VERSION/* - Linux device drivers (modules)

If kernel is installed using binary package system such as rpm, yum, up2date, apt-get etc you can remove with following commands:

Rpm based distro - Red Hat/CentOS/Fedora Core/Suse Linux

First find out all installed kernel version with following command:
# rpm -qa | grep kernel-smp
or
# rpm -qa | grep kernel
Output:

kernel-smp-2.6.9-42.EL
kernel-smp-2.6.9-42.0.3.EL
kernel-smp-2.6.9-42.0.8.EL

I've total 3 different kernel installed. To remove kernel-smp-2.6.9-42.EL type command:
# rpm -e kernel-smp-2.6.9-42.EL
OR
# rpm -vv -e kernel-smp-2.6.9-42.EL

.deb based distro - Debian or Ubuntu Linux

Again find out all installed kernel version:
$ dpkg --list | grep kernel-image
Output:

ii  kernel-image-2.4.27-2-386   2.4.27-10sarge1             Linux kernel image for version 2.4.27 on 386
ii  kernel-image-2.6.8-2-686    2.6.8-16sarge1              Linux kernel image for version 2.6.8 on PPro

Now remove kernel-image-2.4.27-2-386 with apt-get command itself:
# apt-get remove kernel-image-2.4.27-2-386
OR
$ sudo apt-get remove kernel-image-2.4.27-2-386

If you have custom compiled kernel you need to remove following files/dirs:

  • /boot/vmlinuz*KERNEL-VERSION*
  • /boot/initrd*KERNEL-VERSION*
  • /boot/System-map*KERNEL-VERSION*
  • /boot/config-*KERNEL-VERSION*
  • /lib/modules/*KERNEL-VERSION*/
  • Update grub configuration file /etc/grub.conf or /boot/grub/menu.lst to point to correct kernel version.

Caution: Removing working kernel may result into unstable / non- bootable Linux server system.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 17 comments… read them below or add one }

1 saad September 11, 2008 at 5:24 pm

i want to remove linux from my system but unable to do so…i formatted the hard disk my making it a slave.but still linux kernel is there and i m getting error message “kernel panic-not syncing:attempted to kill init”..can someone know the solution to completely remove the linux

Reply

2 giri June 24, 2010 at 2:02 pm

you better to use 911 cd. it helps you to completely remove the red hat os.

Reply

3 Sailon October 11, 2008 at 10:51 am

My Ubuntu system only returns searches by “linux-image”, not “kernel-image”.
This is most likely due to changes made since this was written.

Reply

4 ASHOK May 21, 2009 at 5:01 am

Can any one tell me how to delete a file in Linux

Reply

5 nandhu June 18, 2009 at 2:19 am

can any one tell me how to delete linux kernel(vmlinuz).
and how to ovrride linux kernal with vista kernal.

Reply

6 oleksa June 28, 2009 at 9:36 pm

@sailon:
Try using synaptic or remove linux-images-xxx

Reply

7 Rohit November 18, 2009 at 4:36 am

can any one tell me how to delete linux kernel(vmlinuz).
and how to ovrride linux kernal with vista kernal.

Reply

8 Peter M. Saama December 1, 2009 at 3:08 pm

I have just successfully removed a Centos 5.4 v2.6.18 kernel that I installed yesterday. This kernel was installed using “make install”. After deleting /boot/*KERNEL-VERSION*, I found that I had two stale links in /boot:
System.map -> /boot/System.map-*KERNEL-VERSION*
vmlinuz -> /boot/vmlinuz-*KERNEL-VERSION*

I replaced these links with links to the files that match the default kernel in grub.conf

Reply

9 YP December 14, 2009 at 12:03 pm

I have installed kernel2.6.32. After that I am enable to boot the system using the kernel 2.6.32. So I want to remove the kernel2.6.32. But i ont know how to remove kernel from the system. please help me!!!!!!!

Reply

10 abhijeet January 7, 2010 at 5:51 pm

i have make a partition on my windows and i want to remove linux 5.0 so is possible without formatting. I f possible then how, can u tell me its very urgent?

Reply

11 dan March 1, 2010 at 4:21 pm

thanks

Reply

12 pratik jawkar August 10, 2010 at 11:32 am

how to clean user space…?
i tried to compile linux-2.6.26 module after make menucofig executed it shows user space full warning please tell me some answer……!
advance

Reply

13 vishnu March 13, 2011 at 3:53 am

i dele my grub.conf file by mistake in linux & i want to recover that file how can i do this

Reply

14 Peter Fisher June 12, 2012 at 9:39 pm

In recent versions of Ubuntu its apt-get remove linux-kernel-

Reply

15 Norteleng June 24, 2012 at 12:28 pm

sir, you are a gentleman and a scholar, worked like a dream, I am in your debt. Thank you.

Reply

16 Phill July 8, 2012 at 12:25 am

Thanks for this, it helped me run through the removal of current kernel by switching the student to edit grub to from entry , and then remove the current one so he could actually see the “New Kernel” update stuff.

Reply

17 praneeth August 6, 2013 at 4:11 pm

I have compiled latest linux kernel 3.11 rc2 on opensuse 12.3 which by default had 3.7 kernel. i have compiled latest kernel 3 times, due to applying btrfs patches (for my project), now latest compiled kernel’s entries are in grub loader, but when new kernel is loaded it is not working properly. so i loaded into default kernel and saw this article and tried to remove custom compiled kernel and entered 1st command
# rpm -qa | grep kernel-smp
In o/p there is no entry for 3.11 kernel.
what to do now ?
Please help.

Reply

Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: