💾 Archived View for callistix.srht.site › projects › minimal_rpi › pages › 010_initsystem.gmi captured on 2024-03-21 at 15:12:54. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
The requirements for my init system are:
The most minimal init systems I found are `sinit` [1] and Rich Felker's init [2], so I will read through their code to understand how they work. I do like my code well commented, but unfortunately above examples have almost no comments at all, but they're simple enough to figure it out.
I've created a repository containing a commented version of Rich Felkner's init [3] and a README with a description how to set up a toolchain for cross compiling [4]. For convenience I also added a `Makefile`.
After cross compiling the `init` binary, I'm copying to the `root`, changing the file's ownership with ` chown root: init`. I also create an executable empty `/etc/rc` file:
touch etc/rc chmod 755 etc/rc
At boot time the kernel now tries to find the `init` command in a couple of places like `/sbin/init`, and `/etc/init` first, before finally detecting it in `/bin`. We add the correct path as kernel parameter to avoid this, by running `make menuconfig` again on the kernel sources, adding the `init=` parameter in the `Boot options` -> `Default kernel command string` field:
root=/dev/mmcblk0p2 rootwait init=/bin/init
Again, the kernel is compiled and the resulting image is copied to the new SD card. At boot time the kernel now loads `/bin/init` without trying other locations.
[2] minimal init daemon by rich felker, author of musl libc
[3] rpi4_minimal_linux/src/init.c
[4] callistix/rpi4_minimal_linux
⬅ 9. Using the new kernel with an empty SD card
➡ 11. Boot into an interactive session
⬆ The minimal Raspberry 4 project
Created: 9/Feb/2024
Modified: 9/Feb/2024