How to Upgrade Linux Kernel in CentOS

Introduction

The kernel is the core component of an operating system, serving as the bridge between hardware and software. It manages system resources, facilities communication between hardware and applications and ensures the overall stability and functionality of the computer. Acting as a supervisor, the kernel handles tasks such as process scheduling, memory management and device communication. It plays a pivotal role in enabling various software programs to run efficiently on a computer, making it an essential component for the proper functioning of an operating system.


Steps to Update Kernel Version on CentOS/RHEL

Before updating Kernel version on CentOS/RHEL, check installed kernel version of your system OS by following any one of the commands.

uname -r  

cat /proc/version  


Step 1: -  Enable to latest version of EL Repository

To install the new kernel version, a new latest version of EL repository needs to be enabled by following commands

sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org  
        
$ sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm  

Step 2: -  List All Available Kernel versions

To list all available kernek versions, execute following command

yum list available --disablerepo='*' --enablerepo=elrepo-kernel  

Step 3: - Select Required version of the kernel to install

To install the latest version of stable long-term support kernel use following command

sudo yum --enablerepo=elrepo-kernel install kernel-lt  

Step 4: -  Set Default Kernel Version

To set latest installed version of the kernel to load at the boot time automatically edit grub file under /etc/default

sudo vim /etc/default/grub  

Search for the GRUB_DEFAULT line and change it to GRUB_DEFAULT=0. This will instruct boot loader to load default to the first kernel on the list, which is the latest.

After saving the /etc/default/grub file execute the following command to recreate the kernel configuration

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

Step 5: - Reboot  the system
    
sudo reboot