381. The pack store and the base pack
This step prepares the shipped system to receive packs, and can optionally put a copy of KDOS itself on the medium as one. Read it if you use KDOS_PACK_KDOS=1, or want to know why a fresh image’s pack store looks the way it does.
A pack is a single file holding a read-only EROFS image (a compressed, read-only filesystem) and its metadata. The root daemon kdos-packd installs packs into the pack store under /var/lib/kdos/packs, and a box, KDOS’s name for a container an application runs in, can be composed from packs. The medium carries no application packs: an application is built into container images on the machine that asks for it, or imported as packs exported on another machine.
So script/phases/70_image/100_packs.sh bakes nothing by default. It:
- creates the two directories the pack daemon needs;
- with
KDOS_PACK_KDOS=1, packs the root itself as the base packkdos: a clean KDOS inside a running one, to build and test ports in.
Unlike every other step of the phase, this one does not source phase.env. It runs with only the variables script/chroot/exec.sh passes, and the two it reads beyond those have defaults in the script, noted below.
The store directories
STORE=/var/lib/kdos/packs
mkdir -p "$STORE/staging" "$STORE/mnt"
chmod 01777 "$STORE/staging"
script/phases/70_image/100_packs.sh, lines 30–33
staging is where an import is copied before the daemon verifies it, and mnt holds the daemon’s mounts, one mnt/<id> per pack, read-only, nosuid and nodev. Staging is mode 01777, world-writable with the sticky bit, because it is the one place an unprivileged write may land, and the only argument kdos-packd’s install accepts is a file name inside it. The daemon also sets that mode when it starts, but the image ships it already set: a first boot whose staging were 0755 would refuse an import until the daemon had run once.
Removing an old base pack
rm -rf /kdos/build/kdos-base
script/phases/70_image/100_packs.sh, lines 87–87
build/ survives from build to build, and the flag does not. So build/kdos-base/ is deleted on every run, before the step decides whether to make a pack, and the only base pack 110_iso.sh can find is one this run made. A pack left by an earlier run with the flag on is removed both when the flag is now off and when a tool the pack needs is missing.
The base pack
On a machine booted from a medium that carries it, kdos-box create ports base=pack:kdos makes a box named ports whose root is this image’s root, so a port can be built and tested on a running KDOS without touching the machine itself. The pack is opt-in because it costs a second compression of the whole root on every build, for a base most machines never use. To make one, on the machine you build on:
make build KDOS_PACK_KDOS=1 BUILD_ARGS="--phases 70_image"
It runs only when the flag is set and both mkfs.erofs (from erofs-utils) and kdos-pack are installed. With the flag set and either tool missing, the step prints a note saying there is no kdos base pack and carries on, and build/kdos-base/ does not exist, so 110_iso.sh has no pack to copy.
The metadata
echo "[packs] packing this rootfs as base pack 'kdos'..."
OUT=/kdos/build/kdos-base
rm -rf "$OUT"
mkdir -p "$OUT"
cat > "$OUT/meta" <<META
id = kdos
version = ${KDOS_VERSION:-0.2}
kind = base
summary = KDOS itself — a clean tree to build and test ports in
META
script/phases/70_image/100_packs.sh, lines 97–106
version is KDOS_VERSION when the environment has one and the script’s fallback otherwise. script/chroot/exec.sh passes no KDOS_VERSION, so a build from make build always writes the fallback.
Testing the excludes
probe=$(mktemp -d)
mkdir -p "$probe/src/drop" "$probe/src/deep/er/still" "$probe/src/keep"
head -c 2000000 /dev/urandom > "$probe/src/drop/big"
head -c 2000000 /dev/urandom > "$probe/src/deep/er/still/big"
echo k > "$probe/src/keep/a"
# A NESTED path as well as a top-level one, because half the list is
# nested — `var/cache`, `var/lib/kdos/packs` — and a top-level-only probe
# would pass while the excludes that matter did nothing.
mkdir -p "$probe/src/proc"
head -c 2000000 /dev/urandom > "$probe/src/proc/big"
mkfs.erofs -b 4096 --exclude-path=drop --exclude-path=deep/er/still \
--exclude-regex='^(proc)/' \
"$probe/out.erofs" "$probe/src" >/dev/null 2>&1 || true
probe_sz=$(stat -c %s "$probe/out.erofs" 2>/dev/null || echo 0)
rm -rf "$probe"
if [ "$probe_sz" = 0 ] || [ "$probe_sz" -gt 500000 ]; then
echo "[packs] this mkfs.erofs did not honour --exclude-path" >&2
echo "[packs] (a 2 MB directory told to be excluded came back as" \
"${probe_sz} bytes); refusing to pack the rootfs" >&2
exit 1
fi
script/phases/70_image/100_packs.sh, lines 112–132
mkfs.erofs --exclude-path matches an exact literal path, relative to the tree being packed, and a path that matches nothing is not an error: --exclude-path=/kdos, with its leading slash, is accepted and excludes nothing. Here that would pack the repository, bound at /kdos and /ports, into the image, and fill the disk. So before it packs the root the step packs a small fixture: two 2 MB directories excluded by path, one of them nested three levels down, and a 2 MB file inside a directory excluded by the same kind of pattern the real run uses. An image that honoured all three is a few kilobytes; one over 500,000 bytes, or none at all, stops the phase.
Packing the root
mkfs.erofs -zzstd -b 4096 \
-T "${SOURCE_DATE_EPOCH:-1735689600}" --all-time \
--force-uid=1000 --force-gid=1000 \
-U "$(kdos-pack uuid kdos)" \
--exclude-regex='^(proc|sys|dev|tmp|run|mnt|media|var/cache|var/log)/' \
--exclude-path=kdos --exclude-path=ports --exclude-path=build \
--exclude-path=var/lib/kdos/packs \
--exclude-path=home/kdos/.local/share/containers \
"$OUT/kdos.erofs" / >/dev/null
script/phases/70_image/100_packs.sh, lines 155–163
-zzstd- Compress with zstd.
-b 4096- A block size of 4096 bytes.
-T "${SOURCE_DATE_EPOCH:-1735689600}" --all-time-
Give every file the same timestamp instead of its real modification time, so the same tree gives the same image. The step does not source
phase.envandexec.shdoes not passSOURCE_DATE_EPOCH, so the value is the script’s fallback, which is the same valuescript/env/common.envsets. --force-uid=1000 --force-gid=1000-
Record every file as owned by UID and GID 1000. A box runs with
--userns keep-id, so the process inside it is UID 1000, not root. Every other pack is made bykdos-pack build, which forces the same owner. Packed with the real owners, the root would be root’s from/down, and the box’s user could create nothing in it; podman fails at the first file it needs to make. A pack is mountednosuid, so the owner grants nothing either way. -U "$(kdos-pack uuid kdos)"-
The filesystem UUID, derived from the pack id the same way
kdos-pack buildderives it.mkfs.erofspicks a random one by default, and an image that differs on every run gives a differentkdos-pack imagehashevery time. --exclude-regex='^(proc|sys|dev|tmp|run|mnt|media|var/cache|var/log)/'-
Leave out everything inside these directories, but keep the directories. A container root without
/proc,/sys,/dev,/tmpor/runto mount onto cannot start at all, and podman reports a missing mount point for a box that was created without complaint. Software in the box expectsvar/cacheandvar/logto exist as well. --exclude-path=kdos,ports,build-
/kdosand/portsare the repository’s bind mounts in the chroot. They are gigabytes in size, and the output itself is written under/kdos/build./buildis left out as well, as it is fromsystem.sfs. --exclude-path=var/lib/kdos/packs-
The root’s own pack store,
stagingandmntwith whatever they hold, is left out of the pack. --exclude-path=home/kdos/.local/share/containers- podman’s own store, which a clean tree to build ports in must not carry.
/-
The source tree, the root the step runs in: the image stage, so the base pack carries the base, or
build/fsunderKDOS_IMAGE=full. The excludes are written without a leading slash because they are matched relative to it.
kdos-pack assemble "$OUT/kdos.erofs" "$OUT/meta" "$OUT/kdos.kpack"
rm -f "$OUT/kdos.erofs"
echo "[packs] kdos base pack: $(du -h "$OUT/kdos.kpack" | cut -f1) (on the medium)"
script/phases/70_image/100_packs.sh, lines 173–175
kdos-pack assemble wraps the image made outside kdos-pack with the metadata into a .kpack, and the bare image is deleted. The excludes are this step’s own, which is why the image is made here and not by kdos-pack build.
Where the pack goes
The pack is written to build/kdos-base/kdos.kpack, outside the root. The pack store is inside the root, so a pack written there would be squashed into system.sfs, and since this pack is itself a compressed copy of the root, the medium would carry the root twice. With the same flag, 110_iso.sh copies it to /packs/kdos.kpack on the medium, beside system.sfs. kdos-packd scans /mnt/iso/packs, where the booted medium appears, for *.kpack, so base=pack:kdos works on the live system with nothing installed.
What it leaves
On the image, /var/lib/kdos/packs/staging at mode 01777 and /var/lib/kdos/packs/mnt, both empty. With KDOS_PACK_KDOS=1 and both tools installed, build/kdos-base/ holds meta and kdos.kpack. Without the flag, or with either tool missing, build/kdos-base/ does not exist.
See also
- Where a pack comes from: the routes a pack takes onto a machine
- Building the root-filesystem pack: the rules the step keeps
- Create with a box base:
kdos-box createandbase=