Remove Old Linux Kernels on AlmaLinux

This tutorial intends to show you how to Remove or Delete Old Unused Linux 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.

Upgrade AlmaLinux Kernel Version

To install and Upgrade your Kernel version on AlmaLinux servers, you can visit these guides:

Upgrade Linux Kernel on AlmaLinux 8

Upgrade Linux Kernel on AlmaLinux 9

Now you can follow the steps below to display the current kernel version, list all kernels, and remove all old kernels on AlmaLinux.

Steps 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 Linux Kernel?

First, you can use the following command to display your current kernel version on your AlmaLinux server:

uname -sr
Output
Linux 6.4.1-1.el8.elrepo.x86_64

Step 2 – How To List All Linux Kernels?

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 Delete Old Unused Linux 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, we use vi editor:

vi /etc/yum.conf

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.

sudo dnf update

Conclusion

At this point, you have learned to display the current kernel version, list all kernels, and remove all old Linux kernels on AlmaLinux with the DNF package manager.

Hope you enjoy it. Please Subscribe to us on Facebook and Twitter.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular