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


GRUB2

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/<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

 

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

 

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

4 thoughts on “How to update GRUB2 using grub2-editenv and grubby in RHEL 8 Linux”

  1. grub2-editenv - set "$(grub2-editenv - list | grep kernelopts | sed -e 's///')"
    sed: -e expression #1, char 0: no previous regular expression
    grub2-editenv: error: invalid parameter .
    Reply
  2. 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

    Reply
    • 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

      Reply

Leave a Comment