The boot loader Grand Unified Boot Loader (GRUB2) in RHEL 8 differs from the GRUB2 in RHEL 7. In this article I will share different commands to update GRUB2 and set kernel command line argument in RHEL 8 Linux.
/etc/default/grub
changes no longer being included when issuing grub2-mkconfig -o /boot/grub2/grub.cfg
. It seems that at least some options set there are now silently ignored.In this article I will disable IPv6 using GRUB2 (ipv6.disable
) on RHEL 8 Linux to demonstrate the steps to update GRUB2 in RHEL 8 Linux host.
Update GRUB2 using grub2-editenv
The grub2-editenv
utility is actually the recommended path to alter these variables. As a result, the following can be used. Appending an extra argument:
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
Here copy paste the content from above command and append the additional kernel parameter you wish to add to the GRUB2.
[root@rhel-8 ~]# grub2-editenv - set "kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1"
Alternatively you can also choose a shorter and less error prone approach as shown below
[root@rhel-8 ~]# grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) ipv6.disable=1"
Here, $(grub2-editenv - list | grep kernelopts)
will automatically select the existing kernelopts
and will append the additional kernel command line argument.
Verify the newly added output
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1
Next reboot the node and verify the configuration to make sure your changes are persistent
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1
As you can see our IPv6 is disabled in the GRUB2 command line.
[root@rhel-8 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-80.el8.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1
Similarly to remove a parameter or argument from kernel command line in GRUB2, use the below syntax
# grub2-editenv - set "$(grub2-editenv - list | grep kernelopts | sed -e 's/<arg>//')"
For example, here to remove ipv6.disable
argument we will use:
# grub2-editenv - set "$(grub2-editenv - list | grep kernelopts | sed -e 's/ipv6.disable=[01]$//')"
Lastly reboot your system for the changes to take effect.
Update GRUB2 using grub2-mkconfig
The older method of achieving this behaviour is still possible, but the existing kernelopts
value will need to be unset first:
[root@rhel-8 ~]# grep GRUB_CMDLINE_LINUX /etc/default/grub GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
Here I will update ipv6.disable=1
in the GRUB2 configuration file /etc/default/grub
[root@rhel-8 ~]# grep GRUB_CMDLINE_LINUX /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1"
But as you see the existing kernelopts reflects old GRUB2 entry, so if we reboot the node or rebuild our GRUB2 then the new changes will not reflect on the node.
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
So we need to unset the kernelopts which is an additional step here:
[root@rhel-8 ~]# grub2-editenv - unset kernelopts
next rebuild the grub configuration
[root@rhel-8 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... done
Next re-verify kernelopts
[root@rhel-8 ~]# grub2-editenv - list | grep kernelopts
kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1
So our changes are visible as expected.
Update GRUB2 using grubby
grubby is a utility for manipulating bootloader-specific configuration files.
You can use grubby also for changing the default boot entry, and for adding/removing arguments from a GRUB2 menu entry.
[root@rhel-8 ~]# grubby --info DEFAULT index=0 kernel="/boot/vmlinuz-4.18.0-80.el8.x86_64" args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet $tuned_params" root="/dev/mapper/rhel-root" initrd="/boot/initramfs-4.18.0-80.el8.x86_64.img $tuned_initrd" title="Red Hat Enterprise Linux (4.18.0-80.el8.x86_64) 8.0 (Ootpa)" id="f653c3662e81432aa484cd1639a04047-4.18.0-80.el8.x86_64"
Add the argument you wish to append to the kernel command line menu
[root@rhel-8 ~]# grubby --args ipv6.disable=1 --update-kernel DEFAULT
Next verify the GRUB2 configuration
[root@rhel-8 ~]# grubby --info DEFAULT
index=0
kernel="/boot/vmlinuz-4.18.0-80.el8.x86_64"
args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet $tuned_params ipv6.disable=1"
root="/dev/mapper/rhel-root"
initrd="/boot/initramfs-4.18.0-80.el8.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-80.el8.x86_64) 8.0 (Ootpa)"
id="f653c3662e81432aa484cd1639a04047-4.18.0-80.el8.x86_64"
Next reboot the node to activate the changes
[root@rhel-8 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-80.el8.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ipv6.disable=1
What's Next
Now since you are familiar with grubby command, you should learn about the new kernel-core and kernel-modules introduced in RHEL/CentOS 8 along with some more examples on grubby command
- What are kernel-core and kernel-modules introduced in RHEL/CentOS 8 and how to upgrade these kernels
- 12 practical grubby command examples (cheat cheet)
Conclusion
In this tutorial I shared you different methods which you can use to modify GRUB2 content in RHEL/CentOS 8 using grubby
and grub2-editenv
. Now grubby would be the most preferred choice as grub2-editenv
is not very user friendly in some cases specially if you wish to use this as part of some script.
Lastly I hope the steps from the article to set kernel command line argument, update GRUB2 using grub2-editenv, grub2-mkconfig and grubby in RHEL 8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
References
I have used below external references for this tutorial guide
Configure Kernel Command Line Arguments
Thanks for highlighting this, I have corrected the command
Hi
As changes now seem to be ignored in /etc/default/grub when using grub2-mkconfig -o /boot/grub2/grub.cfg is there an equivalent way of applying GRUB_DISABLE_SUBMENU=false using other grub utilities as this seems to be one of the parameters no longer being included?
Thanks
I believe the changes which are ignored are for GRUB_CMDLINE_LINUX as I did some quick test and the changes were properly reflected for other values in RHEL 8. You can make your change in /etc/sysconfig/grub and then execute grub2-mkconfig -o /boot/grub2/grub.cfg and verify the same in /etc/default/grub