Skip to contentSkip to conversation

reading grub.cfg

DISCUSSION Laszlo Ersek 2 participants 2 messages Apr 12, 2023 – Apr 14, 2023

lore
Share & tools
lore
#0 lore raw

Hi,

sorry for the beginner questions in advance.

How does grub2 locate and read "grub.cfg"?

My (very superficial) understanding is this:

- grub2 relies on its own filesystem drivers; for example, it does not attempt to consume EFI_SIMPLE_FILE_SYSTEM_PROTOCOL directly on a UEFI system -- it presumably consumes the BlockIo and/or DiskIo protocols, as a dependency of its own filesystem drivers

- in one of those detected filesystems, it locates "grub.cfg", and reads it.

Is this more or less correct?

What about the following dependency problem:

- some filesystem driver is built as a grub2 module,
- grub.cfg contains a matching "insmod" grub2 command, loading said module,
- but "grub.cfg" is placed on a filesystem of that particular type.

Is this a realistic problem? If so, how is it solved? Is there something obvious I'm missing?

Another question: assuming an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL-based fs driver existed in grub2, a particular filesystem might then appear *twice* to grub2, once via its own "native" driver, and another time via the UEFI SimpleFs-backed driver. Would this be a problem?

Thanks for your patience!
Laszlo

#1 lore raw

Hey,

Quoted 4 lines · Laszlo Ersek

Hi,

sorry for the beginner questions in advance.

Quoted 8 lines

How does grub2 locate and read "grub.cfg"?

My (very superficial) understanding is this:

- grub2 relies on its own filesystem drivers; for example, it does not attempt to consume EFI_SIMPLE_FILE_SYSTEM_PROTOCOL directly on a UEFI system -- it presumably consumes the BlockIo and/or DiskIo protocols, as a dependency of its own filesystem drivers

Yep, here is the driver: grub-core/disk/efi/efidisk.c

Quoted 1 line

- in one of those detected filesystems, it locates "grub.cfg", and reads it.

It works in a bit different way. Please take a look at [1], [2], [3], grub-core/kern/main.c:grub_load_normal_mode() and grub-core/normal/main.c.

Quoted 9 lines

Is this more or less correct?

What about the following dependency problem:
- some filesystem driver is built as a grub2 module,
- grub.cfg contains a matching "insmod" grub2 command, loading said module,
- but "grub.cfg" is placed on a filesystem of that particular type.

Is this a realistic problem? If so, how is it solved? Is there something obvious I'm missing?

Required filesystem drivers (modules) are embedded into GRUB core.img and loaded automatically [4] (the picture mentions "stages" which are legacy thing and should not be used when you speak about GRUB2; though otherwise it is OK).

Quoted 4 lines

Another question: assuming an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL-based fs driver existed in grub2, a particular filesystem might then appear *twice* to grub2, once via its own "native" driver, and another time via the UEFI SimpleFs-backed driver.

Yes, if both drivers do not communicate between each other to remove duplicates then a given filesystem can be seen twice through different paths.

Quoted 1 line

Would this be a problem?

Due to lack of write support in the GRUB, except an environment file, it should not be big deal. Though I think it would be better if GRUB uses only EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and ignores "own drivers" where possible.

I hope that helps.

Daniel

[1] https://www.gnu.org/software/grub/manual/grub/grub.html#prefix
[2] https://www.gnu.org/software/grub/manual/grub/grub.html#root
[3] https://www.gnu.org/software/grub/manual/grub/grub.html#normal
[4] https://en.wikipedia.org/wiki/GNU_GRUB#/media/File:GNU_GRUB_on_MBR_partitioned_hard_disk_drives.svg