383. The ISO
The last step of the build, script/phases/70_image/110_iso.sh, makes the file a user downloads and writes to a stick: build/iso-build/kdos.iso. Read this chapter to understand what is on the medium and why, to choose a compression or block size for your own image, or to work out why the last step of your build stopped.
The step works in this order:
- It copies the kernel and the initramfs (the small root the kernel starts first, which finds and mounts the real one).
- It squashes the root filesystem into
system.sfsand appends the recipe tree as/ports. - It writes the Limine boot menu.
- It makes the image with xorriso and checks that a stick written from it boots by BIOS and by UEFI.
- It holds the image to the size of one release asset.
The chapter goes through those parts in order, and ends with what the scripts do to make two builds of one tree give the same image, and what they leave to the clock.
How the finished medium boots is described in Limine and the kernel command line and The live medium and persistence.
Runs in: the chroot, as the last script step of 70_image
Reads: the root, which is the image stage trimmed to the base, or build/fs under KDOS_IMAGE=full; build/initramfs.cpio.gz from the initramfs step, the recipe tree 105_ports.sh staged in build/image-ports, with KDOS_PACK_KDOS=1 the base pack in build/kdos-base, and when the size gate fails, the ledger build/image-ledger
Writes: the pseudo-file build/sfs-var.pseudo, the tree build/iso_root/ and the image build/iso-build/kdos.iso; in the root, /boot/initramfs.cpio.gz
The ISO tree
echo "Building KDOS ISO..."
ISO_ROOT=/kdos/build/iso_root
rm -rf $ISO_ROOT
mkdir -p $ISO_ROOT
script/phases/70_image/110_iso.sh, lines 16–20
build/iso_root is made empty on every run. Everything the image holds is copied into it, and xorriso turns that directory into the image at the end.
The kernel and the initramfs
# 1. Copy Kernel and Initramfs
#
# THEY SIT ON THE MEDIUM, NOT IN THE EFI SYSTEM PARTITION, because Limine
# reads ISO9660 and a UEFI firmware never has to. That is what keeps the ESP
# down to the two megabytes Limine's own El Torito image is: a bootloader that
# could only read FAT would need the kernel and the initramfs copied into the
# ESP as well as onto the medium, and the image would carry both twice.
mkdir -p $ISO_ROOT/boot $ISO_ROOT/EFI/BOOT
if [ -f /boot/vmlinuz-kdos ]; then
cp /boot/vmlinuz-kdos $ISO_ROOT/boot/vmlinuz
else
echo "Error: /boot/vmlinuz-kdos not found!"
exit 1
fi
# THE MEDIUM'S INITRAMFS IS boot/initrd.img, A NAME VENTOY KNOWS. Ventoy
# boots an ISO without parsing limine.conf and adds its hook, which maps the
# ISO file on its exFAT partition to /dev/mapper/ventoy, only to an initrd at a
# path it recognises; /boot/initrd.img is one. Under any other name the kernel
# starts from a Ventoy stick with no device holding the medium and the scan
# ends at the rescue shell. The copy in the root's /boot keeps the name
# initramfs.cpio.gz, which kinstall and kdos-bootctl read, and goes into
# system.sfs so an installed system carries it.
if [ -f /kdos/build/initramfs.cpio.gz ]; then
cp /kdos/build/initramfs.cpio.gz $ISO_ROOT/boot/initrd.img
cp /kdos/build/initramfs.cpio.gz /boot/initramfs.cpio.gz
# The image's initramfs is the one for the image's kernel. One a `linux`
# postinstall built in this tree for an earlier kernel would be preferred
# over it by kinstall and `kdos-bootctl deploy`, and boot a stale base.
rm -f /boot/initramfs-kdos.cpio.gz
else
echo "Error: /kdos/build/initramfs.cpio.gz not found!"
exit 1
fi
script/phases/70_image/110_iso.sh, lines 22–56
The kernel the linux port installed as /boot/vmlinuz-kdos is copied to boot/vmlinuz, and the initramfs to boot/initrd.img, a path Ventoy recognises: Ventoy boots an ISO without reading limine.conf and adds its hook, which maps the ISO file on a Ventoy stick to /dev/mapper/ventoy, only to an initrd at a path it knows. Both sit on the ISO9660 filesystem, which Limine reads on BIOS and UEFI alike; see Where the kernel is kept. Either file missing stops the step.
The initramfs is also copied into the root as /boot/initramfs.cpio.gz. The root is squashed in the next part, so the copy is inside system.sfs, and a machine installed from the medium has it. /boot/initramfs-kdos.cpio.gz is removed, for the reason the comment gives: it is the name the linux package’s postinstall.sh writes, and one left there from an earlier kernel would be chosen ahead of this one.
system.sfs
The codec
# 2. Create System SquashFS
#
# zstd AT LEVEL 19 BY DEFAULT: the smallest image whose reads stay cheap,
# because the medium is read far more often than it is written. Measured on
# the base, 9.5 GB of package files in 1 MiB blocks: zstd:19 is 5% smaller than
# zstd:15 and decompresses at 1.1 GB/s on one core against zstd:15's 1.3;
# zstd:22 is the same size, since a 1 MiB block caps zstd's window. xz is 4%
# smaller than zstd:19 and xz-bcj (xz with the x86 branch filter, tried on
# every block) 6%, but both decompress at about 160 MB/s, seven times slower,
# on every boot and every first launch. KDOS_ISO_COMP=zstd:3 is a developer
# image, larger and quicker to write, for the rig, and never a release. ANY
# OTHER VALUE IS FATAL, so a typo cannot quietly ship a medium in a codec
# nobody chose.
ISO_COMP="${KDOS_ISO_COMP:-zstd:19}"
case "$ISO_COMP" in
xz) SFS_COMP=(-comp xz) ;;
xz-bcj) SFS_COMP=(-comp xz -Xbcj x86) ;;
zstd:[1-9]|zstd:1[0-9]|zstd:2[0-2])
SFS_COMP=(-comp zstd -Xcompression-level "${ISO_COMP#zstd:}") ;;
*) echo "FATAL: KDOS_ISO_COMP=$ISO_COMP is not xz, xz-bcj or zstd:<1-22>" >&2; exit 1 ;;
esac
# The block size, KDOS_ISO_BLOCK, 1M unless set: see the squash below. The
# same rule as the codec, a value squashfs does not take is fatal.
ISO_BLOCK="${KDOS_ISO_BLOCK:-1M}"
case "$ISO_BLOCK" in
4K|8K|16K|32K|64K|128K|256K|512K|1M) ;;
*) echo "FATAL: KDOS_ISO_BLOCK=$ISO_BLOCK is not a power of two from 4K to 1M" >&2; exit 1 ;;
esac
echo "Squashing Root Filesystem ($ISO_COMP, $ISO_BLOCK blocks)..."
script/phases/70_image/110_iso.sh, lines 58–86
KDOS_ISO_COMP picks the compression of system.sfs, the image of the whole root, and KDOS_ISO_BLOCK its block size. The Makefile passes both into the build container, and script/chroot/exec.sh passes them on into the chroot. The codec takes four forms:
KDOS_ISO_COMP |
mksquashfs gets | Use |
|---|---|---|
| unset or empty | -comp zstd -Xcompression-level 19 |
the default |
zstd:1 to zstd:22 |
-comp zstd -Xcompression-level <n> |
zstd:3 for a quicker image on the rig |
xz |
-comp xz |
xz at its defaults |
xz-bcj |
-comp xz -Xbcj x86 |
xz that tries the x86 branch filter on every block and keeps the smaller result |
KDOS_ISO_BLOCK is 4K, 8K and so on up to 1M, the powers of two squashfs takes; empty is 1M. Any other value of either stops the step, so a mistyped setting cannot produce an image. For example:
make build KDOS_ISO_COMP=zstd:3 BUILD_ARGS="--phases 70_image"
The default was measured on the base’s package files, 1,004 packages and 9.54 GB, squashed by squashfs-tools 4.7.5 on 16 threads; the read is unsquashfs -p 1 -pf /dev/null, every block decompressed on one core:
| Codec | Block | system.sfs |
Write | Read |
|---|---|---|---|---|
zstd:15 |
1M | 3,282 MiB | 80 s | 7.2 s |
zstd:19 |
1M | 3,106 MiB | 229 s | 8.7 s |
zstd:22 |
1M | 3,106 MiB | 286 s | 8.7 s |
xz |
1M | 2,977 MiB | 237 s | 58.1 s |
xz-bcj |
1M | 2,911 MiB | 484 s | 61.6 s |
zstd:19 |
128K | 3,321 MiB | 357 s | 11.0 s |
xz-bcj |
128K | 3,121 MiB | 418 s | 69.1 s |
The default follows one rule: the smallest ISO whose boot stays within 10% of the fastest codec’s. zstd:19 reads the whole image 1.5 s slower than zstd:15 on one core, and xz-bcj 53 s slower than zstd:19. The medium is read on every boot and every first launch of a program, so the xz codecs’ few per cent of size do not pay for reads about seven times slower, and zstd:19 is the default. The codec gives the same measurement with the development and documentation payload left out.
The squash
# The pseudo filesystems, build artifacts and caches are excluded, and the
# mountpoints they need are recreated as empty directories — an excluded /proc
# is a root that cannot mount one. /var/cache and /var/log come back holding
# only the directories installed packages claim under them, empty, with the
# tree's mode and owner: a daemon creates its own directory there with a single
# mkdir(2), which fails with no parent, and some (smbd's log and cache
# directories, libvirt's) are never created by the daemon at all. A claimed
# directory left out is also `missing` to `kpkg check --all`, which fails a
# pristine image. The installed system is copied from this root. A package
# FILE under either is not carried: the build's logs and caches are what the
# exclusion is for.
#
# `-e` CONSUMES THE REST OF THE COMMAND LINE: every argument after it is an
# exclude pattern, so it goes LAST and every option goes ahead of it. An option
# placed after `-e` is not an error — it is silently taken as a filename to
# exclude, which leaves the compressor at the gzip default, drops every
# pseudo-directory, and appends to an existing system.sfs instead of replacing
# it.
#
# 1 MiB BLOCKS BY DEFAULT, the largest squashfs has. A block is the unit
# compressed and the unit read: the base is 7% smaller than at 128 KiB,
# and a cold random read of a small file pulls up to a whole MiB off the medium
# and decompresses it, which a USB stick serves more slowly.
#
# /ports is the repository's bind mount and is excluded here; the recipe tree
# 105_ports.sh staged is appended below in its place. var/tmp/kdos-home is the
# build's HOME (script/chroot/exec.sh), recreated by every chroot entry after
# 020_cleanup.sh emptied var/tmp.
#
# A pseudo-directory whose parent is neither in the image nor defined first is
# fatal to mksquashfs, so every claimed directory brings its parents, and the
# sorted list puts each parent ahead of its children.
VAR_PSEUDO=/kdos/build/sfs-var.pseudo
{
echo 'var/cache d 755 0 0'
echo 'var/log d 755 0 0'
grep -h -e '^\./var/cache/..*/$' -e '^\./var/log/..*/$' /var/lib/kpkg/db/* |
while IFS= read -r d; do
d=${d#./}
d=${d%/}
while [ "$d" != var/cache ] && [ "$d" != var/log ]; do
printf '%s\n' "$d"
d=${d%/*}
done
done |
LC_ALL=C sort -u |
while IFS= read -r d; do
m=$(stat -c '%a %u %g' "/$d" 2>/dev/null) || m="755 0 0"
printf '"%s" d %s\n' "$d" "$m"
done
} > $VAR_PSEUDO
mksquashfs / $ISO_ROOT/system.sfs \
-noappend "${SFS_COMP[@]}" -b "$ISO_BLOCK" \
-p "proc d 555 0 0" \
-p "sys d 555 0 0" \
-p "dev d 755 0 0" \
-p "tmp d 1777 0 0" \
-p "run d 755 0 0" \
-p "mnt d 755 0 0" \
-p "media d 755 0 0" \
-pf $VAR_PSEUDO \
-e proc sys dev tmp run mnt media var/cache var/log var/tmp/kdos-home build kdos ports
script/phases/70_image/110_iso.sh, lines 87–148
First the step writes build/sfs-var.pseudo: a line var/cache d 755 0 0 and one for var/log, then one line for every directory an installed package claims below either, read from the ./var/…/ lines of the package database’s manifests, with each directory’s parents added and the list sorted so a parent comes before its children (mksquashfs refuses a definition whose parent does not exist yet). Each carries the directory’s mode, owner and group in the root, so samba’s var/log/samba comes out as "var/log/samba" d 755 0 0.
mksquashfs reads the whole root, /, and writes iso_root/system.sfs.
-noappend-
Replace any
system.sfsalready there instead of adding to it. -comp …- The codec chosen above.
-b "$ISO_BLOCK"-
1 MiB blocks unless
KDOS_ISO_BLOCKnames another size; 1 MiB is the largest squashfs allows. The comment gives the trade: a base 7% smaller than in 128 KiB blocks, and a read of a small file that pulls a whole block off the medium. -p "proc d 555 0 0"and the rest- Pseudo-definitions: each makes a directory in the image with the given mode, owned by user 0 and group 0. They put back, empty, the directories the exclusions below take out, so that the booted system has its mount points.
-pf $VAR_PSEUDO-
The same, read from the file written above:
/var/cacheand/var/logholding only the directories packages claim, empty. A daemon that makes its directory with onemkdirneeds the parent,smbdand libvirt make none of theirs, andkpkg check --allreports a claimed directory that is absent asmissing, which would fail a freshly booted image. -e proc sys dev tmp run mnt media var/cache var/log var/tmp/kdos-home build kdos ports-
Leave these out.
proc,sys,dev,tmpandrunare the chroot’s own mounts;mntandmediaare mount points;var/cacheandvar/loghold the build’s caches and logs;var/tmp/kdos-homeis the build’s home directory;kdosandportsare where the chroot mounts the repository, andbuildis a directory of that name in the root, if one is there.-etakes every argument after it as a name to exclude, so it is the last option on the line; the comment says what goes wrong otherwise.
/ports
# 2a. The recipe tree, appended as /ports.
#
# An append adds the staged directory's entries to the root of the image and
# takes the codec and block size the image already has. A name the first pass
# did not exclude would be appended beside it as `ports_1`, so the result is
# checked by path.
PORTS_STAGE=/kdos/build/image-ports
if [ ! -f $PORTS_STAGE/ports/sources.idx ]; then
echo "FATAL: $PORTS_STAGE holds no recipe tree; 105_ports.sh did not run" >&2
exit 1
fi
echo "Appending the recipe tree as /ports..."
mksquashfs $PORTS_STAGE $ISO_ROOT/system.sfs -no-progress -quiet
if ! unsquashfs -l $ISO_ROOT/system.sfs ports/sources.idx | grep -qx 'squashfs-root/ports/sources.idx'; then
echo "FATAL: system.sfs has no /ports/sources.idx after the append" >&2
exit 1
fi
script/phases/70_image/110_iso.sh, lines 150–166
Every image carries the recipe tree at /ports, so that a booted machine can build from it. The tree is not the chroot’s /ports, which is the whole repository’s ports/ with every source in it. 105_ports.sh (its chapter) stages a copy that holds recipes only, with KDOS’s own sources and the two books, in build/image-ports/ports, and stops if a file over 16 MB has found its way in. When that staged tree has no sources.idx, this step stops before the append, naming 105_ports.sh as the step that did not run.
The second mksquashfs call names an existing image and no -noappend, so it appends: the staged directory’s entries are added at the image’s root, in the codec and block size the image already has. The check after it lists ports/sources.idx from the image with unsquashfs -l and stops the step unless it is at squashfs-root/ports/sources.idx. An entry whose name is already in the image would be appended under another name, ports_1, and that is the mistake the check catches.
What else can go on the medium
# 2b. The KDOS base pack, when KDOS_PACK_KDOS built one.
#
# It goes on ISO9660 rather than into /var/lib/kdos/packs for the reason
# 100_packs.sh records: that directory is inside the rootfs, and squashing a
# compressed image of the rootfs into system.sfs makes the medium carry the
# tree twice. kdos-packd scans the medium for *.kpack and needs no index, so
# `kdos-box create ports base=pack:kdos` finds it with nothing installed.
#
# IT IS THE ONLY PACK A MEDIUM CARRIES. Applications are built by podman on the
# machine that asks for one, or imported from an exported set; nothing is baked.
# GATED ON THE FLAG, NOT ON THE FILE. `build/` is not cleaned between runs, so
# testing whether the artefact EXISTS would carry a 9.1 GB pack from an
# earlier opt-in build onto every ISO after it, including builds that never
# set KDOS_PACK_KDOS. The flag is what the user asked for; the file is just
# what is lying around.
if [ "${KDOS_PACK_KDOS:-0}" = "1" ] && [ -f /kdos/build/kdos-base/kdos.kpack ]; then
mkdir -p $ISO_ROOT/packs
cp -a /kdos/build/kdos-base/kdos.kpack $ISO_ROOT/packs/
echo "KDOS base pack: $(du -h $ISO_ROOT/packs/kdos.kpack | cut -f1) on the medium"
fi
script/phases/70_image/110_iso.sh, lines 168–187
make build KDOS_PACK_KDOS=1 bakes a pack of the base system in 100_packs.sh (its chapter), and this block puts it on the medium as packs/kdos.kpack, beside system.sfs rather than inside it. The test is the flag and the file together. build/ is kept between builds, so 100_packs.sh deletes build/kdos-base on every run before it decides whether to bake one; a pack left by an earlier build never reaches this step, whether the flag is set or not, and a pack reaches the medium only on a build that asked for one and made it. Packs are described in Packs and boxes.
# 2c. The sources, when asked for.
#
# A booted stick that can rebuild its own ISO. The tree goes on the ISO9660
# filesystem BESIDE system.sfs rather than inside it, so it costs the installed
# system nothing and is readable from /mnt/iso the moment the live image is up.
#
# Every image carries the recipes at /ports (2a); this adds the fetched
# sources, script/ and fs/. Opt-in because of its size: ports/ is tens of
# gigabytes of upstream tarballs that are already compressed, and squashing them again
# buys nothing.
# `make build KDOS_ISO_SOURCES=1` is a developer stick, not the default one.
#
# The copy reads the tree where the chroot mounts it: ports/ at /ports, and
# src/, script/, fs/, the Makefile and the Dockerfile bound back over /kdos,
# whose own bind of the build container's /workspace is non-recursive and
# shows each of them as an empty mount point. CLAUDE.md is not mounted into
# the container, and each top-level file is copied only when present. Of
# ports/ everything but its
# dot-directories travels, every fetched source beside its recipe: those are
# the fetch cache, whose bytes each port directory already holds by hard link,
# and compiled host helpers. A binhost in build/binhost goes beside the tree as
# sources/binhost only when KDOS_MAKE_BINHOST is set for this run, for the
# reason 2b gates on its flag: build/binhost survives between runs, and a test
# on its index file alone would put an earlier opt-in build's binhost on every
# sources medium after it.
if [ "${KDOS_ISO_SOURCES:-0}" = "1" ]; then
echo "Copying the sources onto the ISO (this is the big one)..."
mkdir -p $ISO_ROOT/sources/ports
for d in src script fs; do
cp -a /kdos/$d $ISO_ROOT/sources/
done
for f in /ports/*; do
cp -a "$f" $ISO_ROOT/sources/ports/
done
for f in Makefile Dockerfile CLAUDE.md; do
[ -f /kdos/$f ] && cp -a /kdos/$f $ISO_ROOT/sources/
done
if [ "${KDOS_MAKE_BINHOST:-0}" = "1" ] && [ -f /kdos/build/binhost/PACKAGES ]; then
cp -a /kdos/build/binhost $ISO_ROOT/sources/binhost
fi
# A stamp, so `kdos rebuild` can say what it is about to rebuild FROM.
cat > $ISO_ROOT/sources/SOURCES <<EOS
# The KDOS tree that built this image.
ports $(find $ISO_ROOT/sources/ports/core -mindepth 2 -maxdepth 3 -name kpkgbuild | wc -l) ports
size $(du -sh $ISO_ROOT/sources 2>/dev/null | cut -f1)
built $(date -u +%Y-%m-%dT%H:%M:%SZ)
EOS
echo "Sources: $(du -sh $ISO_ROOT/sources | cut -f1)"
fi
script/phases/70_image/110_iso.sh, lines 189–237
make build KDOS_ISO_SOURCES=1 adds the build’s own tree under sources/ on the medium: src, script and fs, every top-level entry of ports/ but its dot-directories, and the Makefile and Dockerfile. The script also copies the repository’s CLAUDE.md when it is present, but make build does not mount that file into the build container, so a medium made by make build does not carry it. The binary host goes along as sources/binhost only when this build sets KDOS_MAKE_BINHOST=1 and build/binhost/PACKAGES, its index, exists. The test is the flag as well as the file because build/ survives between runs, and a binhost an earlier opt-in build left there would otherwise land on every later sources medium. The SOURCES file is a stamp with the number of recipes, the size, and the time of the copy. A booted medium sees it at /mnt/iso/sources, where kdos rebuild looks for it.
The boot menu
Limine
# 3. The boot menu
#
# ONE BOOTLOADER FOR BOTH FIRMWARES. Limine boots from BIOS and from UEFI out
# of one tree and one configuration file, so what a machine shows at power-on
# does not depend on how it started. A second bootloader for the other firmware
# would mean two menus to keep in step, and the one that is wrong is the one
# nobody is booting today.
echo "Configuring the boot menu..."
LIMINE_DIR=/usr/share/limine
if [ ! -d "$LIMINE_DIR" ]; then
echo "Error: limine is not installed at $LIMINE_DIR" >&2
exit 1
fi
mkdir -p $ISO_ROOT/boot/limine
cp $LIMINE_DIR/limine-bios.sys $ISO_ROOT/boot/limine/
cp $LIMINE_DIR/limine-bios-cd.bin $ISO_ROOT/boot/limine/
cp $LIMINE_DIR/limine-uefi-cd.bin $ISO_ROOT/boot/limine/
cp $LIMINE_DIR/BOOTX64.EFI $ISO_ROOT/EFI/BOOT/BOOTX64.EFI
# AND THE 32-BIT FIRMWARE'S FIRST STAGE BESIDE IT. A UEFI machine loads
# `EFI/BOOT/BOOT<arch>.EFI` off removable media and reads only the one its own
# firmware can execute, so the two sit together and never compete: a 64-bit
# firmware takes BOOTX64 and an early Atom tablet, whose CPU is 64 bit and whose
# firmware is not, takes BOOTIA32 and boots the same kernel. Both are built by
# the limine port.
cp $LIMINE_DIR/BOOTIA32.EFI $ISO_ROOT/EFI/BOOT/BOOTIA32.EFI
script/phases/70_image/110_iso.sh, lines 239–264
Limine is the boot loader for both kinds of firmware. Its port installs its files in /usr/share/limine, and five are copied:
| File | Goes to | Is |
|---|---|---|
limine-bios.sys |
boot/limine/ |
the BIOS stage the boot code loads |
limine-bios-cd.bin |
boot/limine/ |
the El Torito boot image for BIOS |
limine-uefi-cd.bin |
boot/limine/ |
the El Torito boot image for UEFI, a FAT image with the EFI binaries in it |
BOOTX64.EFI |
EFI/BOOT/ |
the loader for 64-bit UEFI firmware |
BOOTIA32.EFI |
EFI/BOOT/ |
the loader for 32-bit UEFI firmware |
The font
# THE MENU IS DRAWN IN THE CONSOLE'S OWN FACE, so the first screen of KDOS is
# the same character grid in the same palette as every screen after it.
#
# `ter-i16n` AND NOT THE CONSOLE'S OWN `ter-kdos32n`, for two reasons that both
# fail silently. Limine indexes glyphs by CP437 and only Terminus's `-i` faces
# are encoded that way — the console's leaves 46 slots blank, every double-line
# box glyph among them. And Limine reads 8-dot-wide fonts ONLY: `term_font_size`
# refuses any other width and falls back to the built-in font, which draws a
# perfectly good menu in the wrong typeface. psf2limine.py refuses both
# mistakes rather than converting them.
BOOTFONT=/usr/share/consolefonts/ter-i16n.psf.gz
if [ -f "$BOOTFONT" ]; then
zcat "$BOOTFONT" > /tmp/kdos-bootfont.psf
FONT_SIZE=$(python3 /kdos/script/phases/70_image/psf2limine.py \
/tmp/kdos-bootfont.psf $ISO_ROOT/boot/limine/font.bin)
rm -f /tmp/kdos-bootfont.psf
FONT_LINES="term_font: boot():/boot/limine/font.bin
term_font_size: $FONT_SIZE"
else
echo "Warning: $BOOTFONT not found — the menu keeps Limine's own font"
FONT_LINES=""
fi
script/phases/70_image/110_iso.sh, lines 266–287
The menu is drawn in Terminus ter-i16n from terminus-font, an 8x16 face. Limine wants a font as a bare bitmap of 256 glyphs in code page 437 order, which is not what a console font file is, so the face is decompressed and converted by script/phases/70_image/psf2limine.py. The script prints the size, 8x16, which becomes term_font_size. When the font is not installed, the menu is drawn in Limine’s own.
psf2limine.py reads either version of the PSF format and writes the 256 glyphs Limine indexes by CP437, taking each from the font’s Unicode table:
# THE TWO FORMATS DISAGREE ABOUT ORDER, AND THAT IS THE WHOLE JOB. A PSF is
# indexed by the font's own glyph number and carries a unicode table saying
# which codepoints each glyph draws; Limine has no table and indexes by CP437,
# so glyph 218 is whatever CP437 calls 218 — the top-left double corner. Copied
# across unconverted the bitmap is the right size and every frame, rule and
# arrow in the boot menu draws a different letter. The size being right is why
# this cannot be caught by looking at the file.
#
# THE OUTPUT IS HEADERLESS: 256 glyphs of `charsize` bytes and nothing else,
# which is what Limine reads once `term_font_size` tells it the dimensions.
# A header left on shifts every glyph and the menu draws garbage from the
# first character.
script/phases/70_image/psf2limine.py, lines 14–25
# CP437's FIRST 32 SLOTS AND 0x7F ARE GLYPHS, NOT CONTROL CODES, and Python's
# `cp437` codec decodes them the other way — to U+0001..U+001F, which no font
# has. Taken from the codec, a third of the font comes out blank and the two
# arrow glyphs Limine draws its menu selection with are among them. Only this
# table says what those slots actually draw.
CP437_LOW = ("\u0000\u263a\u263b\u2665\u2666\u2663\u2660\u2022"
"\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c"
"\u25ba\u25c4\u2195\u203c\u00b6\u00a7\u25ac\u21a8"
"\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc")
def cp437(i):
if i < 32:
return ord(CP437_LOW[i])
if i == 0x7F:
return 0x2302 # ⌂, not DEL
return ord(bytes([i]).decode("cp437"))
script/phases/70_image/psf2limine.py, lines 83–99
Python’s cp437 codec decodes the first 32 slots and 0x7F as control characters, so the script carries its own table for them. Its two checks turn each silent failure into a stopped build:
# LIMINE ONLY READS 8-PIXEL-WIDE FONTS, and a wider one is not an error
# there: `term_font_size` refuses any width but 8 and the built-in font is
# used in place of `term_font`. The menu then draws perfectly in the wrong
# face, which is indistinguishable from the theming simply not having been
# applied. Terminus at 16 dots wide converts and installs without
# complaint, so this is the only place the mistake is visible.
if width != 8:
raise SystemExit("psf2limine: %s is %d dots wide — Limine reads only "
"8-wide fonts and silently ignores the rest"
% (sys.argv[1], width))
script/phases/70_image/psf2limine.py, lines 108–117
# A CP437-ENCODED FONT ANSWERS FOR ALL 256 AND ANYTHING LESS IS THE WRONG
# FILE. Terminus ships both encodings under names one letter apart:
# `ter-i32n` is the CP437 one and scores zero here, `ter-kdos32n` is the
# console's own and leaves 46 slots blank — every double-line box glyph
# among them, so the menu chrome comes out full of holes. Both convert
# without error and both are the right size, so nothing downstream can
# tell them apart. This is the only place that can.
if missing:
raise SystemExit("psf2limine: %d of 256 glyphs missing — %s is not "
"CP437-encoded" % (missing, sys.argv[1]))
print("%dx%d" % (width, height))
script/phases/70_image/psf2limine.py, lines 141–151
A font that is not 8 dots wide is refused, because Limine would set it aside and draw in its own; and a font that leaves any of the 256 slots without a glyph is refused, because it is not a CP437 face. A font with no Unicode table at all is copied in its own order.
The converter can be tried on its own, in the chroot:
zcat /usr/share/consolefonts/ter-i16n.psf.gz > /tmp/ter-i16n.psf
python3 /kdos/script/phases/70_image/psf2limine.py /tmp/ter-i16n.psf /tmp/font.bin
It prints 8x16 on standard output and a summary line, with the count of missing glyphs, on standard error, and /tmp/font.bin is 256 glyphs of 16 bytes. Given the console’s own ter-kdos16n.psf.gz instead, it stops with a message naming how many glyphs are missing.
The backdrop and the colours
# THE ARTWORK GOES BEHIND EVERYTHING AND THE MENU SITS OPAQUE ON TOP OF IT.
# `centered` draws a wallpaper at its own size in the middle of the screen,
# which is exactly where Limine draws the menu, and `term_background`'s leading
# transparency byte defaults to `80` whenever a wallpaper is set. Either one
# alone prints the artwork THROUGH the entry text. Neither is a taste: they are
# the difference between a menu somebody can read and one they cannot.
#
# The file here is PRE-DIMMED, because Limine has no wallpaper opacity. The
# backdrop generator writes it; how dark it is belongs there and not here.
#
# Only the PATH is set below. `wallpaper_style`, every colour and the font
# scale come out of `kdos-bootctl theme --print`, so the medium, the installer
# and a later `kdos theme` cannot disagree about how the menu looks.
BACKDROP_ART=/usr/share/kdos/boot/kdos-backdrop.png
if [ ! -f "$BACKDROP_ART" ]; then
BACKDROP_ART=/usr/share/kdos/boot/kdos-banner.png
fi
if [ -f "$BACKDROP_ART" ]; then
cp "$BACKDROP_ART" $ISO_ROOT/boot/limine/wallpaper.png
WALLPAPER="wallpaper: boot():/boot/limine/wallpaper.png"
else
echo "Warning: no KDOS boot artwork — the menu is a plain backdrop"
WALLPAPER=""
fi
# THE COLOURS COME OUT OF libkcolor AND ARE NEVER WRITTEN HERE. `kdos-bootctl
# theme --print` expands the scheme's own nine numbers into Limine's keys, and
# the installer writes the same block through the same function — so the menu,
# the splash, the console and the desktop are one palette, and a stick and the
# machine installed from it cannot show different colours. A literal picked to
# look right here would drift the moment the scheme is retuned.
#
# TEN SECONDS IS A COUNTDOWN SOMEBODY CAN ACT ON. Every second of it is boot
# time spent before the kernel exists, with nothing else running, so it is
# bought rather than free — but the menu is the only way to reach the verbose
# entry, the clean session and memtest86+, and a machine that will not boot
# needs one of those. A countdown short enough to miss makes them unreachable
# on exactly the machine that needs them, which costs far more than the wait.
# Up or Down stops it and leaves the menu up indefinitely; Enter, Space and
# Right boot the highlighted entry at once, as Limine reads them as "boot" even
# while it counts down.
#
# `timeout: 0` is NOT an immediate boot with a menu; it boots the default entry
# without drawing one at all, and those entries become unreachable.
#
# THE VERBOSE ENTRY PUTS THE BOOT ON THE SCREEN. /dev/console is the LAST
# console=, so the quiet entries name ttyS0 last and the screen stays the
# splash's; the verbose entry names tty0 last, so the initramfs's and rcS's
# output reach the screen as well as the kernel's. It leaves out `quiet`, and
# kdos-splash draws nothing on a command line without it — a splash there
# would cover the text this entry exists to show. `loglevel=7` holds for the
# whole boot: 20_dmesg.sh leaves a level the command line set alone.
#
# Every entry names the serial console's speed: a bare `console=ttyS0` runs it
# at 9600 baud, and the kernel writes each message to the UART at that rate,
# which holds the verbose boot's screen black for half a minute.
BOOT_THEME=$(kdos-bootctl theme --print "$KDOS_ACCENT")
script/phases/70_image/110_iso.sh, lines 289–345
The backdrop is /usr/share/kdos/boot/kdos-backdrop.png, or kdos-banner.png when there is no backdrop; both are shipped by the fs/ overlay. Without either the menu has a plain background.
Every other line of the look comes from kdos-bootctl theme --print, run with KDOS_ACCENT from phase.env. It prints the block kcol_limine_conf() in libkcolor writes, the same block the installer writes onto an installed machine’s ESP. The keys and why each has its value are in Why the plate is opaque and The margin ceiling; how to change the accent is in Theming.
limine.conf
# The first entry names the release, read from the root's os-release, so the
# menu says which KDOS the medium starts. A root without VERSION_ID is fatal:
# an image that cannot say its version is not one to ship.
LIVE_VERSION=$(. /etc/os-release && printf '%s' "$VERSION_ID")
if [ -z "$LIVE_VERSION" ]; then
echo "FATAL: /etc/os-release has no VERSION_ID" >&2
exit 1
fi
# EVERY LIVE ENTRY NAMES ITS MEDIUM. The initramfs scans every block device for
# an ISO 9660 filesystem holding system.sfs, and a machine with two KDOS media
# attached answers on both; without a name it takes the first to respond, which
# pairs this kernel and its modules with another release's system.sfs and
# makes the installer mark the wrong device as the boot medium. The id is the
# first 16 hex digits of system.sfs's sha256, written beside it as
# kdos-medium.id and passed as kdos.medium=; the scan takes only the medium
# whose file matches. A Ventoy stick in normal mode and a `kdos clone` copy
# carry the same file and this same limine.conf, so they match themselves.
# The id is also the image's Volume Set Identifier (-volset, at 32 KiB + 190
# in the primary volume descriptor), where the installer reads it off every
# whole disk: two copies of one build answer to one id, the scan mounts the
# first, and nothing tells which the firmware started, so the installer
# refuses every disk that carries it. And it is the Publisher Identifier
# (-publisher, at 32 KiB + 318, upper-cased by xorriso as ISO 9660 asks),
# which udev's blkid exports as ID_FS_PUBLISHER_ID where it exports no volume
# set: the graphical installer's probes run as a user who cannot open a disk,
# and read it there.
# Computed after the last write to system.sfs: the /ports append changes it.
MEDIUM_ID=$(sha256sum $ISO_ROOT/system.sfs | cut -c1-16)
case "$MEDIUM_ID" in
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ;;
*) echo "FATAL: cannot hash $ISO_ROOT/system.sfs for the medium id" >&2
exit 1 ;;
esac
printf '%s\n' "$MEDIUM_ID" > $ISO_ROOT/kdos-medium.id
echo "Medium id: $MEDIUM_ID"
cat > $ISO_ROOT/boot/limine/limine.conf <<EOF
timeout: 10
default_entry: 1
$BOOT_THEME
$WALLPAPER
$FONT_LINES
/KDOS Live
comment: Start KDOS $LIVE_VERSION from this medium
protocol: linux
path: boot():/boot/vmlinuz
module_path: boot():/boot/initrd.img
cmdline: root=/dev/ram0 rw console=tty0 console=ttyS0,115200n8 quiet loglevel=3 kdos.medium=$MEDIUM_ID
/KDOS Live (clean session)
comment: Ignore the persistence store and start fresh
protocol: linux
path: boot():/boot/vmlinuz
module_path: boot():/boot/initrd.img
cmdline: root=/dev/ram0 rw console=tty0 console=ttyS0,115200n8 quiet loglevel=3 nopersist kdos.medium=$MEDIUM_ID
/KDOS Live (verbose)
comment: Every kernel and boot message on the screen, no splash
protocol: linux
path: boot():/boot/vmlinuz
module_path: boot():/boot/initrd.img
cmdline: root=/dev/ram0 rw console=ttyS0,115200n8 console=tty0 loglevel=7 kdos.medium=$MEDIUM_ID
EOF
script/phases/70_image/110_iso.sh, lines 347–412
timeout: 10 counts ten seconds down before default_entry: 1, the first entry, boots; Up or Down stops the count, and Enter, Space or Right boots the highlighted entry at once. The three entries boot the same kernel and initramfs, boot/vmlinuz and boot/initrd.img, named by boot():/, the volume the configuration file was read from. Their command lines differ:
KDOS Livepassesquiet loglevel=3. Its comment,Start KDOS <version> from this medium, takes the version fromVERSION_IDin the root’s/etc/os-release, and a root without one stops the step.KDOS Live (clean session)addsnopersist, which makes the initramfs ignore the persistence store.KDOS Live (verbose)passesloglevel=7and noquiet, so the splash does not run and every kernel and boot message is on the screen.
The first two name console=tty0 and then console=ttyS0,115200n8. The last one is /dev/console, so the initramfs prints to the serial port while the splash has the screen. The verbose entry names console=ttyS0,115200n8 and then console=tty0, so its initramfs and rcS print on the screen. Each names the serial line’s speed, 115200 baud, eight bits, no parity: a bare console=ttyS0 runs at 9600 baud, and since the kernel writes every message to the UART at that rate, the verbose boot’s screen would stay black for half a minute. root=/dev/ram0 is not a root=UUID=, so the initramfs takes the live path.
All three end with kdos.medium=<id>. MEDIUM_ID is the first 16 hexadecimal digits of the sha256 of system.sfs, taken after the /ports append, which is the last write to it; the step writes it, one line, to kdos-medium.id at the top of the ISO tree, beside system.sfs. The initramfs takes only the medium whose kdos-medium.id matches the id on its command line, so with another build’s medium attached it passes that one over and never pairs this kernel’s modules with another release’s system.sfs. A stick written with dd, a Ventoy stick in normal mode and a kdos clone copy carry this same limine.conf and the same file, so each matches itself; two copies of one build therefore both match, the first to answer is mounted, and the installer refuses both (-volset below). A hash that is not 16 hexadecimal digits stops the step. The timeout: 0 trap the comment names is Limine’s documented meaning of 0: boot at once and draw no menu.
memtest86+
# 3b. memtest86+, and it is a MENU ENTRY rather than a program because bad RAM
# is the one fault no tool running under an OS can honestly diagnose — the OS
# is itself in the memory being tested. It boots INSTEAD of the kernel, owns
# the machine, and tests everything.
#
# The port installs the payload to /usr/share/kdos/memtest86plus/; a missing
# one is a warning and not a failure, so an ISO still rolls on a tree where
# that port has not been built.
#
# THE PAYLOAD IS AN EFI BINARY, so the entry is chainloaded and `if_fw_type`
# hides it on a BIOS boot. Offered there it would be an entry that cannot
# start, on the one screen a machine with bad memory is able to reach.
MEMTEST=/usr/share/kdos/memtest86plus/memtest.efi
if [ -f "$MEMTEST" ]; then
echo "Adding memtest86+..."
cp "$MEMTEST" $ISO_ROOT/boot/memtest.efi
cat >> $ISO_ROOT/boot/limine/limine.conf <<EOF
/Memory Test (memtest86+)
comment: Test this machine's RAM (UEFI only)
protocol: efi
if_fw_type: UEFI
path: boot():/boot/memtest.efi
EOF
else
echo "memtest86+: no payload at $MEMTEST — skipping the menu entry"
fi
script/phases/70_image/110_iso.sh, lines 414–440
When memtest86plus is installed, its EFI program is copied to boot/memtest.efi and an entry is added that starts it with protocol: efi. if_fw_type: UEFI hides the entry on a BIOS boot. Without the package the menu has three entries.
xorriso
# 4. Generate the ISO
#
# THE IMAGE BOOTS FOUR WAYS AND EACH ONE IS A SEPARATE FLAG. Optical BIOS and
# optical UEFI are the two El Torito records; USB BIOS and USB UEFI are the
# partition table, because `dd` copies bytes and a firmware reading a stick
# never looks in a boot catalogue.
#
# -b boot/limine/limine-bios-cd.bin the BIOS El Torito record
# --efi-boot boot/limine/limine-uefi-cd.bin the UEFI one
# -efi-boot-part --efi-boot-image makes THAT image an EFI System
# Partition in the table, so a written
# stick has one to find
# --protective-msdos-label an MBR for the firmware that wants one
# limine bios-install the BIOS boot code in that MBR
#
# THE VOLUME ID NAMES THE RELEASE, KDOS_0_2_1 for 0.2.1, so a file manager,
# blkid and a stick tool say which KDOS a medium holds. ISO 9660 allows only
# A-Z, 0-9 and `_` there, at most 32 of them, so the release is upper-cased,
# every other character becomes `_` and the id is cut at 32. Nothing finds
# the medium by it: the initramfs scans for system.sfs, the udev rule that
# hides the medium matches its mount, and the installer prints it.
#
# THE ESP IS THE EL TORITO IMAGE ITSELF, not a partition appended after the
# ISO. Nothing is added past the ISO9660 volume, so the volume descriptor still
# describes the whole file and `kdos clone` copies a complete medium from it.
#
# ISO9660 STILL STARTS AT SECTOR 0 and must keep doing so: the initramfs finds
# the medium by mounting each whole-disk node `-t iso9660`, which on a written
# stick is /dev/sda itself. A partition offset for the ISO would move the
# filesystem off sector 0 and that scan would find nothing.
LIVE_VOLID="KDOS_${LIVE_VERSION^^}"
LIVE_VOLID="${LIVE_VOLID//[^A-Z0-9_]/_}"
LIVE_VOLID="${LIVE_VOLID:0:32}"
echo "Generating ISO..."
ISO_BUILD=/kdos/build/iso-build
mkdir -p $ISO_BUILD
rm -f $ISO_BUILD/efiboot.img
xorriso -as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "$LIVE_VOLID" \
-volset "$MEDIUM_ID" \
-publisher "$MEDIUM_ID" \
-b boot/limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image \
--protective-msdos-label \
-o $ISO_BUILD/kdos.iso \
$ISO_ROOT
# THE BIOS BOOT CODE GOES IN AFTERWARDS, because it is written into the MBR of
# a finished image: xorriso lays out the volume, then this patches the first
# sector to chain into limine-bios.sys. Without it the UEFI paths still work
# and a BIOS machine reads a disk with no boot code and moves on to the next
# device, which looks exactly like a machine that was never offered the stick.
limine bios-install $ISO_BUILD/kdos.iso
script/phases/70_image/110_iso.sh, lines 442–500
xorriso, from libisoburn, writes the image. Run as xorriso -as mkisofs, it takes mkisofs’s options:
-iso-level 3- The ISO9660 level that lets a file be larger than 4 GiB − 1, which the two lower levels do not.
-full-iso9660-filenames- Allow ISO9660 names of up to 31 characters. xorrisofs writes Rock Ridge records by default, and those carry the full names.
-volid "$LIVE_VOLID"-
The volume label, which names the release:
KDOS_and the release upper-cased with every character outsideA-Z,0-9and_turned to_, cut at 32, so 0.2 givesKDOS_0_2. Those are the only characters ISO 9660 allows in a volume id. Nothing finds the medium by its label: the initramfs takes the medium whosekdos-medium.idmatches, and the udev rule that hides it matches its mount. -volset "$MEDIUM_ID"-
The medium id as the primary volume descriptor’s Volume Set Identifier, 190 bytes into the descriptor at 32 KiB.
kinstallreads it off every whole disk and refuses each one that carries the running boot’skdos.medium=id: the mounted one as the boot medium, any other as a copy of it, since two copies of one build cannot be told apart. -publisher "$MEDIUM_ID"-
The medium id again, as the Publisher Identifier, 318 bytes into the descriptor; xorriso upper-cases it, as ISO 9660 asks of that field. udev’s blkid exports it as
ID_FS_PUBLISHER_IDand exports no volume set, and the graphical installer’s probes run as a user who cannot open a disk, so they read the id there. -b boot/limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table- The BIOS entry in the El Torito boot catalogue: the boot image, marked as emulating no floppy or disk, with 4 sectors of 512 bytes loaded at boot, and with xorriso writing the block address of the volume descriptor, the block address of the image, its size and a checksum into bytes 8 to 63 of it.
--efi-boot boot/limine/limine-uefi-cd.bin- A second El Torito entry, for EFI, with the UEFI boot image.
-efi-boot-part --efi-boot-image- List that same UEFI boot image in a GPT as an EFI System Partition, which is where firmware booting a stick looks.
--protective-msdos-label- Write an MBR partition table whose one partition covers the image but its first block.
These are the options Limine’s USAGE.md gives for an ISO, with differences: KDOS adds the level, the long names, the label, the volume set and the publisher, and does not pass the -R -r -J -hfsplus -apm-block-size 2048 of Limine’s line.
limine bios-install then writes Limine’s BIOS boot code into the first sector of the finished image. Finding a GPT on an ISO image, it converts the table to MBR, and says so in the step’s output. The comment at the top of the block explains the layout: the ESP is the El Torito image itself, inside the ISO9660 volume, and ISO9660 starts at sector 0, which is what lets the initramfs find the medium by mounting the whole disk.
The checks
# EVERY BOOT PATH IS VERIFIED, NOT ASSUMED, because all four fail silently.
# xorriso accepts a boot flag it has nothing to act on without a word, and the
# image it then writes can have a first 512 bytes of zero, which nothing shows
# until somebody writes it to a stick. A build that
# cannot boot has to fail here rather than on somebody's machine.
# THE TYPE HAS TWO NAMES AND THE IMAGE ENDS UP WITH THE SECOND ONE.
# `limine bios-install` converts the GPT xorriso wrote into an MBR — it says so
# — because more firmware boots that. fdisk then calls the partition
# `EFI (FAT-12/16/32)` and not `EFI System`, which is the GPT spelling. Matching
# only the GPT name fails a perfectly bootable image, and matching only the MBR
# one would fail if that conversion ever stopped happening.
iso_fail=0
if ! fdisk -l $ISO_BUILD/kdos.iso 2>/dev/null \
| grep -Eq "EFI System|EFI \(FAT"; then
echo "FATAL: no EFI System partition — UEFI would not boot from a stick" >&2
iso_fail=1
fi
if [ "$(dd if=$ISO_BUILD/kdos.iso bs=1 skip=510 count=2 2>/dev/null | od -An -tx1 | tr -d ' \n')" != "55aa" ]; then
echo "FATAL: no MBR boot signature — BIOS would not boot from a stick" >&2
iso_fail=1
fi
# The MBR's first 440 bytes are the boot code area. xorriso leaves them ZERO —
# a protective label is a partition table and nothing else — and
# `limine bios-install` is what fills them. All-zero here is a BIOS machine
# reading the stick, finding no code, and moving on to the next boot device,
# which on most firmware is indistinguishable from the stick not being plugged
# in. The 55aa signature above is written by xorriso either way and so cannot
# answer this.
# `od -v` IS LOAD-BEARING: without it od collapses runs of identical lines to a
# single `*`, so the dump of an empty boot area is not all zeros but zeros and
# an asterisk — and every test for "all zero" answers no. That reads as boot
# code being present on an image that has none.
if [ -z "$(dd if=$ISO_BUILD/kdos.iso bs=440 count=1 2>/dev/null \
| od -An -tx1 -v | tr -d ' \n0')" ]; then
echo "FATAL: the MBR boot code area is empty — limine bios-install did" >&2
echo " not run, so BIOS would not boot from a stick" >&2
iso_fail=1
fi
# And the medium id reaches every live entry: an entry without it, or with
# another build's, boots a kernel that refuses this medium's system.sfs.
if [ "$(grep -c "^ cmdline: root=/dev/ram0 rw .* kdos.medium=$(cat $ISO_ROOT/kdos-medium.id)\$" \
$ISO_ROOT/boot/limine/limine.conf)" != 3 ]; then
echo "FATAL: the three live entries do not all name kdos.medium=$(cat $ISO_ROOT/kdos-medium.id)" >&2
iso_fail=1
fi
# And the installer's copies of it: the Volume Set and Publisher Identifiers,
# without which every copy of this medium is offered as an erase target.
if [ "$(dd if=$ISO_BUILD/kdos.iso bs=1 skip=$((0x8000 + 190)) count=16 2>/dev/null)" != "$MEDIUM_ID" ]; then
echo "FATAL: the image's Volume Set Identifier is not the medium id $MEDIUM_ID" >&2
iso_fail=1
fi
if [ "$(dd if=$ISO_BUILD/kdos.iso bs=1 skip=$((0x8000 + 318)) count=16 2>/dev/null)" != "${MEDIUM_ID^^}" ]; then
echo "FATAL: the image's Publisher Identifier is not the medium id $MEDIUM_ID" >&2
iso_fail=1
fi
[ "$iso_fail" = 0 ] || exit 1
script/phases/70_image/110_iso.sh, lines 502–557
Five properties of the finished image are tested, and any one missing stops the step after all five have been reported:
fdisk -lfrom util-linux lists an EFI partition, under either of the two names fdisk gives it:EFI Systemin a GPT,EFI (FAT-12/16/32)in the MBRlimine bios-installconverts it to.- Bytes 510 and 511 are
55 aa, the MBR signature. - The first 440 bytes, the MBR’s boot code area, are not all zero, which shows that
limine bios-installran; xorriso writes the signature in item 2 either way.od -vis needed for this test, because without itodprints a run of identical lines as one*. - All three live entries of
limine.confend withkdos.medium=and the id inkdos-medium.id; an entry without it, or with another build’s, would boot a kernel whose initramfs refuses this medium. - The 16 bytes at 32 KiB + 190 are the medium id, the Volume Set Identifier
-volsetwrote, and the 16 at 32 KiB + 318 are the same id upper-cased, the Publisher Identifier-publisherwrote; without them the installer would offer every other copy of this medium as an erase target.
testing/preflight.sh checks the same boot structure without building, by looking for each of the flags in this script.
The size gate
# 5. The release size gate
#
# A RELEASE ISO IS ONE RELEASE ASSET, and GitHub refuses an asset past 2 GiB;
# 1,900 MiB is the limit ports/srclib.sh's SRC_PART_SIZE names for every
# other asset, so nobody downloading a release joins parts. A base image
# (KDOS_IMAGE=base) larger than KDOS_ISO_MAX bytes fails here, and the failure
# prints the image ledger's top twenty (088_ledger.sh), so the build that
# stops names what the image spends its bytes on. KDOS_ISO_GATE=0 is a
# developer image and passes; a KDOS_IMAGE=full image carries every package
# and is never a release, so it is never gated. The ISO stays on disk either
# way, for the rig.
ISO_MAX="${KDOS_ISO_MAX:-1992294400}"
ISO_GATE="${KDOS_ISO_GATE:-1}"
case "$ISO_MAX" in
''|*[!0-9]*|0*) echo "FATAL: KDOS_ISO_MAX=$ISO_MAX is not a positive number of bytes" >&2; exit 1 ;;
esac
case "$ISO_GATE" in
0|1) ;;
*) echo "FATAL: KDOS_ISO_GATE=$ISO_GATE is not 0 or 1" >&2; exit 1 ;;
esac
iso_size=$(stat -c %s $ISO_BUILD/kdos.iso)
echo "ISO size: $iso_size bytes ($((iso_size / 1048576)) MiB); limit $ISO_MAX bytes ($((ISO_MAX / 1048576)) MiB)"
if [ "${KDOS_IMAGE:-base}" = base ] && [ "$ISO_GATE" = 1 ] && [ "$iso_size" -gt "$ISO_MAX" ]; then
echo "FATAL: $ISO_BUILD/kdos.iso is $iso_size bytes, over the release limit of $ISO_MAX" >&2
echo " (KDOS_ISO_MAX); KDOS_ISO_GATE=0 builds it as a developer image" >&2
LEDGER=/kdos/build/image-ledger
if [ -f $LEDGER ]; then
echo "The twenty largest packages on the image ($LEDGER):" >&2
head -n 21 $LEDGER >&2
tail -n 1 $LEDGER >&2
else
echo "No ledger at $LEDGER: 088_ledger.sh did not run" >&2
fi
exit 1
fi
script/phases/70_image/110_iso.sh, lines 559–593
A release ISO is one release asset, so nobody who downloads it joins parts, and the limit is the one every other asset of the project keeps under: 1,900 MiB, GitHub’s 2 GiB per-asset limit with room to spare, which ports/srclib.sh names as SRC_PART_SIZE. The step prints the image’s size and the limit on every run. When the image is a base image (KDOS_IMAGE=base), the gate is on (KDOS_ISO_GATE=1, the default) and the ISO is larger than KDOS_ISO_MAX bytes, it prints the size, the limit and the first twenty rows and the total of the image ledger, and stops the phase. The ledger names the packages that cost the most and the dependency path that put each one on the medium, which is where a cut to ports/base starts.
The ISO is left in build/iso-build either way, so a failed release build can still be booted on the rig. A KDOS_IMAGE=full image is never gated, because it is never a release, and KDOS_ISO_GATE=0 builds a developer base image that may pass the limit:
make build KDOS_ISO_GATE=0 BUILD_ARGS="--phases 70_image"
KDOS_ISO_MAX and KDOS_ISO_GATE are checked by the Makefile and again here: anything but a positive number of bytes, or 0 or 1, stops the build.
Booting the result
make run
boots build/iso-build/kdos.iso in QEMU with UEFI firmware and software graphics, with a disk to install to, build/kdos.qcow2, which it creates as a sparse 192 GiB image (size set by KDOS_DISK) when there is none. make run-hw boots it with GPU acceleration, in a container. Testing describes the rig that photographs a booted image.
Reproducing an image
A package built twice from one tree is byte-identical, which Reproducible packages explains. The image phase does part of the same work for the image, and leaves some of it undone.
What the scripts pin
phase.env sources script/env/chroot.env, which sources script/env/common.env, so every step of this phase runs with a fixed SOURCE_DATE_EPOCH and TZ=UTC:
# ── reproducible packages ─────────────────────────────────────────────────
#
# A package built twice from this tree must be byte-identical. kpkg normalises
# the ARCHIVE itself (sorted, uid/gid 0, --mtime from SOURCE_DATE_EPOCH, pinned
# xz); these are the environment lines that normalise what goes INTO it.
#
# The epoch is pinned rather than taken from the clock or from git: a package's
# bytes must not depend on when or at which commit it was built. TZ and
# LC_ALL because a few configure scripts and doc generators embed a formatted
# date or sort a list by locale. -ffile-prefix-map rewrites the build directory
# out of __FILE__ and DWARF paths, and --build-id=sha1 makes the note a function
# of the contents instead of a random 128-bit value.
export SOURCE_DATE_EPOCH=1735689600
export TZ=UTC
export LC_ALL=C
script/env/common.env, lines 18–32
chroot.env then sets LC_ALL=C.UTF-8 over the C shown here; the sorts that order the initramfs archives set LC_ALL=C on the command itself.
Three tools put times into the image, and each treats the epoch differently:
- mksquashfs sets the image’s creation time to it, and every file time later than it is lowered to it. A file copied during the build therefore has the same time in
system.sfson every run. - xorriso sets the volume’s creation and modification dates and the GPT disk GUID from it. File dates on the ISO9660 volume are not touched: each file keeps the modification time it has on disk, and xorriso sets its access and change times to that.
- gzip does not read the epoch, but writes zero in its header’s time field when it compresses a pipe, which is how the initramfs step runs it.
The initramfs and microcode archives list their files in byte order, and cpio’s --reproducible keeps the numbers of the devices the files are stored on out of them and numbers the inodes in archive order from 0 (Packing). The commit the image is built from reaches it only through KDOS_GIT_COMMIT, KDOS_GIT_DIRTY, KDOS_GIT_DATE and KDOS_GIT_TIME, which the Makefile reads from git on the host. 045_identity.sh (its chapter) writes the commit and its date into /etc/os-release, never the time of the build, and 105_ports.sh writes the commit and its time into /ports/TREE.
What still differs between two builds
Two runs of the image phase over the same root do not give the same bytes:
- File times in the initramfs. Every file in
build/initramfsis a fresh copy made by the step, so it has the time of the run, and cpio stores each file’s modification time. The initramfs differs, and so doessystem.sfs, which holds a copy of it in/boot. - File times on the ISO9660 volume.
vmlinuz,initramfs.cpio.gz,system.sfs, the Limine files, the font, the backdrop andlimine.confare all written or copied intobuild/iso_rootby the step, and xorriso records the time each was written. - The sources stamp. With
KDOS_ISO_SOURCES=1,sources/SOURCEShas abuiltline with the time of the copy.
Two more inputs change the image whenever they change. A rebuilt linux package has different module signatures (see the same Reproducible packages section), and the initramfs carries modules. And xorriso writes its own version and build date into the volume’s Preparer Id field, so a different xorriso gives a different image from the same files.
Building the same image again
To come as close as the scripts allow, rebuild from the same clean commit, so that KDOS_GIT_DIRTY is 0, with the same make variables: KDOS_IMAGE, KDOS_ISO_COMP, KDOS_ISO_BLOCK, KDOS_PACK_KDOS, KDOS_ISO_SOURCES and KDOS_MAKE_BINHOST. build/keys/kdos-release.pub and build/binhost-key/kdos-binhost.pub, which 105_ports.sh installs into the image when they exist, are not in git, so both builds need the same keys, or neither.
Because the times above differ, two such images are compared by what they hold rather than byte for byte. The volume’s own dates come from the epoch:
xorriso -indev build/iso-build/kdos.iso -pvd_info
prints the epoch’s date and time as both Creation Time and Modif. Time, and the xorriso that made the image as its Preparer Id. To compare what two images hold rather than their bytes, extract each one and compare the trees:
xorriso -osirrox on -indev a.iso -extract / a
xorriso -osirrox on -indev b.iso -extract / b
diff -r a b
unsquashfs -s a/system.sfs prints the image’s creation time, which is the epoch, and unsquashfs -lls lists every file in it with its time.
See also
- The initramfs: the file this step puts in
boot/ - Limine and the kernel command line: the menu on the medium and on an installed machine
- The live medium and persistence: what boots from
system.sfs - Reproducible packages
- kdos clone: copying a medium