01.5 initramfs - Kakemixen/CrossLFS-nix GitHub Wiki

During boot, the kernel mounts the rootfs on /, which is a special tmpfs. A cpio.gz archive containing files and directories is given to the kernel during initialization during boot, and the kernel then starts the /init process found in those files. ref.

The initramf archive can be generated with the cpio and the gzip command, but the kernel provides a stand-alone solution with usr/gen_init_cpio (path from linux tree). This has a neat config file specifying the different files that wil be put in the initramfs.

The goal of the initrams if (often) to mount another file system and start running with that as the new root. A quick guide can be found here.

In this stackoverflow answer, it is indicated that this /init process only inherits the last console= argument to the kernel. But I have observed that the process still only opens /dev/console, so we need to manuallyu start a shell from a controlling terminal, like /dev/ttyS0 for a serial connection, to be able to have job control (backgroun processess and such). Perhaps, while the kernel outputs boot messages to both console= arguments, only the last is persisted as the /dev/console device, allowing interaction over that medium, without being a controlling tty. Thankfulle, we have setsid cttyhack /bin/sh to get a controlling terminal during development.

One interesting this about using an external initramfs is that the kernel generates some basic files by default, mostly just the /dev/console device, as mention in the stackexchange here. This should not be relied upon, but it's an interesting lifeline.

Regarding continued use of initramfs, this stackexchange discussion seems interesting, even if the best solution is probably to call switch_root.