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

370. Stamping the build identity

This page explains how an image records exactly which tree it was built from, and where a user of the machine sees that record. Read it if you build a release, or if About this System shows an unexpected build.

/etc/os-release comes from fs/etc/os-release and names the distribution and its version. It does not say which tree a particular image was built from. script/phases/70_image/045_identity.sh adds that:

System Settings → About this System shows the build beside the version, because /usr/share/kdos/xdg/kcm-about-distrorc sets ShowBuild=true.

Where the values come from

The Makefile works them out from your clone when it starts the build container:

		-e KDOS_GIT_COMMIT="$$(git rev-parse --short=12 HEAD 2>/dev/null)" \
		-e KDOS_GIT_DIRTY="$$(test -n "$$(git status --porcelain 2>/dev/null)" && echo 1 || echo 0)" \
		-e KDOS_GIT_DATE="$$(git log -1 --format=%cs 2>/dev/null)" \
		-e KDOS_GIT_TIME="$$(git log -1 --format=%ct 2>/dev/null)" \

Makefile, lines 218–221

Variable Value
KDOS_GIT_COMMIT The short hash of HEAD, twelve characters long
KDOS_GIT_DIRTY 1 when git status shows any change, else 0
KDOS_GIT_DATE The commit date, as YYYY-MM-DD
KDOS_GIT_TIME The commit time in Unix seconds, which this step and 105_ports.sh use

script/chroot/exec.sh passes all four into the chroot.

The step

set -e
source script/phases/70_image/phase.env

OSR=/etc/os-release

# Any earlier stamp goes first: this phase is re-run on the tree it finds.
grep -v -e '^BUILD_ID=' -e '^KDOS_BUILD_DATE=' "$OSR" > "$OSR.new" || true
cat "$OSR.new" > "$OSR"
rm -f "$OSR.new"

vid=$(sed -n 's/^VERSION_ID="\{0,1\}\([^"]*\)"\{0,1\}$/\1/p' "$OSR")
if [ -n "${KDOS_GIT_RELEASE:-}" ] && [ "${KDOS_GIT_RELEASE#v}" != "$vid" ]; then
    echo "FATAL: release $KDOS_GIT_RELEASE but /etc/os-release says VERSION_ID=$vid — bump fs/etc/os-release, or run 10_bootstrap:000_file_system.sh again if it is bumped" >&2
    exit 1
fi

rm -f /etc/kdos-release
if [ -z "${KDOS_GIT_COMMIT:-}" ]; then
    echo "No commit given; $OSR left unstamped."
    exit 0
fi

id="$KDOS_GIT_COMMIT"
[ "${KDOS_GIT_DIRTY:-0}" = 1 ] && id="$id-dirty"
echo "BUILD_ID=\"$id\"" >> "$OSR"
[ -n "${KDOS_GIT_DATE:-}" ] && echo "KDOS_BUILD_DATE=\"$KDOS_GIT_DATE\"" >> "$OSR"
echo "Stamped $OSR: BUILD_ID=$id${KDOS_GIT_DATE:+, KDOS_BUILD_DATE=$KDOS_GIT_DATE}"

script/phases/70_image/045_identity.sh, lines 51–77

The phase runs on the tree it finds, so the file may already carry a stamp from an earlier run. The grep drops any BUILD_ID and KDOS_BUILD_DATE line, and cat writes what is left back into the same file, so its mode and owner are unchanged.

Then the step reads VERSION_ID back. On a release build, KDOS_GIT_RELEASE is set: a clean checkout with one release tag on HEAD (see Entering the chroot). The step stops when that tag without its v is not the file’s VERSION_ID, for example:

FATAL: release v0.2.1 but /etc/os-release says VERSION_ID=0.2 — bump fs/etc/os-release, or run 10_bootstrap:000_file_system.sh again if it is bumped

The check matters because About this System, kdos version, the boot menus, What’s New and /etc/kdos-release all name the release from this line. An image built from a tag whose file was not bumped would call itself the previous release everywhere.

The root holds the copy of fs/etc/os-release that 10_bootstrap’s file-system step made, so a bump reaches a tree already built only when that step runs again.

Without KDOS_GIT_COMMIT, which is a build not started by make build (kdosbuild run by hand, for instance), the step stops there, and the file carries neither line. About this System then shows the image as unstamped; no commit is made up.

With it, BUILD_ID is the commit, with -dirty appended when the tree had changes git had not recorded. A dirty image cannot be reproduced from its commit alone, and the suffix says so. KDOS_BUILD_DATE is written only when the date is known.

The date is the commit’s, not the clock’s. Two builds of the same commit write the same file, as the rest of the image is meant to be the same for the same tree; a clock date would make them differ in this one file.

Then the step writes /etc/kdos-release, the record of which release this root holds:

ver="$vid+$id"
[ -n "${KDOS_GIT_RELEASE:-}" ] && ver="${KDOS_GIT_RELEASE#v}"

{
    echo '# The KDOS release this root holds. Written by the image build and by'
    echo '# `kdos update` when it fills this root; read by kdos-sysupdated and'
    echo '# kdos-bootctl.'
    echo "VERSION=\"$ver\""
    echo "BUILD_ID=\"$id\""
    echo "BUILD_DATE=\"${KDOS_GIT_DATE:-}\""
    echo "TREE=\"$KDOS_GIT_COMMIT\""
    echo "TREE_TIME=\"${KDOS_GIT_TIME:-0}\""
    echo "INSTALLED_BY=\"medium\""
} > /etc/kdos-release
chmod 0644 /etc/kdos-release
echo "Wrote /etc/kdos-release: $ver, tree time ${KDOS_GIT_TIME:-0}"

script/phases/70_image/045_identity.sh, lines 79–94

The record’s fields:

Field Value
VERSION On a release build, the release without its tag’s v (0.2). On any other build, os-release’s VERSION_ID, a + and the build id (0.2+4dc1f7f826a3-dirty).
BUILD_ID, BUILD_DATE The same values as in /etc/os-release
TREE, TREE_TIME The commit and its time
INSTALLED_BY medium: the root came from the installation medium

VERSION has the one form kdos update also writes when it fills a slot, and the same name kdos-bootctl and kdos-sysupdated give a root without a record, so the two slots of a machine read alike in System Versions and on the logout screen. It is the form kdos version, What’s New, the boot menus, the splash (from the initramfs’s copy), the installer’s Welcome page and the greeter’s footer show. About this System keeps KInfoCenter’s own labelled fields instead: Version: 0.2 and Build: <BUILD_ID>.

The record is what updates are judged by:

Without KDOS_GIT_COMMIT the step removes the file instead.

The end of the file then reads, with the commit’s own values in place of the placeholders:

BUILD_ID="<short commit>"
KDOS_BUILD_DATE="<YYYY-MM-DD>"

Why it runs here

The stamp has to be in the root before 100_packs.sh, so that the base pack kdos, a copy of this root built when KDOS_PACK_KDOS=1, carries it, and before 110_iso.sh squashes the root into system.sfs.

What it leaves

/etc/os-release on the image, with the two lines at its end, and /etc/kdos-release. The installer copies the root, so an installed system carries the stamp of the medium it was installed from.

See also