How to delete old kernels?

Murat Özgün / How To / 25-11-2021

After kernel updates, old files remain in the system and take up unnecessary space. It is also thought that these old files may cause “Kernel Panic”. Each kernel takes up 350mb space in the system. So, it’s better to delete unnecessary kernels.
Unnecessary folders has stayed in /boot/ and /lib/modules. After having root privilage, list the unnecessary folders via “ls -I” and to remove / delete them use “rm” and “rm -rf” for directories. First launch the terminal...


Deleting old kernels

Enter this command:

sudo ls -l /boot/kernel*

Hit "Enter" after writting user password


Enter this command to find out the kernel has been used.

uname -r

5.15.3 ---- This is the kernel on which system’s run.

We begin to delete now...

This sign * is used to identify the kernel version according to last two digit. And it helps to cover all documents / folders under this kernel version.

sudo rm /boot/*58
sudo rm /boot/*63
sudo rm /boot/*70
sudo rm /boot/*78

Four kernels removed in this example...

In general, it is recommended to have the last 2 kernels running well in the system. The system can be opened and repaired with the other kernel when a problem occurs in the kernel used.


Deleting modules

List the modules first.

sudo ls -l /lib/modules/


Leave last two kernels runs well. Then remove / delete rest of them.

sudo rm -rf /lib/modules/5.10.58
sudo rm -rf /lib/modules/5.10.63
sudo rm -rf /lib/modules/5.10.70
sudo rm -rf /lib/modules/5.10.78

We have to update the grub after that.

sudo update-grub

Now you are ready to reboot your system.

"How to delete old kernels?" is shared by Ali Cengiz Kurt