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
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 isgrubx64.efi
. So the EFI variables would be located atEFI/bootloader-id/grubx64.efi
These executables are installed by
grub-install
running on their respective systems, though you might have to pointgrub-install
to that partition using--efi-directory
. And you may also have to choose the value ofbootloader-id
with--bootloader-id
. Different Linux distributions have different defaults forbootloader-id
. For example, Debian defaults todebian
. For more information aboutgrub-install
options, seeman 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. Andgrub.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.