If I use GRUB 2 on a GPT-enabled partition, how does the loader "know" where to find its configuration file and other second stage's files?
Note: I found some mentions about a configuration file which is located in the same folder as GRUB's EFI loader and contains a chained load of "primary" configuration file from the specified partition, but that definitely is not true; there is only one "something.efi" file.
There are actual several ways this can happen:
grub-mkimage
(called by grub-install
) execution time.The latter is probably the functionality you are really asking for, and it's a combination of the default configuration file name (grub.cfg
), the prefix (default /boot/grub
, but it can be explicitly specified to grub-mkimage
) and the GRUB partition name for the partition where the prefix is located.
If I run strings /boot/efi/EFI/debian/grubx64.efi | tail -1
on my current workstation, it prints out the stored value: (,gpt2)/boot/grub
, telling grubx64.efi
to look for its configuration file in /boot/grub on GPT partition 2. The bit before the comma (the GRUB disk device name) gets filled in at runtime based on which disk the grubx64.efi
image itself was loaded from.
Dynamically loaded modules will also be searched for under this location, but in an architecture/platform-specific directory - in this case /boot/grub/x86_64-efi
.