Part XV. The image
This part follows the last phase of the build, 70_image, which turns the installed tree of packages into the ISO you write to a USB stick. Read it when you are building KDOS yourself and want to know what happens between the last package and build/iso-build/kdos.iso, or when an image step has stopped your build.
The phase makes no packages. Starting from the root the package phases built in build/fs, it:
- with
KDOS_MAKE_BINHOST=1, makes the binary host (the signed set of prebuilt packages machines can install from), and trims the package store to its size limit; - trims the stage, an overlay over that root whose changes land in
build/image-upper, down to the base the ISO carries, and removes what only the build needed; - writes the launchers, the identity stamp, the theme, the user homes and the indexes the shipped system expects;
- checks the result and writes a ledger of what the image spends its bytes on;
- builds the initramfs, the optional base pack, the recipe tree and finally the ISO.
Each step script has a chapter here, in the order the phase runs them. This page covers what every step has in common: where it runs, the environment it gets, why the phase keeps no snapshot, the order the steps depend on, and the checks that can stop the phase.
Where the steps run
70_image is a script phase, like Part III, and a chroot phase, like every package phase. kdosbuild runs each script in sorted order, in the container, as
script/chroot/exec.sh bash script/phases/70_image/<step>.sh
so the step itself runs in the chroot, as root, in /kdos (see Where a command runs). Which tree is / depends on the step and on KDOS_IMAGE:
| Steps | KDOS_IMAGE=base, the default |
KDOS_IMAGE=full |
|---|---|---|
010_binhost.sh, 015_pkgstore.sh |
build/fs |
build/fs |
017_stage.sh to 110_iso.sh |
the image stage, build/image-root: an overlay whose lower layer is build/fs and whose upper layer, build/image-upper, takes every write |
build/fs |
Under base, 017_stage.sh removes every package outside the base from the stage, and every later step works on what is left, so the ISO carries the base and build/fs keeps every package for the next build and the binhost; The image stage is the step. A path such as /etc/skel on these pages is therefore the stage’s /etc/skel under base, and build/fs/etc/skel on your machine under full. The steps that write outside the root write under /kdos/build, which is build/ on your machine.
No step of this phase has a mark. Each runs in full every time the phase runs, and 017_stage.sh starts the stage from an empty upper layer, so a step that writes a file first removes the copy an earlier run wrote: the stamp in /etc/os-release, the hardware database, the manual index, the font cache, the software catalogue, the staged recipe tree and the base pack are each made from nothing rather than updated.
No snapshot
# --- build-system metadata ---
# The orchestrator parses these from this file's own text and follows no
# `source`, so they stay here rather than in a shared file.
export KDOS_PHASE_TITLE="Image"
export KDOS_PHASE_DESC="trim rootfs, build initramfs, assemble the ISO"
# No snapshot: this phase is re-run on the tree it finds, never restored.
export KDOS_SNAPSHOT_PATHS=""
export CHROOT=1
script/phases/70_image/phase.env, lines 15–23
KDOS_SNAPSHOT_PATHS is empty, so kdosbuild archives nothing when this phase ends, and there is no 70_image restore point to pick. The phase is re-run on the tree it finds. Two things follow.
Under KDOS_IMAGE=base the steps that change / change the stage: the trim and the orphan sweep uninstall packages there, and the homes are written there. build/fs keeps every package, so a later --continue-from or a port rebuild carries on from the whole tree; 020_cleanup.sh cleans the stage’s copy of the build’s caches and /root, not build/fs’s. Under KDOS_IMAGE=full every step changes build/fs itself, and a later build carries on from the swept, cleaned tree.
Running only this phase makes a new image from the tree as it stands, which is all a change to packaging alone needs. On your machine:
make build BUILD_ARGS="--phases 70_image"
After one port’s rebuild it is --phases <its phase>,70_image --rebuild <port>, as Narrowing a build shows.
The environment
The rest of phase.env is short:
# ── the accent the medium ships in ────────────────────────────────────────
#
# THE NAME IS SPELLED ONCE FOR THE SHELL AND CHECKED AGAINST THE COMPILED ONE.
# libkcolor's `KCOL_DEFAULT_ID` is what every C consumer falls back to and a
# shell script cannot read it, so `050_theme.sh` proves the two agree rather
# than trusting this line — a build whose seeded theme differs from the one an
# unconfigured program picks is a desktop that changes colour on first login.
export KDOS_ACCENT=bone
source "${BASH_SOURCE[0]%/*}/../../env/chroot.env"
# This phase builds no port: it takes no pkg-config search path and no answered
# C++ probe, so a tool it runs sees the chroot's own defaults.
unset PKG_CONFIG_PATH ac_cv_prog_cxx_cxx11
script/phases/70_image/phase.env, lines 25–38
KDOS_ACCENT names the accent the medium ships in. 050_theme.sh seeds that accent’s theme into /etc/skel, and 110_iso.sh draws the boot menu in it. The same default is compiled into libkcolor as KCOL_DEFAULT_ID, which every program of KDOS’s own falls back to when no accent is configured. A shell script cannot read a C macro, so the name is written twice, once here and once in src/libs/libkcolor/kcolor.h, and 050_theme.sh stops the build when the two differ. To change the default accent, change both. The accents are listed in Theming.
chroot.env, and the common.env it sources, supply what every chroot phase has, among it SOURCE_DATE_EPOCH, which 085_fontcache.sh clamps the font directories to, and KPKG_SKIP_INDEX=man, which is why the manual index is written by 080_whatis.sh and not by each install. The phase builds no port, so it drops the pkg-config search path and the answered C++ configure probe that chroot.env sets for the package phases.
The chroot is entered with a cleared environment, so a make build variable reaches a step only when script/chroot/exec.sh names it (see env -i means every variable must be named). The ones this phase reads:
| Variable | Read by | Effect |
|---|---|---|
KDOS_MAKE_BINHOST=1 |
010_binhost.sh, 087_gates.sh, 110_iso.sh |
Writes a signed binary host to build/binhost/, checks that every package in it records its run-time needs, and lets a sources medium carry it |
KDOS_IMAGE |
script/chroot/exec.sh, 017_stage.sh, 087_gates.sh, 110_iso.sh |
base, the default, makes the ISO from the stage trimmed to the base; full makes it from build/fs, every package, and skips the base checks and the size gate |
KDOS_PKG_STORE, KDOS_PKG_STORE_MAX |
015_pkgstore.sh |
Evicts the package store down to the size given |
KDOS_GIT_COMMIT, KDOS_GIT_DIRTY, KDOS_GIT_DATE, KDOS_GIT_TIME |
010_binhost.sh, 045_identity.sh, 105_ports.sh |
Stamp the commit into the binhost index, /etc/os-release, /ports/TREE and /usr/share/kdos/SOURCES |
KDOS_GIT_TAG, KDOS_GIT_RELEASE |
010_binhost.sh, 045_identity.sh, 105_ports.sh |
Name the release the image is: KDOS_GIT_RELEASE is the tag on HEAD only when the checkout is clean, and all three read it; 105_ports.sh alone reads KDOS_GIT_TAG, the tag whatever the checkout’s state, and stops the build when it is not a valid release name |
KDOS_PACK_KDOS=1 |
100_packs.sh, 110_iso.sh |
Packs the root as the base pack kdos and puts it on the medium |
KDOS_ISO_SOURCES=1, KDOS_ISO_COMP, KDOS_ISO_BLOCK |
110_iso.sh |
Copy the tree onto the medium; choose the codec and block size of system.sfs |
KDOS_ISO_MAX, KDOS_ISO_GATE |
110_iso.sh |
The release size gate: a base ISO larger than KDOS_ISO_MAX bytes (1,900 MiB) fails the step unless KDOS_ISO_GATE=0 |
The Makefile works out the KDOS_GIT_* values from your clone. A build started any other way has none of them, and the steps that read them leave their stamps out, or write unrecorded, rather than invent one.
Every step sources phase.env itself, except 100_packs.sh, which sources nothing and runs with only what exec.sh passes; see The pack store and the base pack.
The order of the steps
The step numbers are the only sequencing, and these orderings matter:
010_binhost.shand015_pkgstore.shrun before017_stage.sh, so the binhost and the package store are made onbuild/fs, from every package; the binhost moves the kept packages out ofbuild/fs’s cache, which020_cleanup.shthen never touches underKDOS_IMAGE=base.017_stage.shruns before every step that reads or writes the root, so each of them, and the ISO, sees only the base.030_launchers.shand050_theme.shwrite into/etc/skel, and run before070_user.sh, which copies/etc/skelinto every home. A skel changed after that step reaches no home on this image.040_orphans.shruns before the indexes,060_udev_hwdb.sh,080_whatis.sh,085_fontcache.shand086_swcatalog.sh, so a swept package’s rules, manual pages, fonts and applications are not indexed.045_identity.shruns before100_packs.sh, so the base pack carries the stamped/etc/os-release.087_gates.shruns after the trim, the sweep and every index, so it checks the tree the image carries, and proves the base closure whole, and before090_initramfs.shand110_iso.sh, so a tree that fails it is never written into an image.088_ledger.shruns after087_gates.sh, so the ledger measures the tree the gates passed, and before110_iso.sh, whose size gate prints it.105_ports.shstages the recipe tree that110_iso.shappends tosystem.sfsas/ports.
The gates
Several steps check their own result and stop the phase when it is wrong, most of them because the tool they ran would have exited 0 either way. When the phase stops, the step’s last lines in the build log, most of them starting FATAL: or ERROR:, name the check that failed. 087_gates.sh is the image gate over the whole tree; the others are local to their step:
| Step | Stops the phase when |
|---|---|
010_binhost.sh |
The flag is on and no package was kept, every kept package is superseded, the index does not verify, or a current package is larger than one release asset |
017_stage.sh |
/ is not the stage’s overlay, imageset.py --check finds a name in ports/base, ports/buildonly or ports/groups that does not exist, kpkg remove fails, or a package to remove is still installed after the removal |
020_cleanup.sh |
A Python module a package owns has no bytecode |
030_launchers.sh |
No launcher table was written, or launchers survive a reconcile that found no packs |
040_orphans.sh |
No recipe is found under /ports/core, or more than half the installed packages would be removed |
045_identity.sh |
The build names a release whose version, without its v, is not the VERSION_ID in /etc/os-release |
050_theme.sh |
KDOS_ACCENT is not libkcolor’s default, /etc/skel does not name the accent, a new home’s global theme is not that accent’s, the qt5ct configuration names no KDOS palette, an installed colour scheme fails the contrast floors, the sddm account’s home is not under /var/lib or the accent’s greeter set is missing a file, or glib-compile-schemas writes no gschemas.compiled |
060_udev_hwdb.sh |
There is no *.hwdb source, or no trie was written |
070_user.sh |
A user’s home is not one directory under /home |
080_whatis.sh |
No manual root exists, or no mandoc.db was written |
085_fontcache.sh |
/usr/share/fonts is missing, no cache file was written, or fontconfig rejects it |
086_swcatalog.sh |
The catalogue it wrote lists no application |
087_gates.sh |
testing/linkcheck.py or testing/entrycheck.py reports a finding, script/lib/imageset.py --verify finds a kept package’s run-time need only a dropped package provides, testing/unowned.py finds a file no package owns under /usr/share/locale, man, doc or info, or, with KDOS_MAKE_BINHOST=1, a binhost package carries no record of its run-time needs (N: line) |
090_initramfs.sh |
No readelf reads a program’s libraries; a program the initramfs carries, or a library one of them links, is installed nowhere or missing from the archive; a program that must be util-linux’s or GNU’s is another userland’s; lvm2 is installed without lvm, dmsetup, thin_check or cache_check, or its udev rules run them from outside /usr/sbin; a udev rule a root needs is left out or runs a program the initramfs lacks; installed microcode left an empty or missing bundle; or /lib/modules is empty |
100_packs.sh |
With KDOS_PACK_KDOS=1: mkfs.erofs does not honour the excludes |
105_ports.sh |
ports/shelves, sources.idx, groups, RELEASE, buildonly or buildheaders, every recipe under /ports/core, or one of the book directories is missing; ports/RELEASE is over 16 KiB; the tag on HEAD is not a valid release name; a file over 16 MB is in the recipe tree; or no installed package’s source is in sources.idx |
110_iso.sh |
KDOS_ISO_COMP names no known codec or KDOS_ISO_BLOCK no block size, KDOS_ISO_MAX or KDOS_ISO_GATE is malformed, the kernel, the initramfs, the staged recipe tree or Limine is missing, /ports is not at its path in system.sfs after the append, or the finished image has no EFI partition, no MBR signature or no BIOS boot code, or a base ISO is larger than KDOS_ISO_MAX with KDOS_ISO_GATE=1 |
A step whose tool is not installed at all (kdos-appbox, udevadm, makewhatis, fc-cache, kdos-discover-catalog) prints a line saying so and exits 0, so a tree built without that package still makes an image.
What the phase leaves
Most steps change the root they run on, the stage or under KDOS_IMAGE=full build/fs, which 110_iso.sh squashes into system.sfs; each chapter says where its step’s output lands. Outside the root, under build/:
| Path | Written by |
|---|---|
build/binhost/, build/binhost-key/ |
010_binhost.sh, with KDOS_MAKE_BINHOST=1 |
build/image-upper/, build/image-work/, build/image-root/, build/image-stage.ok |
script/chroot/exec.sh and 017_stage.sh, under KDOS_IMAGE=base |
build/image-ledger |
088_ledger.sh |
build/initramfs/, build/initramfs.cpio.gz, build/ucode/, build/ucode.cpio |
090_initramfs.sh |
build/kdos-base/kdos.kpack |
100_packs.sh, with KDOS_PACK_KDOS=1 |
build/image-ports/ |
105_ports.sh |
build/sfs-var.pseudo, build/iso_root/, build/iso-build/kdos.iso |
110_iso.sh |
See also
- Packaging: 70_image: the phase in the whole journey
- The packaging steps: every step in one table
- Databases stamped into the image: the three indexes
- Boot and init: the initramfs and the A/B slots this phase writes
- Packs and boxes: the pack store and the base pack
- The base image: what the ISO carries and why