[英]How does the GRUB2 UEFI loader know where to look for the configuration file (or where the 2nd stage's files are located)?
If I use GRUB2 on a GPT-enabled partition how does loader "know" where to find its configuration file and other 2nd stage's files? 如果我在启用GPT的分区上使用GRUB2,加载程序如何“知道”在哪里找到其配置文件和其他第二阶段的文件?
Note: I found some mentions about a config file which is located in the same folder as GRUB's EFI loader and contains chained load of "primary" configuration file from the specified partition, but that definitely is not true - there is only one "something.efi" file. 注意:我发现一些配置文件的提及与GRUB的EFI加载器位于同一文件夹中,并且包含来自指定分区的“主”配置文件的链式加载,但这肯定不是真的 - 只有一个“东西。 efi“文件。
There are actual several ways this can happen: 实际上有几种方法可以实现:
grub-mkimage
(called by grub-install
) execution time. grub-mkimage
(由grub-install
调用)执行时决定的路径加载配置文件。 The latter is probably the functionality you are really asking for - and it's a combination of the default config file name ( grub.cfg
), the prefix (default /boot/grub
, but can be explicitly specified to grub-mkimage
) and the grub partition name for the partition where the prefix is located. 后者可能是你真正要求的功能 - 它是默认配置文件名(
grub.cfg
), 前缀 (默认/boot/grub
,但可以明确指定为grub-mkimage
)和grub的组合。前缀所在分区的分区名称。
If I run strings /boot/efi/EFI/debian/grubx64.efi | tail -1
如果我运行
strings /boot/efi/EFI/debian/grubx64.efi | tail -1
strings /boot/efi/EFI/debian/grubx64.efi | tail -1
on my current workstation, it prints out the stored value: (,gpt2)/boot/grub
, telling grubx64.efi
to look for its configuration file in /boot/grub on GPT partition 2. The bit before the comma (the GRUB disk device name) gets filled in at runtime based on which disk the grubx64.efi
image itself was loaded from. 在我当前的工作站上
strings /boot/efi/EFI/debian/grubx64.efi | tail -1
,它打印出存储的值:( (,gpt2)/boot/grub
,告诉grubx64.efi
在GPT分区2上的/ boot / grub中查找其配置文件。逗号前面的位( GRUB磁盘设备名称)在运行时根据grubx64.efi
映像本身加载的磁盘填充。
Dynamically loaded modules will also be searched for under this location, but in an architecture/platform-specific directory - in this case /boot/grub/x86_64-efi
. 动态加载的模块也将在此位置下搜索,但在架构/平台特定的目录中搜索 - 在本例中为
/boot/grub/x86_64-efi
。
for EFI image, I found that grub-install
or grub-mkimage
will always embed an early config
into the result EFI binary, regardless of whether or not you have specified the --config FILE
option. 对于EFI映像,我发现
grub-install
或grub-mkimage
将始终将early config
嵌入到结果EFI二进制文件中,无论您是否指定了--config FILE
选项。 If you do not specify the --config FILE
option, it will try to embed /boot/grub/x86-64_efi/load.cfg
, This early config file looks like this: 如果你没有指定
--config FILE
选项,它将尝试嵌入/boot/grub/x86-64_efi/load.cfg
,这个早期的配置文件如下所示:
search.fs_uuid 8ef704aa-041d-443c-8ce6-71ac7e7f30da root hd0,gpt1
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg # this line seems can be omitted, because it seems to be the default next action
uuid
means uuid of file system, not of partition, you can use blkid to list it. uuid
表示文件系统的uuid,而不是分区,你可以使用blkid列出它。 hd0,gpt1
is just a hint. hd0,gpt1
只是一个提示。 set root=hd0,gpt1
set root=hd0,gpt1
This default behavior of auto embedding is different as in BIOS mode, the latter by default only embed a prefix string like (,gpt3)/boot
without bothering search.uuid. 这种自动嵌入的默认行为与BIOS模式不同,后者默认只嵌入像
(,gpt3)/boot
这样的前缀字符串(,gpt3)/boot
而不会打扰search.uuid。
I also found that Ubuntu bionic EFI image embedded a early config like this https://source.puri.sm/pureos/core/grub2/blob/master/debian/build-efi-images#L64 我还发现Ubuntu仿生EFI图像嵌入了这样的早期配置https://source.puri.sm/pureos/core/grub2/blob/master/debian/build-efi-images#L64
if [ -z "\$prefix" -o ! -e "\$prefix" ]; then
if ! search --file --set=root /.disk/info; then
search --file --set=root /.disk/mini-info
fi
set prefix=(\$root)/boot/grub
fi
if [ -e \$prefix/$platform/grub.cfg ]; then
source \$prefix/$platform/grub.cfg
elif [ -e \$prefix/grub.cfg ]; then
source \$prefix/grub.cfg
else
source \$cmdpath/grub.cfg
fi
The cmdpath
is the DIR of efi binary, so it will fallback to the grub.cfg in the same dir of the efi binary, as you found. cmdpath
是efi二进制文件的DIR,因此它将回退到efi二进制文件的同一目录中的grub.cfg,正如您所发现的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.