![](/img/trans.png)
[英]How does a computer know where in the filesystem the bootloader is located?
[英]How does the GRUB2 UEFI loader know where to look for the configuration file (or where the 2nd stage's files are located)?
如果我在启用GPT的分区上使用GRUB2,加载程序如何“知道”在哪里找到其配置文件和其他第二阶段的文件?
注意:我发现一些配置文件的提及与GRUB的EFI加载器位于同一文件夹中,并且包含来自指定分区的“主”配置文件的链式加载,但这肯定不是真的 - 只有一个“东西。 efi“文件。
实际上有几种方法可以实现:
grub-mkimage
(由grub-install
调用)执行时决定的路径加载配置文件。 后者可能是你真正要求的功能 - 它是默认配置文件名( grub.cfg
), 前缀 (默认/boot/grub
,但可以明确指定为grub-mkimage
)和grub的组合。前缀所在分区的分区名称。
如果我运行strings /boot/efi/EFI/debian/grubx64.efi | tail -1
在我当前的工作站上strings /boot/efi/EFI/debian/grubx64.efi | tail -1
,它打印出存储的值:( (,gpt2)/boot/grub
,告诉grubx64.efi
在GPT分区2上的/ boot / grub中查找其配置文件。逗号前面的位( GRUB磁盘设备名称)在运行时根据grubx64.efi
映像本身加载的磁盘填充。
动态加载的模块也将在此位置下搜索,但在架构/平台特定的目录中搜索 - 在本例中为/boot/grub/x86_64-efi
。
对于EFI映像,我发现grub-install
或grub-mkimage
将始终将early config
嵌入到结果EFI二进制文件中,无论您是否指定了--config FILE
选项。 如果你没有指定--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
表示文件系统的uuid,而不是分区,你可以使用blkid列出它。 hd0,gpt1
只是一个提示。 set root=hd0,gpt1
这种自动嵌入的默认行为与BIOS模式不同,后者默认只嵌入像(,gpt3)/boot
这样的前缀字符串(,gpt3)/boot
而不会打扰search.uuid。
我还发现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
cmdpath
是efi二进制文件的DIR,因此它将回退到efi二进制文件的同一目录中的grub.cfg,正如您所发现的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.