Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

39.9. sysvinit-3.18

System V init — PID 1, runlevels, telinit, shutdown, halt, reboot and poweroff

Version 3.18, release 1
Shelf base — The minimal userland and system daemons that every KDOS image boots with
Phase 30_foundation (Build Foundation), 70 of 127 in build order
Licence GPL-2.0-or-later
Homepage https://codeberg.org/thejessesmith/sysvinit
Build time 0.1 SBU
Installed size 232.8 KiB in 20 files
Recipe ports/core/base/sysvinit/kpkgbuild

About

sysvinit supplies PID 1. KDOS installs eight commands from it and nothing else: init, its alias telinit, halt with the aliases reboot and poweroff, shutdown, runlevel and killall5, with their manual pages and those of inittab(5) and initctl(5). init reads /etc/inittab, runs /etc/init.d/rcS at boot and rcK at shutdown, and respawns what inittab marks respawn: the display manager’s starter kdos-dm on the first console, and the agetty logins on the second console and the first serial port. Services are kept running by ksvc, not by init. Why sysvinit was chosen, and the one way to ask it for a runlevel, are in sysvinit as PID 1; the boot it drives is in rcS and the service scripts.

init and halt also write the boot, runlevel and shutdown records that who -b, who -r and last read, so the build is against utmps, like every other reader and writer of those records (Login records). init writes a record into /run/utmps/utmp only if that file already exists and is writable, and skips it without a word otherwise, which is why 06_utmps.sh creates the file empty before utmpd starts rather than leaving it to utmpd’s first request.

Why it is in KDOS

The comment above the 8 ports from skalibs to sed in script/phases/30_foundation/packages.txt:

utmps, the utmp and wtmp service over skalibs (shelves auth and base-libs): coreutils, sysvinit, util-linux and shadow build against it, and coreutils' depends installs both in the pinned run above, ahead of the other three.

Sources

Dependencies

Depends on: utmps.

Required by (1): kdos-installer.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/30_foundation/phase.env && kpkg install sysvinit'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base/sysvinit.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/base/sysvinit
echo '793d7427e219f1ccf122e7c55655cef5f3419adc620ec2ee0ed557e8c94b438f  sysvinit-3.18.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/sysvinit
SRC=$SRC_ROOT/sysvinit-3.18
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf sysvinit-3.18.tar.xz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

make -C src init halt shutdown runlevel killall5 VERSION=$version \
	CFLAGS="$CFLAGS -I/usr/include/utmps" LDLIBS="-lutmps -lskarnet"

install -Dm755 src/init src/halt src/shutdown src/runlevel src/killall5 -t "$PKG/sbin"
ln -s init "$PKG/sbin/telinit"
ln -s halt "$PKG/sbin/reboot"
ln -s halt "$PKG/sbin/poweroff"

install -Dm644 man/init.8 man/telinit.8 man/halt.8 man/reboot.8 man/poweroff.8 \
	man/shutdown.8 man/runlevel.8 man/killall5.8 -t "$PKG/usr/share/man/man8"
install -Dm644 man/inittab.5 man/initctl.5 -t "$PKG/usr/share/man/man5"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/sysvinit, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf sysvinit-3.18-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/sysvinit, and runs the triggers its paths call for.

Contents

Installed programs: halt, init, killall5, poweroff, reboot, runlevel, shutdown, telinit.

Installed directories: /usr/share/licenses/sysvinit.

Short descriptions

halt stop the system
init process control initialization
killall5 send a signal to all processes
runlevel find the previous and current system runlevel
shutdown bring the system down

Notes

build.sh names its five targets and installs them by hand; it does not run make install. Upstream’s install would also put down last, mesg, wall, utmpdump, sulogin, bootlogd, logsave, fstab-decode, readbootlog, a lastb link and a pidof link. Several of those names belong to other packages here (last, lastb, mesg, wall, utmpdump and sulogin to util-linux, logsave to e2fsprogs, pidof to procps-ng), and kpkg refuses a path a second package claims.

The programs go to /sbin, which on the installed system is a link to usr/sbin. telinit, reboot and poweroff are symbolic links: init and halt look at the name they were started under to decide what to do.