Question: How to keep only running kernel in a CentOS/RHEL Linux system?

Keeping less than 2 kernels in a Linux system is strongly not recommended. There are several reasons for this recommendation:

  • If an installation of a new kernel is interrupted or aborted in any before it completes successfully, rebooting the system with that kernel may not be possible. If there is another kernel installed, it will allow booting the system to attempt a re-installation of the non-booting kernel.
  • If abnormal behavior is seen with a specific kernel, there is the option of booting the system with another one from the same family to check if the behavior is reproducible.
  • If abnormal behavior is seen with a kernel from a particular kernel family (UEK or RHCK), there is the option of booting with a kernel from the other family to check if the same behavior is reproducible.

Currently, the default in Oracle Linux is to keep the 3 last kernels of each family. This is considered a best practice. The installonly_limit parameter in /etc/yum.conf is set to 3 for the above behavior and can be changed to 2 to keep at most 2 kernels from each family.

It is not possible to set the parameter to ‘1’ and doing so will produce an error. This is because when installing a new kernel, the existing running kernel cannot be uninstalled as it is in use by the system. This means that the strict minimum is actually 2 kernels of each family.

Given the above, a non-running kernel can be manually removed via yum as the root user:

NOTE: Never remove the running kernel from a Linux system! This will remove kernel bits from the system, with the potential to not even allow a reinstall of a kernel again (unless another one was kept in the system to allow booting from to recover).