Loading...
Real Time Issues

How to remove old unwanted kernels in alma linux – heading

package-cleanup not working with CentOS/RHEL 8

With the introduction of RHEL/CentOS 8, package-cleanup has been modified and it cannot be used any more to remove old kernels. You can check the difference in the list of supported arguments from their man page in RHEL/CentOS 8 and earlier releases

Now we get this message

 # package-cleanup --oldkernels --count=2

package-cleanup has to be executed with one of the options: –dupes, –leaves, –orphans, –problems or –cleandupes

Using installonly_limit with oldinstallonly

Now we can use dnf with installonly_limit and –oldinstallonly to remove old kernel rpms and to define the list of installed kernel rpms. As per the man page of dnf.conf

installonly_limit: number of installonly packages allowed to be installed concurrently. Defaults to 3. The minimal number of installonly packages is 2. Value 0 or 1 means unlimited number of installonly packages.
oldinstallonly: Removes old installonly packages, keeping only installonly_limit latest versions.

By default installonly_limit is set to 3 in /etc/dnf/dnf.conf

 # grep limit /etc/dnf/dnf.conf"

installonly_limit=3
So if you try to install more than 3 kernel packages, the oldest one will be automatically removed.

Removing old kernels with dnf
Example-1: When latest kernel is active
Now let me show you some case study on using dnf to automatically remove old kernel packages. For the sake of demonstration I installed 4 kernels (by modifying installonly_limit in dnf.conf)
How to properly remove old kernels RHEL/CentOS 8
At this stage currently my Linux server is active with latest kernel version

# uname -r

4.18.0-193.13.2.el8_2.x86_64
In this command we leave the last 2 kernel installed on the system and remove the remaining old kernels. I have explicitly defined installonly_limit=2 using –setopt to overwrite the default value from /etc/dnf/dnf.conf. If you don’t provide this then by default dnf will consider the value of installonly_limit from dnf.conf

# dnf remove --oldinstallonly --setopt installonly_limit=2 kernel

Below is a snippet from my server:
How to properly remove old kernels RHEL/CentOS 8

ALSO READ

Configure postfix mail server and client with examples (CentOS/RHEL 7/8)
So as you see, this command has initiated the removal of 2 old kernels which is working as expected


	
Leave a Reply

Your email address will not be published. Required fields are marked *