Using grub, is it possible to use "if, while" during booting (before loading normal.mod)?
Asked Answered
V

1

7

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

Violoncellist answered 13/8, 2013 at 14:37 Comment(0)
H
4

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
Heartburn answered 7/10, 2019 at 3:56 Comment(4)
It's not really a bug: the -c config runs in rescue mode with limited commands available. GRUB normally enters normal 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
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.