How to upgrade Kernel 5 on CentOS 7

I. Introduction

Although some people use the word   Linux to represent an entire operating system, it’s important to note that Linux is just the  Kernel. The distribution, on the other hand, is a fully functional operating system (CentOS, Ubuntu, EHEL …) built on the Kernel with many tools and application libraries.

During normal operations, the Kernel is responsible for performing two important tasks:

  • Acts as a communication bridge between hardware and software running on the system.
  • Manage system resources as efficiently as possible.

To do this, the Kernel communicates with the hardware through its built-in drivers or drivers that can be later installed as a module.

Example: When an application running on your server wants to connect to a wired network, it sends that request to the Kernel, which in turn uses the appropriate driver to connect to the network.

With new devices and technologies being released periodically, it is important to update the kernel of the system if we want to take full advantage of the latest features. In addition, updating the system’s Kernel will help protect the system from vulnerabilities discovered in previous versions.

And at the time of writing this article, the latest and most stable Kernel is 5.10.9.

You can track the Kernel version at the following link:

  • The Linux Kernel Archives.

If you are ready to upgrade Kernel 5 on CentOS 7 continue reading this article!

II. Upgrade Kernel 5 on CentOS 7

To upgrade Kernel 5 on CentOS 7 you just need to follow these steps.

Step 1: SSH into your CentOS 7 system

To upgrade Kernel 5 on CentOS 7, we first need to SSH or access your VPS or server with  root privileges  first or at least with a user with  sudo.

After successfully SSHing as root, we continue with step 2 to check the Kernel version on your system.

Step 2: Check Installed Kernel Version

When we installed CentOS 7, it included a certain version of the Linux Kernel. To display the current version installed on our system, we can execute the following command:

uname -sr

Below are the results on my CentOS 7 system.

how-to-upgrade-caps-kernel-5-tren-centos-7
My Kernel version is 3.10.0.

If now when we visit  https://www.kernel.org/, we will see that the latest Kernel version is  5.1  at the time of this writing.

With Kernel version  5.1 which will be a long-term release and will be supported for 6 years, previous Linux Kernel versions are only supported for 2 years.

One important thing to consider is the lifecycle of the kernel version – if the version you are using is nearing the end of its life, no further fixes will be made available after that date. For more information, refer to the Kernel releases page.

Step 3: Perform Kernel 5 upgrade on CentOS 7

Most current distributions provide a way to upgrade the kernel using the yum command and an officially supported repository.

However, this will only perform an upgrade to the latest version available from the repositories and it’s not the latest version found at https://www.kernel.org/.

To solve this problem you need to install the ELRepo repository, which is a third-party repository for upgrading to the recently released Kernel version.

To enable the ELRepo repository on CentOS 7, execute the following commands:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
how-to-upgrade-caps-kernel-5-tren-centos-7
Enable ELRepo repository on CentOS 7.

Once the ELRepo repository has been activated, you can use the following command to list the packages related to the Kernel.

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
how-to-upgrade-caps-kernel-5-tren-centos-7
List of Kernels you can use from the ELRepo repository . This list may change from time to time.

Next, we install the latest official stable Kernel with the following command:

yum --enablerepo=elrepo-kernel install -y kernel-ml
how-to-upgrade-caps-kernel-5-tren-centos-7
Install  Kernel 5.10.9  successfully.

Finally, use your  rebootmachine command to apply the latest Kernel that has just been installed and when the server starts, select the latest Kernel from the menu as shown below. If you are using a VPS but cannot access the startup interface, please contact the technical department where you registered to use the VPS.

how-to-upgrade-caps-kernel-5-tren-centos-7
Select the latest Kernel while starting the server.

Continue to log in with permissions  rootand run the following command to check the Kernel version again:

uname-sr

However, we are not quite done yet. Because when restarting the server will still use the old Kernel version. To solve this problem, please go to the next step and also the last step.

Step 4: Set Default Kernel Version in GRUB

To set the newly installed version as the default boot kernel option, you will have to modify the GRUB configuration as follows.

sudo grub2-set-default 0

This means that the top Kernel in the GRUB initial screen will be used as the default.

Then you need to save and run the following command to re-initialize the Kernel configuration.

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

Finally, let’s reboot with the reboot command, and then when the system has booted you can check the Kernel version again with the uname-sr command and you’re done.

Congratulations, you have successfully upgraded Kernel 5 on CentOS 7.

III. Summary

Hopefully, this article on upgrading Kernel 5 on CentOS 7 will help you better understand the Kernel, as well as the importance of upgrading the Kernel of the system you are administering.

On this page