Upgrading CentOS kernel to the latest version

Installation Guide: Upgrading Kernel Version on CentOS 7 Server

This Installation Guide is designed to assist users who need to upgrade the kernel version of their CentOS 7 server. The kernel upgrade is necessary for both single and multinode installations. It is assumed that users are already familiar with yum and rpm, the software package management systems on CentOS and Red Hat, as well as the Grub boot manager.

Prerequisites:

Before proceeding with the kernel upgrade, ensure that the following prerequisites are met:

1. Access to the CentOS 7 server with administrative privileges.

2. Familiarity with the command-line interface.

3. Basic understanding of yum and rpm package management systems.

4. Knowledge of the Grub boot manager.

CentOS Kernel Upgrade

Following are the steps involved in upgrading the kernel:

  • Verify the current kernel version
  • Ensure that existing software packages are updated to the latest versions
  • Install GPG key for ElRepo software repository
  • Install the ElRepo software repository
  • Verify that ElRepo's latest kernel is available
  • Make sure your kernel is up to dateLoad the new kernel by rebooting
  • Make sure the new kernel is running on the system
  • Configure Grub according to your needs
  • Install Grub configuration
  • Reboot

If you wish to upgrade your kernel, you must be logged in as root or have access to root privileges using the sudo su command. This procedure assumes you have issued sudo -s or are logged in as root.

A comprehensive guide to upgrading the CentOS kernel & Step-by-step guide 

Step #1. Update the installed packages to the latest versions and install the fastestmirror package

(needed to select the most available repository for installation at the time)

yum -y update
yum -y install yum-plugin-fastestmirror

Step #2. Import the public key of the ELRepo repository and install this 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

Step #3. Clear the yum cache before installing

yum clean all

Step #4. Install thekernel-ml package from the installed repository

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

Step #5. Check the version of the installed kernel in the OS loader

To do this, you can use the following command:

sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

The output will look like this

# sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.3.8-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1062.4.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-14dc8360d3c94457b2b096d6da6b8737) 7 (Core

As you can see the latest version of the kernel is marked as option 0. We set this option as the default option for the bootloader and regenerate its configuration.

grub2-set-default 0
grub2-mkconfig -o /boot/grub2/grub.cfg

After that, we reboot the system and after loading we check the installed kernel version

# uname -msr
Linux 5.3.8-1.el7.elrepo.x86_64 x86_64

As you can see, the system booted with the correct kernel version. After that, you can uninstall older versions

yum install yum-utils
package-cleanup --oldkernels