You are not logged in.

#1 2025-05-08 12:51:12

kuolemaaa
Member
Registered: 2025-05-08
Posts: 3

[SOLVED] How grubx64.efi knows how and where to read its config file?

I dont know if this is the right place to ask this kind of question but I want to know more about the booting process with UEFI firmware + GRUB2 and since I had an hard time to understand this piece of the process, here I am:

assuming a simple partition table like:
esp parition fat32 `/dev/sda1` mounted at `/boot`
linux fs ext4 `/dev/sda2` mounted at `/` (root)

/boot/ usually contains:
- ./EFI/BOOT/BOOTX64.efi (uefi fallback)
- ./EFI/GRUB/grubx64.efi (proper grub efi application)
- ./grub/ directory with grub.cfg and stuff
- ./initramfs images
- ./vmlinuz kernels

I understand that the firmware is instructed by efibootmgr to load and execute a specific efi application on a specific device,partition and path
for example: # efibootmgr -c -d /dev/sda -p 1 -l '\EFI\GRUB\grubx64.efi' -L GRUB

Q1: but how grubx64.efi knows how to behave once it is started? how it knows where to look for its config file (i assume grub efi app reads the /boot/grub/grub.cfg)
Q2: what happens if the esp partition, /boot partition and /root partition are 3 different partitions mounted accordingly?

Last edited by kuolemaaa (2025-05-09 11:06:02)

Offline

#2 2025-05-08 13:07:49

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,654

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

That information is embedded into the executable by grub-install.

Offline

#3 2025-05-08 13:10:43

frostschutz
Member
Registered: 2013-11-15
Posts: 1,537

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

Embedded configuration. You can check `strings -w grubx64.efi` if you can find it in there somewhere. Usually the UUID of the partition with the Grub config and modules. All modules necessary to reach it also embedded (you can specify more modules to embed at grub-install time.)

Grub also keeps a copy of the configuration it embeds in /boot/grub/*/load.cfg, however editing this file is useless since its re-generated everytime you run grub-install.

Offline

#4 2025-05-08 16:53:31

kuolemaaa
Member
Registered: 2025-05-08
Posts: 3

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

At this point, I guess,  grubx64.efi is an efi application that is (sort of) parameterized and compiled every time grub-install is launched?

Offline

#5 2025-05-08 20:26:53

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 24,378

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

Basically, yes.

Offline

#6 2025-05-09 11:03:43

kuolemaaa
Member
Registered: 2025-05-08
Posts: 3

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

Thank you all. Marking it as solved. But if you have resources in order to learn in depth this mechanism I am glad to look at them.

Offline

#7 2025-05-09 13:44:14

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 352

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

GRUB is opensource. Unlikely you'll find a detailed description how it works except in its source code.

Offline

#8 2025-05-09 14:30:41

cryptearth
Member
Registered: 2024-02-03
Posts: 1,418

Re: [SOLVED] How grubx64.efi knows how and where to read its config file?

a start could be: https://github.com/rhboot/grub2/blob/ma … -install.c
as already mentioned: everytime grub-install is run a new binary is formed (this is true for non-efi i386 legacy, uefi, other platforms supported by grub) which includes required information where to load grub.cfg from and all stuff required to access it
tldr: unless you actively developing low level like design your own hardware and how to bring it up from cold to a running kernel all you need to know is where grub.cfg has to be placed according to the parameters given to grub-install and run grub-mkconfig afterwards
HOW all that the magic works isn't something one has to understand to just use it

Offline

Board footer

Powered by FluxBB