How To Upgrade Linux Kernel Version On CentOS

How To Upgrade Linux Kernel Version On CentOS

By default, Linux 3.10 kernel version comes in Linux 7. So, if we require to upgrade it to the latest version, we can do this easily. We can install a new kernel and upgrade the existing one using the repository on Linux. Let’s see, how to upgrade the Linux kernel version. Linux kernel tutorial mailing list

How to Check the current Linux kernel version. 

[root@hr ~]# uname -r
3.10.0-229.el7.x86_64

Check Out: Error NOAUTH Authentication required while Accessing Redis

Import the GPG key and update the existing EPEL-repository.

[root@hr ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@hr ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

If EPEL is not installed, you can install it using yum install epel-release -y and it doesn’t work for you then run the below commands to download and install the package. 

[root@hr ~]# wget https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
[root@hr ~]# rpm -ivh elrepo-release-7.el7.elrepo.noarch.rpm 
warning: elrepo-release-7.el7.elrepo.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:elrepo-release-7.0-4.el7.elrepo ################################# [100%]

Once you have installed and enabled the repository. we can check the available kernel version on Linux.

[root@hr ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror, langpacks
http://elrepo.org/linux/kernel/el7/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 301 - Moved Permanently
Trying other mirror.
elrepo-kernel                                         | 2.9 kB 00:00:00 
elrepo-kernel/primary_db                              | 1.9 MB 00:00:03 
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirror-hk.koddos.net
Available Packages
kernel-lt.x86_64            4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-devel.x86_64      4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-doc.noarch        4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-headers.x86_64    4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-tools.x86_64      4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.220-1.el7.elrepo            elrepo-kernel
kernel-lt-tools-libs-devel.x86_64   4.4.220-1.el7.elrepo    elrepo-kernel
kernel-ml.x86_64                 5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-devel.x86_64           5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-doc.noarch             5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-headers.x86_64         5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-tools.x86_64           5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-tools-libs.x86_64      5.6.7-1.el7.elrepo         elrepo-kernel
kernel-ml-tools-libs-devel.x86_64    5.6.7-1.el7.elrepo     elrepo-kernel
perf.x86_64                      5.6.7-1.el7.elrepo         elrepo-kernel
python-perf.x86_64               5.6.7-1.el7.elrepo         elrepo-kernel

Next, Enable the kernel repository and install the latest stable kernel. 

[root@hr ~]# yum --enablerepo=elrepo-kernel install kernel-ml

Check Out: Install Tweak Tool On Ubuntu 20.04 LTS Local Fossa Linux

We have to reboot the machine.

[root@hr ~]# reboot

Once the machine is rebooted, check the kernel version should be changed from 3.10 to 5.6. 

[root@hr ~]# uname -r
5.6.7-1.el7.elrepo.x86_64

Set the Default Kernel:

We can also set the default kernel when your machine reboots because there’re more kernels available when the machine rebooted. So, it’s better to set the default one and change this value “GRUB_DEFAULT=0″ in the grub file.

[root@hr ~]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

We will have to regenerate the kernel configuration using the below commands. 

[root@hr ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.6.7-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.6.7-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-cc296a7856c7489a820805edc134cced
Found initrd image: /boot/initramfs-0-rescue-cc296a7856c7489a820805edc134cced.img
done

Reboot the machine and make sure your machine should boot with the latest kernel version. 

Check Out: How To Set Ulimit Users and File Descriptions On Linux Server

This is good for best practice when you want to upgrade the kernel in the production environment. So, it’s better to have the backup of the server before upgrading the kernel version if something goes wrong, you can restore the server.

You’re done

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment