使用grub,是否可以在引导期间(加载normal.mod之前)使用“if,while”?

use*_*024 7 grub

我的电脑安装了grub。在加载 normal.mod 之前的启动过程中,我需要能够在已链接到 core.img 的配置文件中运行 if 和 while 命令(使用 grub-mkimage -c myconfig.confg)。在 myconfig.config 中,我有一个 if 语句,并且在启动过程中不断收到“unknown command if”。我在http://www.gnu.org/software/grub/manual/html_node/Embedded-configuration.html中看到了一个示例,看起来我只需要包含搜索、测试和普通模块。我错过了什么吗?谢谢

xch*_*nge 4

不确定这是一个错误还是文档缺少信息。

无论如何,有一个解决方法,将您的配置文件放入 memdisk 映像中,您可以将其附加到 core.img 中。然后可以执行配置文件 - 包括脚本支持 - 通过configfile

创建一个 tarball 格式的内存磁盘映像,包括您的配置文件:

tar -cf memdisk.tar myconfig.config
Run Code Online (Sandbox Code Playgroud)

创建early.cfg: (这将用于myconfig.config通过执行configfile):

configfile (memdisk)/myconfig.config
Run Code Online (Sandbox Code Playgroud)

创建core.img:(请注意,您将需要附加模块memdisk tar configfile

grub-mkimage -c early.cfg -m memdisk.tar -o core.img search test normal memdisk tar configfile
Run Code Online (Sandbox Code Playgroud)