In this post, will see how to boot with an old kernel version in RHEL7. When the updated kernel not suitable for your application or OS not booting.
There might be a requirement to upgrade the operating system or kernel version alone in Linux/Unix machines.
In such case, we might face issue with the upgraded kernel version. To, fix that, follow the below steps.
By default, /etc/default/grub file has entry called GRUB_DEFAULT=saved.
[root@localhost ~]# cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet" GRUB_DISABLE_RECOVERY="true"
This entry instructs the system which kernel will be used to load the operating system by checking the saved_entry in the grubenv file, which is in /boot/grub2/grubenv.
[root@localhost ~]# cat /boot/grub2/grubenv # GRUB Environment Block saved_entry=0 #########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################[root@localhost ~]#
So we can set the default kernel by editing /boot/grub2/grubenv file or using grub2-set-default command.
To do this, select the old kernel to boot the operating system from grub splash screen.
And use the grub2-set-default command to change the kernel.
Before changing we should remember that, the always updated kernel will be on top and will use numeric value “0” to mention this kernel in command
The old one will be available by next. So, to mention the old kernel will use numeric value “1”. Like this numeric will start from 0.
/boot/grub2/grub.cfg file contains Kernel and initramfs image details.
below command will show us the list of the kernel installed on this machine.
[root@localhost ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg Red Hat Enterprise Linux Server (3.10.0-693.17.1.el7.x86_64) 7.3 (Maipo) Red Hat Enterprise Linux Server (3.10.0-514.el7.x86_64) 7.3 (Maipo) Red Hat Enterprise Linux Server (0-rescue-ffc8e857b7b84166b88e7b0522c168a4) 7.3 (Maipo)
By default, saved_entry will be the latest one, which you updated.
Using below command will change the default kernel as the old one to boot the operating system without any issue.
[root@localhost ~]# grub2-set-default 1
and now check again in /boot/grub2/grunenv file to verify the default kernel.
[root@localhost ~]# cat /boot/grub2/grubenv | grep saved saved_entry=1
Now you can see in above screen that the old kernel is set as default one.
Now rebuild the /boot/grub2/grub.cfg file using grub2-mkconfig -o command.
Use the below command in BIOS based machines:
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-693.17.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.17.1.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-ffc8e857b7b84166b88e7b0522c168a4 Found initrd image: /boot/initramfs-0-rescue-ffc8e857b7b84166b88e7b0522c168a4.img done
Use below command for UEFI based machines:
[root@localhost ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
finally, restart the machine and check whether the machine booting using old kernel.
reference: Red Hat Document