site  contact  subhomenews

Dropping out to shell in initrd

August 01, 2020 — BarryK

The bootup sequence is first the kernel 'vmlinuz', then the 'initrd', then layered SFS filesystem with 'easy.sfs' and a switch_root onto the desktop.

The 'initrd' is a file containing a complete tiny Linux OS. It is a file that is loaded into RAM and then the 'init' script inside the 'initrd' is run. This 'init' script does lots of setting up, including put together the layered SFS filesystem and performs the switch_root onto it.

If the 'init' script encounters an error and is unable to continue, it will drop out to a shell in the initrd. That is, you will have a commandline prompt and can do basic CLI operations. For example type "ls" to list files. Users would hold down the power button at this stage, to turn off the PC, however, developers can poke around and try to find out what has caused the problem.

What we have now, to aid developers, is a really great console GUI text editor, as reported:

https://bkhome.org/news/202008/minimum-profit-3317-now-has-utf-8-support.html

Just type "mp <filename>" and there is a beautiful screen with pull-down menus and syntax highlighting.

I have added another feature, kernel boot parameter "qfix=dropout[0-6]", which will cause a deliberate drop out of 'init', at various points. For example, 'init' has this at line 519:

[ "$DROPOUT" == "0" ] && exit_to_initrd " Exited from init script early, nothing yet mounted."

Where $DROPOUT variable has the number extracted from that "qfix=dropout[0-6]". That line will cause a dropout to a console in initrd, and it will print the line number in the script where it exited, and the message as shown above.

You can then poke around, try out that nice 'mp'. Typing "exit" will exit from the console, back into the 'init' script, and bootup will continue.

What would be nice is a simple console file manager in the initrd.

Thinking also, might make this another option in the "Shutdown" menu. 

Tags: easy