GRUB 2 – How Does GRUB 2 Work Under Multiple Linux Partitions with UEFI

boot-loadergrub2linuxuefi

When we install a new Linux, the installer will install a bootloader (efi file) at EFI partition and update the menu entry at NVRAM, and most likely set the newly added bootloader as default. The bootloader will read the /boot/grub/grub.cfg to load the kernel and initrd.

My question is, when there are multiple bootloaders (.efi) reside in ESP, are they identical? Since they are all GRUB2. Can each of them discover all the kernels in the system?

Since each OS's partition has /boot/grub/grub.cfg file, which one is being read by the default bootloader?

Best Answer

My question is, when there are multiple bootloaders (.efi) reside in ESP, are they identical? since they are all grub2. Can all of them discover all the kernel in the system?

If there are multiple UEFI Linux installations on a disk, they normally use the same EFI System Partition (ESP), but their respective EFI executables live in different subdirectories of the ESP, of the form EFI/bootloader-id. The EFI executables have the same name; for 64 bit installations it is grubx64.efi. So the EFI variables would be located at EFI/bootloader-id/grubx64.efi

These executables are installed by grub-install running on their respective systems, though you might have to point grub-install to that partition using --efi-directory. And you may also have to choose the value of bootloader-id with --bootloader-id. Different Linux distributions have different defaults for bootloader-id. For example, Debian defaults to debian. For more information about grub-install options, see man grub-install.

grub-install hard-wires the name of the boot/root devices into those executables using UUIDs.

These EFI executables are executed by the EFI firmware on the motherboard. Since the EFI executable knows the boot/root devices for its Linux installation, and since, by definition, grub.cfg has a fixed location relative to the boot/root devices, the EFI executable can execute the /boot/grub/grub.cfg corresponding to that installation. And grub.cfg of course has all the information needed to do a boot, including the names of the kernels installed on the system.

The Arch Wiki GRUB page has good coverage of these matters. See also the Debian Wiki UEFI page.

Related Question