How to Upgrade the Linux Kernel on CentOS 7
The default kernel version on CentOS 7 remains at 3.x. If certain software requires a specific Linux kernel version, upgrading the kernel becomes necessary. For instance, Google's BBR acceleration requires a Linux kernel greater than 4.9. This article discusses the topic of upgrading the CentOS 7 kernel.

Kernel Version Selection
We can download specific kernel source code from the https://www.kernel.org/ official website and compile it for an upgrade, but this process is quite tedious and is not within the scope of this discussion.
If we choose to upgrade using rpm packages, we can use pre-compiled packages provided by others. The kernel upgrade packages provided by elrepo are quite trustworthy. The kernel address is as follows: https://elrepo.org/linux/kernel/el7/x86_64/RPMS/
However, when opening the elrepo website, we can only see two versions: 5.15.x and 5.4.x (these may change over time), marked as ml and lt.

mlstands for the mainline version, which always keeps the latest mainline kernel.ltstands for the long-term support version, which has a longer support cycle.
By cross-referencing the https://www.kernel.org official website with the lifecycle of the two versions above, we can see that 5.15 is supported until 2023, while 5.4 is supported until 2025.

If you pursue the latest version, simply choose the rpm package with ml. If you pursue stability and a longer support cycle, simply choose the lt version.
Online Upgrade
# Import ELRepo public key
wget https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm --import RPM-GPG-KEY-elrepo.org
# Install ELRepo
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# Upgrade to the latest kernel
yum --enablerepo=elrepo-kernel install kernel-ml -y
# Upgrade to the long-term support lt kernel (choose one)
yum --enablerepo=elrepo-kernel install kernel-lt -y
Offline Upgrade
You can also manually download the rpm kernel for an offline upgrade. Taking the upgrade of the lt kernel as an example, the method is as follows:
# Download the kernel (links may expire over time)
wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.160-1.el7.elrepo.x86_64.rpm
# Backup download address
wget https://wget.ovh/linux/kernel/kernel-lt-5.4.160-1.el7.elrepo.x86_64.rpm
# Upgrade the kernel
rpm -ivh kernel-lt-5.4.160-1.el7.elrepo.x86_64.rpm
Switching Kernel
Enter the command awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg to view the grub2 boot sequence number.
[root@test ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (5.4.160-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-face32e3e9d448e2a0403204f18369d9) 7 (Core)
As seen, sequence number 0 is the kernel we just installed. We set it as the default boot kernel:
# Set default boot kernel
grub2-set-default 0
# Reboot server to take effect
reboot
Some service providers may encounter issues where the setting does not take effect. In this case, we can adopt the approach of deleting the old kernel and keeping the new one. You need to reboot the server and connect via VNC (please consult your service provider) and select the new kernel (5.4) at the boot interface to enter. Then, delete the old kernel using the following method:
# Check current kernel to ensure it boots with the new kernel
uname -a
# View all kernels in the system
rpm -qa | grep kernel
# Remove unnecessary kernels
yum remove kernel-3.10.0-229.4.2.el7.x86_64
If there is only one kernel in the system, it will be selected by default for the next boot.
Note
Upgrading the kernel carries risks. The methods above do not guarantee a successful kernel upgrade. Please operate cautiously in production environments. If the kernel fails to boot after the upgrade, you can connect to the server via VNC (consult your service provider), select the normal kernel to start, and delete the abnormal kernel to recover.
Summary
mlrepresents the mainline version, always keeping the latest mainline kernel.ltrepresents the long-term support version, with a longer support cycle.- If the kernel upgrade fails, you can connect via VNC to select the normal kernel to enter the system.
- ELRepo often deletes old kernels, so it is recommended to regularly download and save kernels from the ELRepo website for future use.
Some parts of the above content are referenced from: Linux Kernel 5.14.x Compiled Version