23

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?

user128063
  • 677
  • 1
  • 6
  • 13
  • as I understand it, the configuration for the location of the kernel is in the efi partition. – Joe Mar 05 '16 at 08:04
  • Clearly the information has to be in the efi partition, but you never really specify it at any point (like you used to have to) when installing grub. – user128063 Mar 05 '16 at 08:06
  • in the .efi file that is generated when you run grub-efi – Joe Mar 05 '16 at 08:08

1 Answers1

14

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"

Joe
  • 1,236
  • 8
  • 17
  • It would be interesting to see if you could patch this file and change your configuration and uuid's and still boot without reinstalling Grub – Joe Mar 05 '16 at 08:31
  • Weird, I'm not able to find it. My ubuntu efi directory has a grub.cfg (in ascii) with the prefix and root information inside id. But my archlinux efi directory simply has a grubx64.efi that has no sign of the root and prefix commands you mentioned even when I read them in ghex. – user128063 Mar 05 '16 at 17:44
  • Not in ubuntu.efi look for boot.efi. the efi partition has a folder. Called efi and in it a folder called boot. – Joe Mar 07 '16 at 07:40
  • The efi folder has several efi binaries, one for windows, one for ubuntu and so on. The name of the efi file is irrelevant. The reason I wasn't able to find the uuid line is because my root partition is an lvm partition. It stores an lvmid instead! – user128063 Mar 09 '16 at 06:10
  • I do not think your efi boot partition gets mounted into your Linux system. I had to mount it separately. Using mount /dev/sda1 /.... Then I get a file labeled EFI in that directory. opening that I get my 2 operating systems (steamos, gentoo) and another folder called BOOT. This boot file is the one I am referring to. Inside of each file is a binary .efi file. The BOOT folder ends up containing "BOOTX64.EFI" and contains the segments above. I think this is the partition you are referring to. – Joe Mar 09 '16 at 06:38
  • You're right, it does not, it has to be mounted, unless it's in your fstab. I don't follow your point though... – user128063 Mar 09 '16 at 06:43
  • I'm just curious about how efi is setup on your system. Mostly because in gentoo you have to configure these things by hand. – Joe Mar 09 '16 at 06:44
  • In most systems you have to set it up by hand as far as I know, especially if you want to multiple boot. Make a gpt partition table using gdisk, give it the EFI partition type (It's some hex code like ef00). Format it in fat32. Make your linux partitions, lvm whatever, install linux. Then when you install grub, do `grub-install --efi-directory=/mnt/efi-partition --boot-directory=/boot --target=x86_64-efi`. Windows however will detect your efi partition automatically and put in its own boot.efi file. You can set the boot order for these quite easily. – user128063 Mar 09 '16 at 06:55
  • 1
    Oh, sorry I misread your previous post. Stackexchange cut off your previous post at the part where you described your system. Your description is of a single bootloader (grub) image (BOOTX64.EFI) that boots two operating systems as far as I can tell. Here are a few more possibilities: 1) steamos could also have it's own separate bootloader, for which it would have its own EFI file in the efi partition. 2) you have a hybrid EFI-legacy boot system where your steamos bootloader is stored in the MBR. You can see the efi bootorder is to use `sudo efibootmgr -v` on gentoo, but I'm sure you know this – user128063 Mar 09 '16 at 07:30