How do I permanently modify the kernel command line on RHEL 7?
Environment
- Red Hat Enterprise Linux (RHEL) 7
- GRUB2 boot loader
Issue
- How do I modify the kernel command line (and, thus, kernel boot parameters) in Red Hat Enterprise Linux 7 with GRUB2 installed as a boot loader?
Resolution
For RHEL7:
Alternative 1:
-
Make copy of the GRUB2 configuration files as a precaution:
For a BIOS-based system:
# cp /etc/default/grub /etc/default/grub-backup # cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg-backupFor a UEFI-based system:
# cp /etc/default/grub /etc/default/grub-backup # cp /boot/efi/EFI/redhat/grub.cfg /boot/efi/EFI/redhat/grub.cfg-backup -
Open the
/etc/default/grubfile for editing:# vi /etc/default/grubThis file contains multiple GRUB2 options. Kernel boot parameters are specified by the
GRUB_CMDLINE_LINUXoption. -
Once the file is edited, save it and run the command specified below to generate a new
grub.cfgfile:For a BIOS-based system:
# grub2-mkconfig -o /boot/grub2/grub.cfgFor a UEFI-based system:
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg -
Finally, reboot the system to apply the changes:
# systemctl reboot
Alternative 2: Using grubby command:
- For checking details of default kernel:
# grubby --info DEFAULT
- For adding parameters on all kernels:
# grubby --update-kernel=ALL --args="argA argB"
- For removing parameters on all kernels:
# grubby --update-kernel=ALL --remove-args="argA argB"
- Reboot the system to apply the changes:
# reboot
- For more information about grubby: refer to the documentation.
Additional Notes:
-
For RHEL5 and RHEL6, see: How do I permanently modify the kernel command line in RHEL5 and RHEL6?
-
For RHEL 8, see: How do I permanently modify the kernel command line in RHEL 8?
-
For RHEL 9, see: How to modify the kernel command-line in Red Hat Enterprise Linux 9
-
To make a one-time, non-persistent change at boot, please see: How to manually modify the boot parameter in grub before the system boots
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.