This tutorial intends to show you to Remove Old Unused Kernels on AlmaLinux with DNF. The kernel is the bridge between software and hardware, and it is part of an operating system that interacts with the hardware. If you plan to remove a kernel from your server, it is recommended to keep your system updated and install the latest kernel version.
To install and Upgrade your Kernel version on AlmaLinux servers, you can visit these guides:
Now you can follow the steps below to display the current kernel version, list all kernels, and remove all old kernels on AlmaLinux.
How To Remove Old Kernels on AlmaLinux?
To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. Then, follow the steps below to use the DNF package manager to remove the old kernels.
Note: To see the difference between DNF and YUm, you can visit this guide on Differences between YUM and DNF package managers.
Step 1 – How To List Current Kernel?
First, you can use the following command to display your current kernel version on your AlmaLinux server:
Output Linux 6.4.1-1.el8.elrepo.x86_64
Step 2 – How To List All Kernels on Almalinux?
At this point, you can run the following command in your Linux terminal to display all available kernels on AlmaLinux:
rpm -q kernel
Output kernel-4.18.0-372.9.1.el8.x86_64 kernel-4.18.0-477.13.1.el8_8.x86_64
Step 3 – How To Remove Old Unused Kernels on AlmaLinux?
It is recommended to keep at least one or two old kernels if there is a problem with an update.
Now you can use the following command to remove all old kernels on your AlmaLinux:
dnf remove $(dnf repoquery --installonly --latest-limit 2 -q)
Note: This command will remove all old/unused kernels and keep the currently running and old latest kernel as a backup.
Also, there is another way that you can remove the old kernels. You can edit the YUM config file and set the kernel limit. To do this, open the file with your favorite text editor, here we use vi editor:
And set the kernel counts as shown below:
installonly_limit=2 #set kernel count
When you are done, save and close the file. At this point, when you run the system update only two kernels will be left on the system.
At this point, you have learned to display the current kernel version, list all kernels, and remove all old kernels on AlmaLinux with the DNF package manager.