My computer has grub installed. During booting before normal.mod is loaded, I need to be able to run if and while commands in my config file which has been linked into core.img (using grub-mkimage -c myconfig.confg). In myconfig.config, I have an if statement and I kept getting "unknown command if" during booting. I saw an example in http://www.gnu.org/software/grub/manual/html_node/Embedded-configuration.html and looks like I just need to include search, test, and normal modules. Am I missing something? Thanks
Using grub, is it possible to use "if, while" during booting (before loading normal.mod)?
Asked Answered
Not sure whether this is a bug or the documentation is lacking information.
Anyway there is a workaround by putting your config file in a memdisk image which you can append to the core.img. The config file can then be executed - including scripting support - via configfile
:
Create a tarball formatted memdisk image including your config file:
tar -cf memdisk.tar myconfig.config
Create early.cfg
: (which will serve to execute myconfig.config
via configfile
):
configfile (memdisk)/myconfig.config
Create core.img
: (note that you will need the additional modules memdisk tar configfile
)
grub-mkimage -c early.cfg -m memdisk.tar -o core.img search test normal memdisk tar configfile
Oh, and not even comments work in the
-c
embedded file: it prints syntax error for #
. –
Skeptical BTW, it seems not possible to enter
normal
mode without loading some (external) fille. That's because normal
without any argument it loads the default ${prefix}/grub.cfg
. I'm not sure what happens if the file can't be loaded, but I guess it kicks back to rescue mode. –
Skeptical Actually, in that last case, it doesn't drop you to a rescue prompt, but to a normal prompt (assuming
normal
is included in core.img
) . Still not useful for scripting anything. –
Skeptical © 2022 - 2024 — McMap. All rights reserved.
-c
config runs in rescue mode with limited commands available. GRUB normally entersnormal
mode at the end of that file. help-grub.gnu.narkive.com/SgdiBpll/… For the same reason, you can't have menus in the-c
embedded config. That last bit is mentioned in the documentation. – Skeptical