How to Change the default kernel (boot from old kernel) in CentOS/RHEL 8

 

In case you have multiple kernels installed in the system, you can boot from a specific kernel in case of a downgrade or any other requirement. Let’s see for the purpose of this blog post, how to revert back to an older kernel in CentOS/RHEL 8. Before moving forward, let’s understand how to view the current default kernel system has booted from.

View the current default kernel

1. You can view the default kernel level currently set in your system using grubby. grubby is a command line tool for updating and displaying information about the configuration files for various architecture specific bootloaders. It is primarily designed to be used from scripts which install new kernels and need to find information about the current boot environment.

# grubby --default-kernel
/boot/vmlinuz-4.18.0-147.0.3.el8_1.x86_64

2. Every kernel installed in the system has an index associated with it. To view the kernel index use:

 
# grubby --default-index
0

3. List out the available kernels using:

# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Apr 26  2019 /boot/vmlinuz-0-rescue-d026443091424a74948f9f62d2adb9b5
-rwxr-xr-x. 1 root root 7868768 Jun 19  2019 /boot/vmlinuz-0-rescue-ec2b9a54dc859388d7bc348e87df5332
-rwxr-xr-x. 1 root root 8106848 Nov 11 13:07 /boot/vmlinuz-4.18.0-147.0.3.el8_1.x86_64
-rwxr-xr-x. 1 root root 7876960 Sep 15  2019 /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64
-rwxr-xr-x. 1 root root 7881056 Jul 26  2019 /boot/vmlinuz-4.18.0-80.7.2.el8_0.x86_64

4. To get detailed information of a certain kernel version, you can use grubby again:

# grubby --info /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64
index=1
kernel="/boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64"
args="ro console=ttyS0,115200n8 console=tty0 net.ifnames=0 rd.blacklist=nouveau crashkernel=auto $tuned_params"
root="UUID=58013e4a-11c0-4195-8fd8-e4b33e5b17d6"
initrd="/boot/initramfs-4.18.0-80.11.2.el8_0.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-80.11.2.el8_0.x86_64) 8.0 (Ootpa)"
id="ec2b9a54dc859388d7bc348e87df5332-4.18.0-80.11.2.el8_0.x86_64"

As you can see from the output above, you can easily find the kernel-index of any kernel available in your system. The latest kernel will always have an index of 0.

Now that you know which kernel you have booted from and the list of available kernels you can boot from, we can go ahead and boot from an older kernel. There are 2 ways to boot from an older kernel:

  1. using kernel filename
  2. using kernel index

Method 1 – Boot from old kernel using kernel filename

1. List out the available kernel filenames available in your system:

# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Apr 26  2019 /boot/vmlinuz-0-rescue-d026443091424a74948f9f62d2adb9b5
-rwxr-xr-x. 1 root root 7868768 Jun 19  2019 /boot/vmlinuz-0-rescue-ec2b9a54dc859388d7bc348e87df5332
-rwxr-xr-x. 1 root root 8106848 Nov 11 13:07 /boot/vmlinuz-4.18.0-147.0.3.el8_1.x86_64
-rwxr-xr-x. 1 root root 7876960 Sep 15  2019 /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64
-rwxr-xr-x. 1 root root 7881056 Jul 26  2019 /boot/vmlinuz-4.18.0-80.7.2.el8_0.x86_64

2. Use the grubby command once you have devcided on which kernel to boot from:

# grubby --set-default [kernel-filename]

For example:

# grubby --set-default boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64

Method 2 – Boot from old kernel using kernel index

1. List out the available kernel filenames available in your system:

# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Apr 26  2019 /boot/vmlinuz-0-rescue-d026443091424a74948f9f62d2adb9b5
-rwxr-xr-x. 1 root root 7868768 Jun 19  2019 /boot/vmlinuz-0-rescue-ec2b9a54dc859388d7bc348e87df5332
-rwxr-xr-x. 1 root root 8106848 Nov 11 13:07 /boot/vmlinuz-4.18.0-147.0.3.el8_1.x86_64
-rwxr-xr-x. 1 root root 7876960 Sep 15  2019 /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64
-rwxr-xr-x. 1 root root 7881056 Jul 26  2019 /boot/vmlinuz-4.18.0-80.7.2.el8_0.x86_64

2. To view the index of any of the kernel listed above:

# grubby --info [kernel-filename] | grep index

For example:

# grubby --info /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64 | grep index
index=1

3. Now that you know index of the kernel you want to boot from, use the command:

# grubby --set-default-index=[kernel-entry-index]

For example:

posted @ 2020-09-29 22:01  ascertain  阅读(148)  评论(0编辑  收藏  举报