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.

How to update GRUB2 using grub2-editenv and grubby in RHEL 8 Linux

 

IMPORTANT NOTE:
An update to Red Hat Enterprise Linux 8 Beta results in /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///')"

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

 

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:
Configure Kernel Command Line Arguments

Leave a Reply

Your email address will not be published. Required fields are marked *