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

173.2. kdos-boxinit-0.1.0

pid 1 inside a pack box, in place of distrobox-init

Version 0.1.0, release 1
Source tree src/system/kdos-boxinit/
Phase 41_system (System), 961 of 1047 in build order
Licence MIT
Homepage https://github.com/kunaldawn/kdos
Build time 0.1 SBU
Installed size 132.6 KiB in 1 file
Recipe src/system/kdos-boxinit/kpkgbuild

About

kdos-boxinit is process 1 inside a pack box and a store box, in place of distrobox’s init. In order, it

  1. writes a user and group matching yours into the box, and creates the home directory;
  2. writes the box’s xdg-open and asound.conf, so links and sound reach the host;
  3. sets the search path and HOME;
  4. prints the container_setup_done marker the launcher waits for;
  5. stays alive, reaping orphaned processes.

What each step is for is in The box.

The package installs one file, /usr/libexec/kdos/kdos-boxinit. It is not run on the host: kdos-appbox bind-mounts it read-only into the box at /usr/libexec/kdos-boxinit and names it as the container’s entrypoint (What a pack box is created with). A store box is created the same way over its image. Only a development box that distrobox makes from somebody else’s image runs distrobox’s own init.

Why it is in KDOS

The comment above it in script/phases/41_system/packages.d/src-system.txt:

pid 1 inside a pack box, in place of distrobox-init: it creates the user and group matching the host's, sets the PATH that includes /usr/games, and prints the container_setup_done marker box_wait_ready() polls for. Static, because it is bind-mounted into a box whose /usr is Debian's and a musl-linked binary would look for its loader there.

Sources

None: the port builds from its own directory, /kdos/src/system/kdos-boxinit.

Dependencies

Depends on: nothing a recipe names.

Required by (1): kdos-appbox.

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/41_system/phase.env && kpkg install kdos-boxinit'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/system/kdos-boxinit.

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.

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/kdos-boxinit
SRC=$SRC_ROOT/kdos-boxinit-0.1.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"

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:

LIBS="$PORT_SRC/../../libs"

gcc $CFLAGS -O2 -std=gnu11 -D_GNU_SOURCE -Wall -Wextra -static-pie \
	-I"$LIBS/libkbase" \
	-o kdos-boxinit "$PORT_SRC"/main.c "$LIBS"/libkbase/*.c $LDFLAGS

install -Dm755 kdos-boxinit "$PKG/usr/libexec/kdos/kdos-boxinit"

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/kdos-boxinit, 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 kdos-boxinit-0.1.0-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/kdos-boxinit, and runs the triggers its paths call for.

Other files in the port directory, read by build.sh: main.c.

Notes

It is a process 1, with process 1’s obligations: if it exits the container goes with it, and if it stops reaping, every application that exits leaves a zombie until the process table fills.

It runs as the box’s root and takes the box’s name and the account it writes from its environment: kdos-appbox passes KDOS_BOX, KDOS_BOX_USER, KDOS_BOX_UID, KDOS_BOX_GID and KDOS_BOX_HOME when it creates the box. KDOS_BOX_SHELL is read too, but nothing passes it, so the account’s shell is /bin/bash. It runs no shell and builds no command line from those values.

container_setup_done, printed unbuffered on standard output, is the contract with the launcher, which reads it out of podman’s log. It is printed only after the account records are written: printed earlier, it would let a launch run a program in a box that has no such user yet.