How to re-create the missing /etc/default/grub file in Red Hat Enterprise Linux ?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9

Issue

  • The /etc/default/grub file is missing from the system.
  • The system is up and running, how can one re-create it?

Resolution

  1. 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"
    
  2. In the created /etc/default/grub file, change the arguments list for GRUB_CMDLINE_LINUX. You can either fetch the list from /proc/cmdline or from /boot/grub2/grub.cfg if not re-created. If you are unable to fetch the arguments list, you can mention all lvm names on the command line with the custom kernel parameters as required.

  3. Ensure the following:

    • The owner and group for this file is root.
    • The file permissions are set to -rw-r--r--.
  4. 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
    
  5. 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-cmdline
        

        NOTE: The /boot/efi/EFI/redhat/grub.cfg file, 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 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.