Linux Kernel and related files are stored in the following locations on your Linux distro:
- /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).
- /lib/modules/KERNEL-VERSION/* (/lib/modules/$(uname -r))- Linux device drivers (modules)
If the Linux kernel is installed using a binary package system such as rpm, yum, up2date, apt-get, etc., you can remove it with the following commands.
WARNING! Make sure you only remove or delete the unwanted Linux kernel. Removing the currently running Linux kernel will create a non-bootable system. Check Linux Kernel Version by tying the following command:
uname -r
Rpm based distro – Red Hat/CentOS/Fedora Core/Suse Linux
First, find out all installed kernel version with the following commands:
# rpm -qa | grep kernel-smp
# rpm -qa | grep kernel
# Use grep command/egrep command to filter out results #
# rpm -qa | grep kernel-[0-9]
Here is what I see before I delete or remove the installed Linux kernel on my system:
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 have a total of three different kernels installed. To remove kernel-smp-2.6.9-42.EL type the rpm command:
# rpm -e kernel-smp-2.6.9-42.EL
OR
# rpm -vv -e kernel-smp-2.6.9-42.EL
Deleting or removing RHEL 8 Linux kernel
These days we use the yum command/dnf command to list installed kernels and delele them directly:
sudo dnf list --installed kernel
# get the current kernel version #
uname -r
# note down disk space using the df command #
df -H /
df -H
Now let us delete the Linux kernel version 4.18.0-240.10.1.el8_3:
sudo dnf remove kernel-4.18.0-240.10.1.el8_3.x86_64
Deleting Linux kernel using the dnf on RHEL 8 cloud VM
$ sudo dnf remove kernel-modules-4.18.0-240.10.1 \
kernel-core-4.18.0-240.10.1
I am keeping kernel-headers package as I need to compile other modules.
.deb based distro – Debian or Ubuntu Linux
Again find out all installed kernel version on your Debian or Ubuntu Linux system, run the dpkg command:
$ dpkg --list | grep kernel-image
# latest version of Debian/Ubuntu uses linux-image pkg #
$ dpkg --list | grep linux-image
Outputs from my Debian system:
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 the help of the apt-get command or apt command itself:
# apt-get remove kernel-image-2.4.27-2-386
OR
$ sudo apt-get remove kernel-image-2.4.27-2-386
Apart from the kernel-image or linux-image, you need to remove and delete headers and module packages too. For instance, here are packages releated to Linux kernel 5.4.0-25 on my Ubuntu Linux 20.04 LTS desktop:
$ dpkg --list | grep 5.4.0-25
List:
ii linux-headers-5.4.0-25 5.4.0-25.29 all Header files related to Linux kernel version 5.4.0 ii linux-headers-5.4.0-25-generic 5.4.0-25.29 amd64 Linux kernel headers for version 5.4.0 on 64 bit x86 SMP ii linux-image-5.4.0-25-generic 5.4.0-25.29 amd64 Signed kernel image generic ii linux-modules-5.4.0-25-generic 5.4.0-25.29 amd64 Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
In other words, eliminate all those four packages:
$ sudo apt --purge remove linux-headers-5.4.0-25 \
linux-headers-5.4.0-25-generic \
linux-image-5.4.0-25-generic \
linux-modules-5.4.0-25-generic
See the following pages for more info:
A note about custom compiled Linux kernel
If you have a custom compiled Linux kernel running, you need to remove the 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.
Summing up
Removing the working Linux kernel may result in an unstable/non- bootable Linux server system. Hence, care must be taken while removing the older Linux kernel. Apart from disk space-saving, you can get rid of the vulnerable Linux kernel from the system to improve the system’s stability and security.
🐧 21 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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
you better to use 911 cd. it helps you to completely remove the red hat os.
My Ubuntu system only returns searches by “linux-image”, not “kernel-image”.
This is most likely due to changes made since this was written.
Can any one tell me how to delete a file in Linux
can any one tell me how to delete linux kernel(vmlinuz).
and how to ovrride linux kernal with vista kernal.
@sailon:
Try using synaptic or remove linux-images-xxx
can any one tell me how to delete linux kernel(vmlinuz).
and how to ovrride linux kernal with vista kernal.
cd /; sudo rm -rf
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
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!!!!!!!
1) First check the current kernel version running on your host machine
uname -r
2) List all the kernels installed in the host
rpm -qa kernel // you can see all the kernels including the one you want to remove
3) Uninstall the kernel which you want to remove
rpm -e kernel-2.6.32-xxx.xxx –nodeps
4) Check if it is uninstalled or not
rpm -qa kernel
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?
thanks
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
i dele my grub.conf file by mistake in linux & i want to recover that file how can i do this
In recent versions of Ubuntu its apt-get remove linux-kernel-
sir, you are a gentleman and a scholar, worked like a dream, I am in your debt. Thank you.
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.
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.
It helped me very much!
I had update from fedora 21 to 22, it worked
but after that i had 2 other
unnecessary kernel
This page helped me very well,
to remove these
After removing custom kernel according to above directions, it will still appear in boot loader entries when you boot the system. To remove boot loader entry of the removed kernel navigate to /boot/loader/entries folder and delete the entry related to remove kernel. Thereafter the the entry will no longer show in the boot loader entries menu when you boot the system (done in CentOS8 Stream but must be similar more or less for Ubuntu or Fedora or any other flavour)