Upgrading the CentOS kernel to the latest version
This guide explains how to install a newer kernel on CentOS 7 using the ELRepo repository.
ELRepo discontinued support for el7 in July 2024. The procedure described in this guide no longer works. This guide is preserved as archival material.
If you are still running CentOS 7, consider migrating to AlmaLinux 8 using the Elevate tool.
Choose a kernel variant
ELRepo provides two kernel variants:
kernel-ml installs the mainline kernel, which follows the latest upstream Linux releases. It receives new features and improvements quickly but may introduce compatibility issues with drivers or production workloads.
kernel-lt installs a long-term support kernel, which prioritizes stability over new features. This is the recommended option for production servers.
Update the system and install ELRepo
Update the installed packages:
yum -y update
Import the ELRepo GPG key and install the repository:
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
Verify that the repository was added successfully:
yum repolist | grep elrepo
Clear the yum cache:
yum clean all
Install the new kernel
To install the long-term support kernel (recommended for production):
yum --enablerepo=elrepo-kernel install kernel-lt kernel-lt-headers kernel-lt-tools kernel-lt-tools-libs
To install the mainline kernel instead:
yum --enablerepo=elrepo-kernel install kernel-ml kernel-ml-headers kernel-ml-tools kernel-ml-tools-libs
Verify that the kernel packages were installed:
rpm -qa | grep '^kernel-'
Set the new kernel as default
List all installed kernels with their boot order:
grubby --info=ALL | grep -E 'title|kernel'
The newest kernel is usually assigned index 0, but verify the order before setting it as default. Set the default by index:
grubby --set-default=0
Or by the full kernel path for reliability:
grubby --set-default /boot/vmlinuz-<version>
Replace <version> with the actual version string from the grubby --info=ALL output.
Verify the default kernel:
grubby --default-kernel grub2-editenv list
If Secure Boot is enabled in BIOS/UEFI, third-party kernels from ELRepo may fail to boot. Disable Secure Boot before rebooting.
Reboot and verify
Reboot the server:
reboot
After the system comes back up, verify the running kernel version:
uname -r
Remove old kernels
Once the new kernel is confirmed working, remove older versions to free disk space. The --count=2 option keeps the two most recent kernels as a fallback:
yum install -y yum-utils package-cleanup --oldkernels --count=2
Emergency rollback
If the new kernel does not boot, select the previous kernel from the GRUB menu during startup. After booting into the old kernel, restore it as default:
grubby --set-default=1 reboot
Replace 1 with the index of the working kernel from grubby --info=ALL.