Hey, On Wed, Apr 12, 2023 at 01:47:56PM +0200, Laszlo Ersek wrote: > 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
Yep, here is the driver: grub-core/disk/efi/efidisk.c > - 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. > 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). > 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. > 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 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel