Upgrade CentOS to the Latest Linux Kernel and Set the Default Boot Entry

Most WordPress sites in the world run on Linux servers. CentOS is a Linux distribution based on Red Hat and is well known for its stability. Most of our own servers use CentOS, and when we recommend servers to clients, CentOS is usually our default recommendation as well.

Most VPS and cloud server providers offer CentOS as an available operating system. At the same time, almost all of those providers do not ship CentOS with the latest stable Linux kernel. In most cases, that is not a problem, because the default CentOS kernel maximizes server stability.

However, there are times when we need to upgrade to the latest Linux kernel in order to take advantage of new features. For example, we may need BBR to improve network performance and reduce server latency.

Upgrade the Kernel in CentOS 7 to the Latest Version

The Linux kernel in the default CentOS 7 repositories is not the latest version. First, we need to install and enable the ELRepo repository so that we can install the latest Linux kernel.

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Once the repository is enabled, we can run the following command to list the available kernel packages:

# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

From the output of the command above, we can see that the latest kernel is already available. Then we can install the latest Linux kernel:

# yum --enablerepo=elrepo-kernel install kernel-ml

Set the Default GRUB Boot Kernel to the Latest Kernel

After installing the latest kernel, we need to reboot the system before we can use it. To avoid choosing the kernel manually every time the server restarts, we can set the latest kernel as the default boot option by following these steps.

Run the following command to set the first kernel entry as the default boot kernel:

grub2-set-default 0

Then run the following command to verify that the setting was applied successfully:

grub2-editenv list

Finally, run the following command to regenerate the GRUB configuration:

grub2-mkconfig -o /boot/grub2/grub.cfg

After the setup is complete, reboot the server and run the following command to check whether the system is using the latest kernel:

uname -sr

If the version shown is the latest kernel you installed in the first step, that means the new kernel has been enabled successfully.

After upgrading to the latest kernel, we can enjoy the benefits it brings, such as BBR support, newer device drivers, and updated KVM support. That said, aside from improvements such as BBR reducing some network latency, the latest kernel may not be dramatically different from the older kernel in everyday server usage. If you do not have a specific need, it is still recommended to use the default kernel provided by the distribution.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *