Sep 13, 2018

How to limit number of kernels in CentOS / Fedora / RedHat / Oracle Linux

By default, CentOS will keep the 5 last installed kernels available. Since kernels are getting bigger and the /boot partition is, in most of the cases, a primary partition which is difficult to extent, you could run into problem of /boot was too small.

Nowadays 500M of /boot is quite common. But if you have a system at hand with a small size of /boot,
the workaround is to limit the number of old kernels that you want to keep after installing a new one.

Install the package yum-utils:

yum install yum-utils

Remove the old kernels:

package-cleanup --oldkernels --count=2

To make this permanent, edit /etc/yum.conf and set installonly_limit:


CentOS will now install no more than 3 kernels. The current one and two older versions. This applies to other RPM-based systems like Fedora, Amazon AMI, Redhat or Oracle Enterprise Linux.