How to maintain specific number of kernel packages on Red Hat Enterprise linux systems?
Environment
- Red Hat Enterprise Linux (RHEL) 5, 6, 7, 8, 9, 10
Issue
- What is the use of
installonly_limitoption in maintaining specific number of kernel packages on system? - How to change the number of kernels presented in grub?
- How to increase the number of kernels presented in grub?
- How to decrease the number of kernels presented in grub?
Resolution
The installonly_limit option in /etc/yum.conf is used to maintain the number of kernel packages on the system.
For example, the following parameter will maintain 3 kernel packages on the system. Once that number is reached, the oldest kernel will be removed.
# cat /etc/yum.conf
[main]
installonly_limit=3
Using installonly_limit=2 ensures that one backup kernel is available.
You cannot set installonly_limit=1 because that would make yum remove the running kernel, which is prohibited. If installonly_limit=1 is used, yum fails.
If three kernel versions are already installed on the server, configuring installonly_limit=2 and reinstalling (or upgrading to) the latest kernel,
Will result in the automatic removal of the oldest installed kernel, ensuring that only the two most recent kernel versions are retained.
For example,
# rpm -qa | grep -i kernel-core
kernel-core-5.14.0-284.11.1.el9_2.x86_64
kernel-core-5.14.0-503.40.1.el9_5.x86_64
kernel-core-5.14.0-611.16.1.el9_7.x86_64
# grep install /etc/dnf/dnf.conf
installonly_limit=2
# dnf reinstall kernel-core-5.14.0-611.16.1.el9_7.x86_64
Updating Subscription Management repositories.
Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs) 5.1 MB/s | 103 MB 00:20
Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs) 16 MB/s | 83 MB 00:05
Dependencies resolved.
=======================================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================================
Reinstalling:
kernel-core x86_64 5.14.0-611.16.1.el9_7 rhel-9-for-x86_64-baseos-rpms 17 M
Installing dependencies:
kernel-uki-virt x86_64 5.14.0-284.11.1.el9_2 rhel-9-for-x86_64-baseos-rpms 54 M
Removing:
kernel x86_64 5.14.0-284.11.1.el9_2 @anaconda 0
kernel-core x86_64 5.14.0-284.11.1.el9_2 @anaconda 56 M
kernel-devel x86_64 5.14.0-284.11.1.el9_2 @AppStream 63 M
Transaction Summary
=======================================================================================================================================
Install 1 Package
Remove 3 Packages
Total download size: 71 M
Is this ok [y/N]: n
Operation aborted.
Note: For RHEL 8+ ensure that /etc/yum.conf is a symlink to /etc/dnf/dnf.conf, otherwise edits made to /etc/yum.conf will not take effect.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments