How to re-create the missing /etc/default/grub file in Red Hat Enterprise Linux ?
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
Issue
- The
/etc/default/grubfile is missing from the system. - The system is up and running, how can one re-create it?
Resolution
-
Manually create a file at the
/etc/default/grublocation with the following content:GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true #GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="root=/dev/mapper/volgroup_lv_root rd.lvm.lv=vg_<volgroup>/<lvm_1> rd.lvm.lv=vg_<volgroup>/<lvm_1> custom_parameter_1 custom_parameter_2" GRUB_DISABLE_RECOVERY="true" GRUB_THEME="/boot/grub2/themes/system/theme.txt" -
In the created
/etc/default/grubfile, change the arguments list forGRUB_CMDLINE_LINUX. You can either fetch the list from/proc/cmdlineor from/boot/grub2/grub.cfgif not re-created. If you are unable to fetch the arguments list, you can mention alllvmnames on the command line with the custom kernel parameters as required. -
Ensure the following:
- The owner and group for this file is
root. - The file permissions are set to
-rw-r--r--.
- The owner and group for this file is
-
Once run, take a backup of the existing grub configuration file:
- In case of BIOS:
# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup- In case of EFI:
# cp /boot/efi/EFI/redhat/grub.cfg /boot/efi/EFI/redhat/grub.cfg.backup -
Re-create the grub configuration file:
- In case of BIOS:
# grub2-mkconfig -o /boot/grub2/grub.cfg-
In case of EFI:
-
In Red Hat Enterprise Linux 7,8,9.0,9.1 and 9.2:
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg -
In Red Hat Enterprise Linux 9.3 and later:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdlineNOTE: 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.
-
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.