How to recreate the missing /etc/default/grub file in Red Hat Enterprise Linux ?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 10
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 7
  • GRUB2 Bootloader

Issue

  • The /etc/default/grub file is missing.
  • The system is up and running, how can one recreate it?

Resolution

  • Manually create a file at the /etc/default/grub location 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/grub file, change the arguments list for GRUB_CMDLINE_LINUX. The list can be obtained from /proc/cmdline (or from /boot/grub2/grub.cfg if it was not recreated).

    • Note: if the argument list is not available, the LVM names can be passed via command line with the custom kernel parameters as required.
  • Ensure the file owner and group is root and the modes are set to 0644 (-rw-r--r--).

  • Once run, take a backup of the existing grub configuration file:

    • For BIOS-based systems:

      # cp -v /boot/grub2/grub.cfg /boot/grub2/grub.cfg.backup
      
    • For UEFI-based systems:

      # cp -v /boot/efi/EFI/redhat/grub.cfg /boot/efi/EFI/redhat/grub.cfg.backup
      
  • Recreate the grub.cfg configuration file:

    • In case of BIOS:

      # grub2-mkconfig -o /boot/grub2/grub.cfg
      
    • In case of EFI:

      • For RHEL 9.2 and older:

        # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
        
      • For RHEL 9.3 and later:

        # grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline
        
      • Note: The /boot/efi/EFI/redhat/grub.cfg file, which GRUB2 previously used on UEFI systems, is now a stub that redirects to /boot/grub2/grub.cfg, which contains the real GRUB2 configuration. In RHEL 9 grub2-mkconfig should not be used with /boot/efi/EFI/redhat/grub.cfg as an output file.

SBR
Components
Category

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.