简体   繁体   English

GRUB2 UEFI加载器如何知道在哪里查找配置文件(或第二阶段文件所在的位置)?

[英]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: 实际上有几种方法可以实现:

  • Load an embedded config file. 加载嵌入的配置文件。
  • Load a config file in the same directory as the GRUB binary. 将配置文件加载到与GRUB二进制文件相同的目录中。
  • Load a config file from a path decided at 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-installgrub-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
  • The uuid means uuid of file system, not of partition, you can use blkid to list it. uuid表示文件系统的uuid,而不是分区,你可以使用blkid列出它。
  • The hd0,gpt1 is just a hint. hd0,gpt1只是一个提示。
  • You can change the first line into 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.

相关问题 计算机如何知道引导加载程序位于文件系统中的哪个位置? - How does a computer know where in the filesystem the bootloader is located? GRUB stage 1.5的代码驻留在磁盘上的位置是什么?它加载的地址是什么? - Where does code of GRUB stage 1.5 reside on disk and what is the address it is loaded? 如何在 Centos-8 下的命令行中列出和编辑 GRUB2 的“菜单项”? - How to list and edit GRUB2's "menuentry" in command-line under Centos-8? 没有操作系统的 Grub 是如何编程的? 是否可以在没有安装其他操作系统的新组装的 UEFI PC 中仅安装 grub 引导加载程序? - How was Grub programmed without OS? And is it possible to install only the grub bootloader in an newly assembled UEFI PC with no other OS installed? Windows Vista / 7中的BCD在哪里? - Where is the BCD located in windows vista/7? 在GRUB2中隐藏“正在加载初始ramdisk…”初始屏幕 - Hide “Loading initial ramdisk …” splash screen in GRUB2 UEFI 引导模式引导流程如何? - How does UEFI boot mode boot flows? 使用 grub 编辑文件 - Edit a file using grub 如何在没有 root 权限的情况下在图像文件上安装 grub? - How to install grub on image file WITHOUT root privilege? 为什么GRUB2不直接将diskboot.img加载到地址0x8000? - Why doesn't GRUB2 load the diskboot.img to address 0x8000 directly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM