April 19, 2024

EBAZ4205 Bitcoin miner board - linux and the "init" program

Unix old timers have fond memories of the "init" program, now largely displaced by systemd on modern systems. The days of "init" were simpler and kinder.

As much as I despise using the bourne shell as a general purpose programming language, the fact that the "init" scheme was based on a collection of shell scripts made it easy and simple to use the editor of your choice to manage the system.

The init program is the first actual process run by a linux system. It is responsible for launching every other process and becomes the ultimate parent of every process on the system.

The behavior of init is governed by the /etc/inittab file, which you ought to inspect, but perhaps not fiddle with. The one thing you could possibly want to fiddle with is the default runlevel, which is typically "5".

# The default runlevel.
id:5:initdefault:
You can type the "runlevel" command to see what the state of things is:
runlevel
N 5

Run levels

There are typically 7 of them (0-6) and typically they are not all used. At any moment the system is in one run level or another. A typical setup is:
0 - halt the system
1 - single user
3 - multi user
5 - multi user with GUI
6 - reboot the system
On the ebaz, 3 and 5 are identical. Both run the network. Level 1 (single user) does not run the network and requires a physical console to be in any way useful. I don't think I have ever seen a system where 2 or 4 were used.

There is a program "telinit" that is used to send a message to the init process telling it to change to a different runlevel. Typing "telinit 0" would halt the system (as an example).

The "rc" directories

In the /etc directory, there are 8 "rc" directories as follows:
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc0.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc1.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc2.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc3.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc4.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc5.d
drwxr-xr-x    2 root     root             0 Apr 21  2017 rc6.d
drwxr-xr-x    2 root     root             0 Jan  1  1970 rcS.d
Close eyes will have noticed the last directory has an "S" rather than a "5". The "S" stands for startup.

These directories contain shell scripts. As an example, here is what the contents of rcS.d looks like (the startup directory):

-rwxr--r--    1 root     root           200 Jun 29  2017 K95cgminer.sh
lrwxrwxrwx    1 root     root            19 Apr 21  2017 S02banner.sh -> ../init.d/banner.sh
lrwxrwxrwx    1 root     root            18 Apr 21  2017 S02sysfs.sh -> ../init.d/sysfs.sh
-rwxr--r--    1 root     root           858 Jun 29  2017 S03mountall.sh
lrwxrwxrwx    1 root     root            14 Apr 21  2017 S04mdev -> ../init.d/mdev
lrwxrwxrwx    1 root     root            21 Apr 21  2017 S05modutils.sh -> ../init.d/modutils.sh
lrwxrwxrwx    1 root     root            22 Apr 21  2017 S06alignment.sh -> ../init.d/alignment.sh
lrwxrwxrwx    1 root     root            22 Apr 21  2017 S06checkroot.sh -> ../init.d/checkroot.sh
lrwxrwxrwx    1 root     root            18 Apr 21  2017 S07bootlogd -> ../init.d/bootlogd
lrwxrwxrwx    1 root     root            34 Apr 21  2017 S29read-only-rootfs-hook.sh -> ../init.d/read-only-rootfs-hook.sh
lrwxrwxrwx    1 root     root            30 Apr 21  2017 S37populate-volatile.sh -> ../init.d/populate-volatile.sh
lrwxrwxrwx    1 root     root            19 Apr 21  2017 S38devpts.sh -> ../init.d/devpts.sh
lrwxrwxrwx    1 root     root            18 Apr 21  2017 S38dmesg.sh -> ../init.d/dmesg.sh
lrwxrwxrwx    1 root     root            17 Apr 21  2017 S38urandom -> ../init.d/urandom
lrwxrwxrwx    1 root     root            21 Apr 21  2017 S39hostname.sh -> ../init.d/hostname.sh
lrwxrwxrwx    1 root     root            21 Apr 21  2017 S55bootmisc.sh -> ../init.d/bootmisc.sh
lrwxrwxrwx    1 root     root            23 Apr 21  2017 S65inetd.busybox -> ../init.d/inetd.busybox
Scripts that begin with "S" are run when the level is entered, and the "K" (kill) scripts get run when the level is exited. They are run in the order given by the next digits. So S02 runs before S38 and so on.

Note that these are generally links to actual files in the init.d directory. This is just to save space and centralize things since many scripts are duplicated in most or all of the rc directories.

This gives you the general idea. Details of the scripts themselves is something that I don't intend to tackle here.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org