RHEL7: How to set the number of old kernels kept.

Share this link

Presentation

When you’ve got servers running for several years, their kernels have been replaced many times for security reason. You keep getting new ones regularly in the /boot partition until it becomes a problem.

To get the list of the old kernels kept, type:

# rpm -q kernel
kernel-3.10.0-123.8.1.el7.x86_64
kernel-3.10.0-123.9.2.el7.x86_64
kernel-3.10.0-123.9.3.el7.x86_64
kernel-3.10.0-123.13.1.el7.x86_64
kernel-3.10.0-123.13.2.el7.x86_64

The yum command provides you two solutions: one temporary and one permanent.

The temporary solution

The package-cleanup command offers several interesting options.

To install the package-cleanup command, type:

# yum install yum-utils

To list dependency problems in the local RPM database, type:

# package-cleanup --problems
No Problems Found

To display the RPMs that are not relied upon by any other RPM, type:

# package-cleanup --leaves
NetworkManager-libreswan-0.9.8.0-5.el7.x86_64
libertas-sd8686-firmware-20140804-0.1.git6bce2b0.el7_0.noarch
...
net-snmp-libs-5.7.2-18.el7.x86_64

To list installed packages which are not available from currently configured repositories, type:

# package-cleanup --orphans
libtiger-0.3.4-7.el7.nux.x86_64
python-coverage-3.7-3.el7.nux.x86_64

To scan for duplicates in the local RPM database, type:

# package-cleanup --dupes

Note: If you get any duplicate RPMs in the local database, you can use the –cleandupes option to remove them.

Finally, the –oldkernels and –count options allows you to define the number of old kernels to keep.
To remove all the old kernels except two, type:

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

The permanent solution

Edit the /etc/yum.conf file and set the installonly_limit variable:

installonly_limit=2

Note: The default value is 5.

Sources: Inspired from the Lintut website and the package-cleanup man page.

Additional Resources

You can also read a tutorial about maintaining Yum and boosting its performance.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

Be the First to Comment!

Notify of
wpDiscuz

RHCSA7: Task of the day

Allowed time: 3 minutes.
Check that you've got no SELinux policy violations.

RHCE7: Task of the day

Allowed time: 10 minutes.
Configure a httpd server that executes a Perl script in the /var/www/cgi-bin directory displaying "Hello!".

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...