CentOS: How To Upgrade CentOS Linux VPS Kernel


1. Get Current Linux Kernel Version.

uname -srm

tutorialspots# uname -srm
Linux 3.10.0-514.21.2.el7.x86_64 x86_64

2. Get Current Linux OS Version.

cat /etc/*release

tutorialspots# cat /etc/*release
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)

3. How To Upgrade Linux Kernel In CentOS 7?

3.1 Update CentOS Packages.

yum -y update

tutorialspots# yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.constant.com
 * epel: ftp-nyc.osuosl.org
 * extras: centos.mirror.constant.com
 * remi-safe: mirror.oxilion.nl
 * updates: centos.mirror.constant.com
http://yum.mariadb.org/10.0/centos7-amd64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

No packages marked for update

yum -y install yum-plugin-fastestmirror

http://tutorialspots.com/wp-admin/post-new.php# yum -y install yum-plugin-fastestmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.constant.com
 * epel: ftp-nyc.osuosl.org
 * extras: centos.mirror.constant.com
 * remi-safe: mirror.oxilion.nl
 * updates: centos.mirror.constant.com
http://yum.mariadb.org/10.0/centos7-amd64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

Package yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do

3.2 Add ELRepo Repository.

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

tutorialspots# sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

tutorialspots# sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Retrieving https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:elrepo-release-7.0-3.el7.elrepo  ################################# [100%]

3.3 Check ELRepo Repository

yum repolist

tutorialspots# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.constant.com
 * elrepo: ftp.nluug.nl
 * epel: ftp-nyc.osuosl.org
 * extras: centos.mirror.constant.com
 * remi-safe: mirror.oxilion.nl
 * updates: centos.mirror.constant.com
elrepo                                                   | 3.0 kB     00:00
http://yum.mariadb.org/10.0/centos7-amd64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

elrepo/primary_db                                          | 547 kB   00:00
repo id          repo name                                                status
base/7/x86_64    CentOS-7 - Base                                          10,072
elrepo           ELRepo.org Community Enterprise Linux Repository - el7      161
epel/x86_64      Extra Packages for Enterprise Linux 7 - x86_64           13,753
extras/7/x86_64  CentOS-7 - Extras                                           512
!mariadb         MariaDB                                                      43
remi-safe        Safe Remi's RPM repository for Enterprise Linux 7 - x86_  4,809
updates/7/x86_64 CentOS-7 - Updates                                        3,842
repolist: 33,192

3.4 List Available Kernels in ELRepo

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

tutorialspots# yum list available --disablerepo='*' --enablerepo=elrepo-kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirror.koddos.net
Available Packages
elrepo-release.noarch                   7.0-5.el7.elrepo           elrepo-kernel
kernel-lt.x86_64                        5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-devel.x86_64                  5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-doc.noarch                    5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-headers.x86_64                5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-tools.x86_64                  5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-tools-libs.x86_64             5.4.196-1.el7.elrepo       elrepo-kernel
kernel-lt-tools-libs-devel.x86_64       5.4.196-1.el7.elrepo       elrepo-kernel
kernel-ml.x86_64                        5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-devel.x86_64                  5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-doc.noarch                    5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-headers.x86_64                5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-tools.x86_64                  5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-tools-libs.x86_64             5.18.1-1.el7.elrepo        elrepo-kernel
kernel-ml-tools-libs-devel.x86_64       5.18.1-1.el7.elrepo        elrepo-kernel
perf.x86_64                             5.18.1-1.el7.elrepo        elrepo-kernel
python-perf.x86_64                      5.18.1-1.el7.elrepo        elrepo-kernel

We see that Linux 5 kernel is the latest mainline release.

3.5 check all available kernel versions in the Grub2.

tutorialspots# cat /etc/grub2.cfg|awk -F\' '$1=="menuentry " {print i++ " : " $2}'
0 : CentOS Linux (3.10.0-1160.66.1.el7.x86_64) 7 (Core)
1 : CentOS Linux 7 Rescue 81e366ea98b8433281e08f1ce25e9b27 (3.10.0-514.21.2.el7.x86_64)
2 : CentOS Linux (3.10.0-514.21.2.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)
4 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core)
5 : CentOS Linux (0-rescue-e4293fb2b8c749e391cbb8733a6a43f0) 7 (Core)

3.6 Install New CentOS Kernel Version.

If you’d like to use mainline release

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

If you’d like to use long term support (Recommended)

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

3.7 similar to 3.5

3.8 Configure Grub2 on CentOS.

3.8.1 Change the default kernel when Linux is started.

Method 1:

sudo grub2-set-default 0

Method 2: edit file /etc/default/grub

sudo nano /etc/default/grub

change

GRUB_DEFAULT=saved

to

GRUB_DEFAULT=0

3.8.2 Run grub2-mkconfig command to generate the grub2 config

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

3.8.3 Reboot the Linux

sudo reboot

Done, now you can use Step 1 to check your current Linux kernel version

3.9 Remove The Old Linux Kernel.

If you do not need the old Linux kernel anymore, you can remove it

yum install yum-utils
package-cleanup --oldkernels

Leave a Reply