Every three months once kernel team releasing new stable kernel which comes with new features, Improved Hardware & System Performance. At least monthly once we will get kernel patch/update from operating system for varies fix. For best practices, i would advice users to install all the updates regularly to make the system up and running without any issue.
And /boot partition sometimes needs a bit of that attention. If you enable automatic
updates, it will fill up with old kernels that you’ll probably never need. It also will stop
you from running dnf (Dandified Packaging Tool) to install or remove anything. If you find yourself in this
situation, you can use rpm to get around it. RPM is the higher-level package manager
in Red-Hat-based distributions, and it’s very useful when dnf has “broken”.
If you look in the directory /boot, you will see it full of old kernels and images. It is not
advisable just to delete them, as you can break your system. Run uname -r , which
will tell you what kernel you are currently on:
Let’s find out which kernels are installed and which can be removed from your system.
To do this, run the following:
rpm -q kernel
The output still might be quite long, but as you can notice i have just installed Fedora 30 so it might explain short kernel list.
Anyhow, if you are happy and have sudo privileges, go ahead:
sudo rpm -e kernel-5.0.10-300.fc30.x86_64
Please note: For me it’s kernel-5.0.10-300.fc30.x86_64, but for you would be the old ones you choose to remove from the list. But PLEASE BE CAUTIONS what you are doing, you may brick your system.
How update you bootloader:
grub2-mkconfig -o /boot/grub2/grub.cfg
For the UEFI systems use:
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Now reboot your system! While you are at in terminal just use sudo reboot.
And Ta da! Your older kernel’s are gone with the wind!
Now, i know what you are probably thinking “Why cant this be managed to be done easier & automatically?” Well! I’ve got some good news for you. It can! We can easily accomplish this on RHEL, CentOS distributions by installing system utility called yum-utils package & dnf-plugins-core for Fedora. yum-utils contains package-cleanup binary which allow users to remove the old kernels easily on RHEL & CentOS.
yum-utils package is part of yum package manager. It is a collection of utilities and plugins extending and supplementing yum in different ways. Use yum package manager to install yum-utils.
sudo yum install yum-utils
Core Plugins for DNF. This package enhances DNF with builddep, config-manager, copr, debuginfo-install, download, needs-restarting, repoquery and reposync commands.
Additionally provides generate_completion_cache, noroot and protected_packages passive plugins. Use dnf package manager to install yum-utils.
sudo dnf install dnf-plugins-core
Delete/Remove Old kernels in CentOS/RHEL:
sudo package-cleanup --oldkernels --count=1
Delete/Remove Old kernels in Fedora:
sudo dnf remove $(dnf repoquery --installonly --latest-limit -2 -q)
Automatically Delete/Remove Old kernels in Fedora/CentOS/RHEL:
The above method is manual one which needs to be take care every time. To automate this, just add the kernels count which you want to keep on /etc/yum.conf file.
From your next update, this will remove all old kernels except latest two which includes live on. =:)