How does the grub efi loader find the correct grub.cfg and boot directory

biosbootgrub

As I understand it, the uefi bios loads grub.efi from the efi partition. This now loads a bunch of grub modules and the configuration file from the /boot directory.

But how does grub find the correct device in which the boot partition resides? In grub legacy, you'd usually install grub to a specific partition, using

# grub-install --root-directory=/dev/sda

So it's quite clear where it will look for the boot directory. How does grub-efi figure out the correct device?

Best Answer

After using ghex to examine my "BOOTX64.EFI" file in the efi partition I found this line.

search.fs_uuid a43d1f11-6ebe-477d-8be3-321a33bc37f9 root hd2,gpt4 
set prefix=($root)'/boot/grub'

This shows that the information for the location of grub (the boot partition) has been embedded by grub2-install into the BOOTX64.EFI file generated for the system.

Grub2 is then executed by the EFI loader and you get the grub interface to choose the operating system (kernel) to boot into or the default kernel is loaded.

Just to expand a bit: ".EFI" files are kind of like applications that the UEFI subsystem can execute. Intended to be used to both boot the system and provide a convenient place to run execution protection and anti-virus type programs.

They put the extensible in "Unified Extensible Firmware Interface"

Related Question