Bootstrap FreeKB - Linux Fundamentals - Install a new kernel in Linux
Linux Fundamentals - Install a new kernel in Linux

Updated:   |  Linux Fundamentals articles

On a Red Hat distribution (CentOS, Fedora, Red Hat), the dnf list or yum list command can be used to list the currently installed kernels.

~]# yum list installed kernel
Installed Packages
kernel.x86_64                      4.18.0-477.21.1.el8_8       @rhel-8-for-x86_64-baseos-rpms 
kernel.x86_64                      4.18.0-477.27.1.el8_8       @rhel-8-for-x86_64-baseos-rpms
kernel.x86_64                      5.14.0-284.30.1.el9_2       @System

 

And the uname command with the -r or --kernel-release or -a or -all flag can be used to display the kernel being used.

~}# uname --kernel-release
5.14.0-284.30.1.el9_2.x86_64

 

In the prior examples, the following is the breakdown of the version.

  • 3 - major version
  • 10 - minor version
  • 0 = revision
  • 327.el7 = fix
  • x86_64 = architecture

 

On a Debian distribution (Ubuntu, Mint) the apt-get -u update command can be used to determine if a newer kernel is available. On a Red Hat distribution (CentOS, Fedora, Red Hat), the dnf check-update or yum check-update command can be used.

[root@server1 ~]# yum check-update | grep kernel
kernel.x86_64              3.3.4.2          updates
kernel-tools.x86_64        3.3.4.2          updates
kernel-tools-libs.x86_64   3.3.4.2          updates

 

On a Red Hat distribution (CentOS, Fedora, Red Hat), the dnf update <kernel> or yum update <kernel> can be used to install the newer kernel. This will not overwrite the current kernel. If you cannot use dnf or yum to install a new kernel, you can download the kernel from https://www.kernel.org. Typically, kernels are downloaded from https://www.kernel.org/pub/linux/kernel/.

[root@server1 ]# yum update kernel_name
Installed:
  kernel.x86_64 0:3.10.0-514.26.2.el7

 

After the new kernel is installed, often GRUB will be configured to boot into the new kernel. If your system has the grubby CLI, you can use grubby to display the default kernel that will be used on boot.

~]# grubby --default-kernel
/boot/vmlinuz-5.14.0-284.30.1.el9_2.x86_64

~]# grubby --default-index
0

~]# grubby --default-title
Red Hat Enterprise Linux (5.14.0-284.30.1.el9_2.x86_64) 9.2 (Plow)

 

If you want to change the default kernel, let's first display information about the kernel.

~]# grubby --info=/boot/vmlinuz-4.18.0-477.27.1.el8_8.x86_64
index=1
kernel="/boot/vmlinuz-4.18.0-477.27.1.el8_8.x86_64"
args="ro rd.lvm.lv=rootvg/lv_root rd.lvm.lv=rootvg/lv_swap rhgb quiet net.ifnames=0 biosdevname=0 LANG=en_US.UTF-8 $tuned_params crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M"
root="/dev/mapper/rootvg-lv_root"
initrd="/boot/initramfs-4.18.0-477.27.1.el8_8.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-477.27.1.el8_8.x86_64) 8.8 (Ootpa)"
id="c412e00d88a746d884ab2d375aa9cfab-4.18.0-477.27.1.el8_8.x86_64"

 

And then we can set the default kernel.

~]# grubby --set-default=/boot/vmlinuz-4.18.0-477.27.1.el8_8.x86_64

~]# grubby --set-default-index=1

 

If you don't have grubby, the following command can be used to set the kernel to boot into.

grub2-reboot 'CentOS Linux (3.10.0-327.18.2.el7.x86_64) 7 (Core)'
grub2-set-default 'CentOS Linux (3.10.0-327.18.2.el7.x86_64) 7 (Core)'

 

Or you can use the index number of the kernel.

~]# grub2-set-default 1

 

Typically, /etc/default/grub will have the following, which tells GRUB to use the grub.cfg file.

~]# cat /etc/default/grub
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true

 

Let's find the grub.cfg file. It's often located at /boot/grub2/grub.cfg.

~]# find /boot -iname grub.cfg
/boot/grub2/grub.cfg

 

Sometimes grub.cfg will have one or more menuentry for the kernel to boot into.

~]# grep ^menuentry /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-514.26.2.el7.x86_64) . . .
menuentry 'CentOS Linux (3.10.0-354.el7.x86_64) . . .

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 43f5db in the box below so that we can be sure you are a human.