Is there a different file location for grub2 configuration files on a UEFI system?

One of our old scripts looks in two separate places for the grub.conf file: one “default” and one for UEFI

if [ -f /boot/grub/grub.conf ] ; then     
    GRUB_CONF_FILE=/boot/grub/grub.conf
elif [ -f /boot/efi/EFI/redhat/grub.conf ] ; then
    GRUB_CONF_FILE=/boot/efi/EFI/redhat/grub.conf

The script is now being updated to support using grub2, but I’m not sure if/where I need to be looking for the /etc/default/grub and /boot/grub2/grub.cfg, and /etc/grub.d

I’m sorry if some of the wording is poor. I’ve never had the GREAT pleasure of playing around with this fun boot stuff before and a lot of this is pretty new to me

Asked By: Tesomas

||

It depends on how you are installing grub. And of course, if you are installing it on the EFI System Partition (ESP), then it depends on where you are mounting that. In the particular case of your script, it looks as though perhaps it is expecting the ESP to be mounted on /boot/efi, and the /EFI/redhat directory is set up to contain what would ordinarily be in /boot on a BIOS based system. If this is correct, just take the location of grub2.conf on a BIOS system and replace the /boot prefix with /boot/efi/EFI/redhat, and you have your answer, namely /boot/efi/EFI/redhat/grub2/grub2.conf. (Note that /etc/default/grub will not move, because that is only used to generate the grub configuration and not used at boot time.)

There are at least two other common ways of setting up your ESP. One is to mount the ESP directly on /boot. The advantage is that you can then install things like grub and the kernel without worrying about the BIOS/UEFI distinction. The disadvantage is that you are now polluting the root directory of your ESP (which in theory is OS-independent) with all kinds of linux-specific files, like the kernel, whereas it would be tidier to stick all of those in one place like under /EFI/redhat.

The approach I favor (and this is just my opinion), is to mount your ESP on its own directory (/esp), and then bind-mount a subdirectory of your ESP onto /boot. So then you get the advantage of a tidy ESP and the advantage of existing tools finding what they want in /boot. The disadvantages are a slightly more complicated fstab and the fact that you cannot have symbolic links in /boot (a FAT file system). Here is a snippet of an /etc/fstab file on a machine with this setup:

/dev/sda2               /esp            vfat            rw,nosuid,nodev,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro       0 2
/esp/EFI/redhat         /boot           none            rw,nosuid,nodev,bind    0 0
Answered By: user3188445
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.