s6-linux-init
Software
skarnet.org

The s6-linux-init-maker program

s6-linux-init-maker reads configuration options on the command line, and outputs a directory to place in the root filesystem as well as a script suitable as an init program.

s6-linux-init-maker only writes scripts. At boot time, these scripts will call commands provided by other skarnet.org packages such as execline or s6. It is the responsibility of the administrator to make sure that all the dependencies are properly installed at boot time, and that the correct options have been given to s6-linux-init-maker so that the programs are found on the root filesystem of the machine - else the scripts will crash.

Interface and usage

     s6-linux-init-maker \
       [ -c basedir ] \
       [ -l tmpfsdir ] \
       [ -b execline_bindir ] \
       [ -u log_user ] \
       [ -g early_getty ] \
       [ -2 stage2 ] \
       [ -r ] \
       [ -Z ] stage2_finish \
       [ -3 stage3 ] \
       [ -p initial_path ] \
       [ -m initial_umask ] \
       [ -t timestamp_style ] \
       [ -d dev_style ] \
       [ -e initial_envvar ] ... \
       dir > stage1

dir should then be copied by the administrator to the place declared as basedir. Be careful: it contains fifos, files with precise uid/gid permissions, and files with non-standard access rights, so be sure to copy it verbatim. The s6-hiercopy tool can do it, as well as the GNU or busybox cp -a or mv commands.

The stage1 script printed by s6-linux-init-maker on its stdout is then suitable as an init program. The administrator should copy it to /sbin/init and make it executable.

Boot sequence

When the kernel boots, it runs the stage1 script, and this is what happens:

stage2 is the responsibility of the administrator - it will not be written automatically! It should contain all the necessary initialization sequence to bring up a proper system. When stage2 is executed, the machine state is as follows:

There is nothing else. In particular, no filesystem has been mounted yet, including /proc and /sys; and no one-time initialization has been performed. The point of stage1 is only to make it possible to run stage2 with a logging infrastructure and a supervision infrastructure already available, and all the real machine and service initialization should happen in stage2.

Shutdown sequence

When s6-svscan is told to exit via an appropriate s6-svscanctl command, it executes into the stage3 script, which, like stage2, is the responsibility of the administrator. stage3 is run in the following state:

When s6-svscan receives a signal such as SIGINT, typically sent by the Ctrl-Alt-Del key combination or a reboot or poweroff command, it will run the corresponding script in tmpfsdir/service/.s6-svscan, which will first run stage2_finish, then send an exit command to s6-svscan as described above. This is useful if some commands need to be run before s6-svscan executes into stage3: for instance, if the machine state is maintained by a service manager such as s6-rc, all the services can be turned off in stage2_finish while s6-svscan is still alive, and then the last steps of the shutdown procedure can be performed in stage3.

Generally speaking, stage2_finish should undo what stage2 has done at boot time, so stage3 has very little work to do.

The examples/ subdirectory of the s6-linux-init package contains an example of /etc/rc.init, /etc/rc.tini and /etc/rc.shutdown scripts, suitable for stage2, stage2_finish and stage3 respectively. Those scripts can practically be used as is if the machine is managed by the s6-rc service manager.

s6-linux-init-maker options

Notes

The difficult parts of running s6-svscan as process 1 are:

The main benefit of s6-linux-init-maker is that it automates those parts. This means that it has been designed for real hardware where the above issues apply. If you are building an init system for a virtual machine, a container, or anything similar that does not have the /dev/console issue or the read-only rootfs issue, you will probably not reap much benefit from using s6-linux-init-maker: you could probably invoke s6-svscan directly as your process 1, or build a script by hand, which would result in a simpler init with less dependencies.