How to modify the kernel command-line in Red Hat Enterprise Linux 9 and 10
Environment
- Red Hat Enterprise Linux (RHEL) 9
- Red Hat Enterprise Linux (RHEL) 10
- grub2
Issue
-
How to modify the boot parameter in RHEL 9 and RHEL 10
-
grub2-editenv - listcommand output is not showing kernelopts option to update kernel commandline.# grub2-editenv - list saved_entry=d7a9453a54b34038ab12deddd44484e6-5.14.0-39.el9.aarch64 boot_success=0
Resolution
Solution 1 - Update the kernel command-line via grubby
-
Verify the current arguments
# grubby --info DEFAULT index=0 kernel="/boot/vmlinuz-5.14.0-39.el9.aarch64" args="ro crashkernel=2G-:448M rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap" root="/dev/mapper/rhel-root" initrd="/boot/initramfs-5.14.0-39.el9.aarch64.img" title="Red Hat Enterprise Linux (5.14.0-39.el9.aarch64) 9.0 (Plow)" id="d7a9453a54b34038ab12deddd44484e6-5.14.0-39.el9.aarch64" -
Add the command-line parameters with option to update the current kernel or all kernel
# grubby --update-kernel=/boot/vmlinuz-$(uname -r) --args="<NEW_PARAMETER>"or
# grubby --update-kernel=ALL --args="<NEW_PARAMETER>"or
# grubby --args <NEW_PARAMETER> --update-kernel DEFAULT -
Similarly we may remove any kernel command-line parameters with below option
# grubby --update-kernel=ALL --remove-args="<PARAMETER_TO_REMOVE>" -
Reboot the system for changes to reflect
# systemctl reboot
Solution 2 - Edit /etc/default/grub and rebuild the menu
-
Edit
/etc/default/grubfile and update the kernel command-line parameter on lineGRUB_CMDLINE_LINUXand save itGRUB_CMDLINE_LINUX="crashkernel=2G-:448M rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap" -
Rebuild the menu files
-
In Red Hat Enterprise Linux 9.0, 9.1 and 9.2:
# grub2-mkconfig -o /boot/grub2/grub.cfg -
In Red Hat Enterprise Linux 9.3 and later:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline
NOTE: The
/boot/efi/EFI/redhat/grub.cfgfile, which GRUB previously used on UEFI systems, is now a stub that redirects to/boot/grub2/grub.cfg, which contains the real GRUB configuration. In RHEL 9grub2-mkconfigshould not be used with/boot/efi/EFI/redhat/grub.cfgas an output file. See the "Root Cause" section below for more details.NOTE: If
/boot/efi/EFI/redhat/grub.cfggets overwritten, then it is possible to restore its initial content by re-installing the packagegrub2-common. See the "Diagnostic Steps" section below for more details on the expected content of this file. -
-
Reboot the system to apply the changed kernel command line.
# systemctl reboot
NOTE If you are changing the name of your root VG, please reference: grub2-mkconfig command shows "/usr/sbin/grub2-probe: error: failed to get canonical path of `/dev/mapper/rhel-root'." error message after renaming root lv.
Root Cause
-
By default, the kernel command-line parameters, for RHEL 8 using the GRUB2 bootloader, were defined in the
kerneloptsvariable of the/boot/grub2/grubenvfile for all kernel boot entries. -
The file
/boot/grub2/grubenvcan easily get corrupted. As all boot entries in RHEL 8 use the same variable for the kernel command-line, if this file gets corrupted then none of the boot entries will be able to get correct kernel command-line options. This creates a single point of failure for all boot entries. Especially if the root parameter is not set correctly, all entries will fail to boot. -
Storing the kernel command line parameters in the
grubenvfile as akerneloptsvariable isdeprecatedin RHEL 9. -
In RHEL 9 configuration files for the GRUB boot loader are stored in the
/boot/grub2/directory on all supported CPU architectures. There is no longer a different configuration file for UEFI systems. Also the symbolic links in /etc are pointing to/boot/grub2/grub.cfg. More information is available in the Red Hat Enterprise Linux 9.0 relase notes. -
In RHEL 9 the file
/boot/grub2/grub.cfgcontains a default kernel command line as a fall-back option, for the case individual boot loader entries are missing kernel command line options. Every boot entry is saved in a Boot Loader Specification (BLS) snippet (in/boot/loader/entries) and can contain a kernel command line definition overriding the one in/boot/grub2/grub.cfg. -
In RHEL 9.3 and later, the grub2-mkconfig utility works differently than in RHEL 9.2 or older:
If theGRUB_ENABLE_BLSCFGparameter is true, running thegrub2-mkconfig -o /path/to/grub.cfgcommand applies changes from/etc/default/grubonly to grub.cfg without updating the BLS snippets that are used to dynamically generate the boot menu during boot.
To update also BLS snippets, use the--update-bls-cmdlineoption ofgrub2-mkconfigor thegrubbytool.
For more information, see: New default behavior of grub2-mkconfig with BLS and theman grubbypage.
Diagnostic Steps
Disclaimer: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.
-
It is possible to review boot loader entries with:
grubby --info=ALL -
According to the Content from uapi-group.org is not included.Boot Loader Specification, snippets used for creating grub entries during boot can be found in
/boot/loader/entries.
These files can be reviewed with a text editor for confirming options, but, under normal contitions, they should not be edited manually.grubbycan be used to update these entries. -
On UEFI systems, the file
/boot/efi/EFI/redhat/grub.cfgshould contain minimal configuration to redirect to/boot/grub2/grub.cfg, similar to the following:search --no-floppy --fs-uuid --set=dev <filesystem UUID of /boot> set prefix=($dev)/grub2 export $prefix configfile $prefix/grub.cfgIf the file has different content, then it has been overwritten and needs to be recreated by re-installing the
grub2-commonpackage (which contains a scriptlet to generate/boot/efi/EFI/redhat/grub.cfg).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.