362.1. linux-7.2.11
Linux kernel
The build-state snapshot was taken from 7.2.11-1; this recipe is 7.2.11-2, so the size, time and contents below describe the earlier build.
| Version | 7.2.11, release 2 |
| Shelf | boot — Everything before userspace: the kernel, microcode, firmware for the host, bootloader and EFI tooling |
| Phase | 60_kernel (Kernel), 2 of 2 in build order |
| Licence | GPL-2.0-only WITH Linux-syscall-note |
| Homepage | https://www.kernel.org/ |
| Build time | 94.7 SBU |
| Installed size | 204.6 MiB in 7295 files |
| Recipe | ports/core/boot/linux/kpkgbuild |
About
The Linux kernel. Its whole configuration is one file beside the recipe, kdos.config, in the minimal form make savedefconfig writes: every symbol whose value differs from the kernel’s default, plus the hardening settings that are written out even where they equal it. build.sh copies the file to .config, lets make olddefconfig fill in the rest, and then refuses to build a kernel that differs from what the file says. The three checks, and the way to change the file without losing settings, are in The kernel configuration; what the hardening lines remove is in The kernel.
The package installs the kernel as /boot/vmlinuz-kdos with its System.map, the modules under /lib/modules/<version>, and the kernel’s user-space API headers under /usr/include. Those headers are the same files the bootstrap’s Linux API headers step wrote from the same source, and this package adopts them. Nothing boots /boot/vmlinuz-kdos where it lies: 70_image copies it into the ISO, and on an installed machine kdos-bootctl deploy copies it into the root slot’s directory on the ESP.
Several of the build dependencies are there for one configuration option each. rust, bindgen and clang are what CONFIG_ needs, and with it the QR-code panic screen; dwarves provides pahole, without which there is no BTF; openssl writes the module-signing key and signs the modules. zstd compresses the kernel image (CONFIG_) and every module as modules_install writes it (CONFIG_), and postinstall.sh uses it again to decompress the modules it puts into the initramfs. cpio is for postinstall.sh alone, which lists the image’s initramfs and writes the archive of this kernel’s modules it appends.
Sources
linux-7.2.11.tar.xz(153.0 MiB)
sha256fd0fc479f983a8c05313f13e9c36330fe6651cf725396748c40d5cd93fa1e6a4
upstream: https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.2.11.tar.xz
archive copy: sources-1/boot--linux-7.2.11.tar.xz
Dependencies
Depends on: bc, bison, flex, perl, openssl, elfutils, zstd, kmod, dwarves, rust, bindgen, clang, cpio.
Required by: no port names it.
Differs from the bootstrap build. Linux API headers builds this source too, in script/phases/10_bootstrap/010_linux_headers.sh, before kpkg exists.
The two name the same switches.
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/60_kernel/phase.env && kpkg install linux'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/boot/linux.
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.
cd /ports/core/boot/linux
echo 'fd0fc479f983a8c05313f13e9c36330fe6651cf725396748c40d5cd93fa1e6a4 linux-7.2.11.tar.xz' | sha256sum -c -
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/linux
SRC=$SRC_ROOT/linux-7.2.11
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf linux-7.2.11.tar.xz -C "$SRC" --strip-components=1
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:
export KBUILD_BUILD_TIMESTAMP="$(LC_ALL=C date -u -d "@${SOURCE_DATE_EPOCH:-0}")"
export KBUILD_BUILD_USER=kdos
export KBUILD_BUILD_HOST=kdos
export KBUILD_BUILD_VERSION=1
make mrproper
cp $PORT_SRC/kdos-logo-mono.pbm drivers/video/logo/kdos-logo-mono.pbm
cp $PORT_SRC/kdos.config .config
KCONFIG_WERROR=1 KCONFIG_WARN_UNKNOWN_SYMBOLS=1 make olddefconfig
if grep -E '^(CONFIG_[A-Za-z0-9_]+=|# CONFIG_[A-Za-z0-9_]+ is not set$)' $PORT_SRC/kdos.config | grep -vxFf .config; then
echo "ERROR: kdos.config sets the lines above and olddefconfig did not keep them" >&2
exit 1
fi
for opt in CONFIG_RUST CONFIG_DRM_PANIC_SCREEN_QR_CODE CONFIG_DEBUG_INFO_BTF CONFIG_DEBUG_INFO_BTF_MODULES CONFIG_SQUASHFS_ZSTD CONFIG_SQUASHFS_XZ; do
grep -qx "$opt=y" .config || { echo "ERROR: $opt was dropped by olddefconfig" >&2; exit 1; }
done
modkey=/kdos/build/keys/linux-module-signing.pem
if [ -d /kdos/build ]; then
if [ ! -s "$modkey" ]; then
mkdir -p "${modkey%/*}"
( umask 077; openssl req -new -nodes -utf8 -sha512 -days 36500 -batch -x509 \
-config $PORT_SRC/x509.genkey -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 \
-outform PEM -out "$modkey.new" -keyout "$modkey.new" )
mv "$modkey.new" "$modkey"
fi
./scripts/config --set-str CONFIG_MODULE_SIG_KEY "$modkey"
fi
make HOSTCFLAGS="-D__attribute_const__= -D__always_inline=inline" bzImage modules
make INSTALL_MOD_PATH=$PKG INSTALL_MOD_STRIP=1 DEPMOD=/bin/true modules_install
rm -f "$PKG/lib/modules/$version/build"
rm -f "$PKG/lib/modules/$version/source"
mkdir -p $PKG/boot
cp arch/x86/boot/bzImage $PKG/boot/vmlinuz-kdos
cp System.map $PKG/boot/System.map-$version
make INSTALL_HDR_PATH=$PKG/usr headers_install
The switches, and why each is set:
KBUILD_BUILD_TIMESTAMP— The date kbuild puts inUTS_VERSION, whichuname -vand the boot banner show; by default it is the moment of the build. The recipe writesSOURCE_DATE_EPOCHas a date, so two builds of the same tree carry the same string. See Reproducible packages.KBUILD_BUILD_USER— Theuserof theuser@hoststring in/proc/versionand the boot banner, by default the output ofwhoami. Pinned tokdos.KBUILD_BUILD_HOST— Thehostof the same string, by default the build machine’s host name, which in the build container is the container’s. Pinned tokdos.KBUILD_BUILD_VERSION— The#Nat the start ofuname -v. Without it kbuild takes the number from a build counter it keeps in a.versionfile in the tree. Pinned to1.KCONFIG_WERROR=1— Kconfig treats its warnings as errors, soolddefconfigstops on a value a symbol cannot take or a selected symbol whose dependencies are not met, instead of printing a warning and carrying on.KCONFIG_WARN_UNKNOWN_SYMBOLS=1— Kconfig warns about every symbol inkdos.configthat this kernel does not have. WithKCONFIG_WERRORthat is an error, so a symbol renamed or removed by a new kernel release stops the build instead of disappearing from the configuration.CONFIG_— Set withMODULE_ SIG_ KEY scripts/config --set-strtobuild/keys/linux-module-signing.pem, but only inside the KDOS build, where/kdos/buildexists. The first build writes the key with the subject inx509.genkey(an ECDSA P-384 key, valid for a hundred years) and every later build signs with the same one. A build anywhere else keeps the kernel’s default, a key generated for that build alone. See Module signing.HOSTCFLAGS— Extra flags for the programs kbuild compiles to run on the build machine. Some of them include the kernel’sswab.h, which uses__attribute_const__and__always_inline. glibc defines both in<sys/cdefs.h>; musl has no such header, so the recipe defines the first as nothing and the second asinline.INSTALL_MOD_PATH=$PKG— The prefixmake modules_installputs in front of/lib/modules, so the modules land in the package and not on the build root.INSTALL_MOD_STRIP=1— Strip each module as it is installed, with--strip-debug. BTF needsCONFIG_, which would otherwise leave full DWARF in every module. TheDEBUG_ INFO .BTFsection is not a debug section and stays, and kbuild signs each module after stripping it.DEPMOD=/bin/true—modules_installrunsscripts/depmod.sh, which calls$DEPMOD; naming/bin/truemakes that step do nothing, so the package carries nomodules.depor other module index.postinstall.shrunsdepmod -bagainst the root the package was installed into.INSTALL_HDR_PATH=$PKG/usr— Wheremake headers_installwrites the sanitised API headers:$PKG/usr/include.
The common switches of each build system are explained in the Flag glossary.
postinstall.sh runs on the installed system after the package is adopted:
# Everything happens under PKG_ROOT, the root kpkgadd is installing into: an A/B
# update installs into the inactive slot, and working on / instead would strip
# the running system's modules and index the wrong tree.
root="${PKG_ROOT:-/}"
root="${root%/}"
# The kernels an installed machine boots are the ones on its ESP, not the one
# in /boot: Limine cannot read every root filesystem the installer offers, so
# each root slot's kernel and initramfs are copied to EFI/kdos/<slot>/ there,
# and an ESP no deploy has touched holds one flat pair in EFI/kdos/ that either
# slot boots. The ESP is the RUNNING system's /boot/efi whichever root this
# package is going into.
esp=/boot/efi/EFI/kdos
# The version a bzImage carries: the boot protocol's kernel_version field at
# 0x20E points, relative to 0x200, at a string that starts with it. Empty for
# anything that is not a bzImage.
kernel_version() {
[ "$(dd if="$1" bs=1 skip=514 count=4 2>/dev/null)" = HdrS ] || return 0
off=$(od -An -tu2 -j 526 -N 2 "$1" 2>/dev/null | tr -d ' ')
[ -n "$off" ] && [ "$off" -gt 0 ] || return 0
dd if="$1" bs=1 skip=$((off + 512)) count=128 2>/dev/null |
tr '\0' '\n' | head -n 1 | cut -d' ' -f1
}
esp_versions=
for k in "$esp/vmlinuz" "$esp"/a/vmlinuz "$esp"/b/vmlinuz; do
[ -f "$k" ] && esp_versions="$esp_versions $(kernel_version "$k")"
done
# Remove module trees of every other kernel. Two kinds stay. The running
# kernel's, when the root is the running system: its modules must keep loading
# until the reboot. And every kernel's on the ESP, in every root: until this
# root's own kernel reaches the ESP, the next boot of it runs one of those, and
# a root stripped of that kernel's modules boots with no GPU, network or sound
# driver and nothing saying why.
running=
[ -z "$root" ] && running=$(uname -r)
for d in "$root"/lib/modules/*/; do
[ -d "$d" ] || continue
ver=$(basename "$d")
[ "$ver" = "$version" ] && continue
[ "$ver" = "$running" ] && continue
case " $esp_versions " in *" $ver "*) continue ;; esac
echo "Removing stale kernel modules: $ver"
rm -rf "$d"
done
echo "Generating modules.dep for $version..."
if command -v depmod >/dev/null; then
depmod -b "${root:-/}" -a "$version"
else
echo "Warning: depmod not found, skipping."
fi
# A reinstall of this same version into the running system (PKG_OLD_VERSION
# is the version kpkgadd replaced: a `--dev` restore, a forced reinstall)
# builds and deploys nothing when this boot's ESP directory already holds what
# a deploy would write: a vmlinuz of this version identical to
# /boot/vmlinuz-kdos, beside an initramfs identical to the one deploy takes
# (/boot/initramfs-kdos.cpio.gz where it exists, else the image's
# /boot/initramfs.cpio.gz, which is all a freshly installed root has). The
# directory is the one this boot's menu entry names with kdos_slot=, or the
# flat EFI/kdos/ of an ESP with no slot directories. Any other install, a
# rebuilt kernel of the same version, and an initramfs-kdos built but never
# deployed, builds and deploys.
on_esp=
if [ -z "$root" ] && [ "${PKG_OLD_VERSION:-}" = "$version-$release" ] &&
mountpoint -q /boot/efi 2>/dev/null; then
slot=$(tr ' ' '\n' < /proc/cmdline 2>/dev/null |
sed -n 's/^kdos_slot=\([ab]\)$/\1/p' | head -n 1)
dir="$esp${slot:+/$slot}"
rd="$root/boot/initramfs-kdos.cpio.gz"
[ -f "$rd" ] || rd="$root/boot/initramfs.cpio.gz"
if [ -f "$rd" ] && cmp -s "$rd" "$dir/initramfs.cpio.gz" &&
[ "$(kernel_version "$dir/vmlinuz" 2>/dev/null)" = "$version" ] &&
cmp -s "$root/boot/vmlinuz-kdos" "$dir/vmlinuz"; then
on_esp=1
fi
fi
if [ -n "$on_esp" ]; then
echo "linux $version is already on the ESP"
exit 0
fi
# The new kernel's initramfs, kept in the root beside the kernel as
# /boot/initramfs-kdos.cpio.gz: `kdos-bootctl deploy` and kinstall take it
# over the image's own, which is built for the image's kernel. The image's
# initramfs stays the base — it carries the microcode, which the early loader
# finds only at the very start of the file, and the init — and a second
# archive is appended after it holding this kernel's copies of the modules the
# base carries for the image's kernel. The kernel unpacks concatenated archives
# in order into one tree, and the init's modprobe looks under `uname -r`, so it
# finds the new set.
#
# The set is /boot/initramfs.modules where the image wrote one. A root with no
# such file takes the set the base itself carries — every module under
# lib/modules/ in it — because without vfat, xfs, f2fs, dm-crypt and md in the
# new kernel's copies, its init cannot read the boot state, count an attempt
# or mount any root those modules serve.
archive_modules() (
f="$1" off=0
# Uncompressed newc archives at the front — the microcode — are walked
# header by header; the compressed part starts after the zero padding
# that follows the last one's trailer.
while [ "$(dd if="$f" bs=1 skip=$off count=6 2>/dev/null | tr -d '\0')" = 070701 ]; do
fsz=$((16#$(dd if="$f" bs=1 skip=$((off + 54)) count=8 2>/dev/null)))
nsz=$((16#$(dd if="$f" bs=1 skip=$((off + 94)) count=8 2>/dev/null)))
name=$(dd if="$f" bs=1 skip=$((off + 110)) count=$((nsz - 1)) 2>/dev/null)
off=$(( (off + 110 + nsz + 3) / 4 * 4 ))
off=$(( (off + fsz + 3) / 4 * 4 ))
[ "$name" = 'TRAILER!!!' ] || continue
while [ "$(od -An -tx1 -j $off -N 4 "$f" 2>/dev/null | tr -d ' \n')" = 00000000 ]; do
off=$((off + 4))
done
done
tail -c +$((off + 1)) "$f" | gzip -dc 2>/dev/null | cpio -t 2>/dev/null |
while read -r p; do
case "$p" in
lib/modules/*/*.ko*|./lib/modules/*/*.ko*) ;;
*) continue ;;
esac
p=${p##*/}
echo "${p%%.ko*}"
done | sort -u
)
build_initramfs() {
out="$1" base="$root/boot/initramfs.cpio.gz" list="$root/boot/initramfs.modules"
if [ ! -f "$base" ]; then
echo "No $base: cannot build an initramfs for $version"
return 1
fi
if [ -f "$list" ]; then
mods=$(cat "$list")
else
mods=$(archive_modules "$base")
fi
if [ -z "$mods" ]; then
echo "No module set in $list or $base: cannot build an" \
"initramfs for $version"
return 1
fi
work=$(mktemp -d) || return 1
mkdir -p "$work/lib/modules/$version"
for m in $mods; do
modprobe -d "${root:-/}" -S "$version" --show-depends "$m" 2>/dev/null
done |
while read -r kind path _; do
[ "$kind" = insmod ] || continue
rel=${path#*/lib/modules/$version/}
dest=$work/lib/modules/$version/${rel%.zst}
[ -e "$dest" ] && continue
mkdir -p "${dest%/*}"
case "$path" in
*.zst) zstd -q -d -c "$path" > "$dest" ;;
*) cp "$path" "$dest" ;;
esac
done
for f in modules.order modules.builtin modules.builtin.modinfo; do
[ -f "$root/lib/modules/$version/$f" ] &&
cp "$root/lib/modules/$version/$f" "$work/lib/modules/$version/"
done
depmod -b "$work" "$version" &&
(cd "$work" && find . | cpio -o -H newc 2>/dev/null) | gzip -9 > "$work.gz" &&
cat "$base" "$work.gz" > "$out"
rc=$?
rm -rf "$work" "$work.gz"
return $rc
}
# A failed build removes the previous one too: it belongs to the kernel this
# package just replaced. `kdos-bootctl deploy` then finds only the image's
# initramfs, and refuses it beside a kernel whose modules it does not carry.
initrd="$root/boot/initramfs-kdos.cpio.gz"
if build_initramfs "$initrd.new"; then
mv -f "$initrd.new" "$initrd"
else
rm -f "$initrd.new" "$initrd"
echo "Warning: no initramfs for $version — a deploy of this root" \
"is refused until one is built"
fi
# Put this kernel on the ESP, into the directory of the slot this root is.
# Installing into the running system, that happens here; installing into
# another root — `kdos update` filling the inactive slot — it is `kdos update`
# that deploys, once every package of the run has gone in, because the slot's
# kernel must not reach the ESP beside a half-updated root.
if [ -n "$root" ]; then
echo "Installed into $root: its kernel reaches the ESP with" \
"\`kdos-bootctl deploy $root\`, which \`kdos update\` runs"
elif [ ! -d "$esp" ] || ! mountpoint -q /boot/efi 2>/dev/null; then
:
elif ! command -v kdos-bootctl >/dev/null; then
echo "Warning: no kdos-bootctl — $version is not on the ESP"
else
echo "Putting $version on the ESP..."
kdos-bootctl deploy / ||
echo "Warning: $version is not on the ESP; the next boot runs" \
"the kernel it ran before"
fi
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/linux, 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 linux-7.2.11-2.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/linux, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: genlogo-mono.py, kdos-logo-mono.pbm, kdos.config, x509.genkey.
Contents
Installed directories: /boot, /lib/modules, /usr/include/asm, /usr/include/asm-generic, /usr/include/drm, /usr/include/fwctl, /usr/include/linux, /usr/include/misc, /usr/include/mtd, /usr/include/rdma, /usr/include/regulator, /usr/include/scsi/fc, /usr/include/sound, /usr/include/video, /usr/include/xen, /usr/share/licenses/linux.
Notes
- The panic-screen logo is a file the kernel tarball does not have.
kdos.configsetsCONFIG_and pointsLOGO CONFIG_atLOGO_ LINUX_ MONO_ FILE drivers/video/logo/kdos-logo-mono.pbm, and the logo’s makefile names that path as an input of the build, sobuild.shcopies the file there from the port before anything is compiled. The.pbmis committed;genlogo-mono.pyregenerates it on a host with PIL, and nothing in the build runs the script. - Two checks after
olddefconfigstop the build. EveryCONFIG_…=and# CONFIG_… is not setline ofkdos.configmust be in the resolved.configunchanged, andCONFIG_,RUST CONFIG_,DRM_ PANIC_ SCREEN_ QR_ CODE CONFIG_,DEBUG_ INFO_ BTF CONFIG_,DEBUG_ INFO_ BTF_ MODULES CONFIG_andSQUASHFS_ ZSTD CONFIG_must beSQUASHFS_ XZ =y.olddefconfigdrops an option whose compiler or tool is missing without a word; these checks turn a missingrustc,bindgen,libclangorpaholeinto a failed build. - Regenerate
kdos.configinside the chroot, or anywhere with the samerustc,clangandpahole. ElsewhereolddefconfigdropsCONFIG_and BTF, andRUST savedefconfigwrites a file without them. - The
buildandsourcelinks are removed fromlib/modules/<version>/. Both point into the work directory the kernel was built in, which is gone once the package is made, and70_image’s gates stop the build on a dangling link. postinstall.shkeeps the boot path consistent. Working on the root it was installed into (PKG_ROOT, the inactive slot duringkdos update), it removes the module trees of kernels that neither run nor sit on the ESP, runsdepmod, builds/boot/initramfs-kdos.cpio.gzfrom the image’s initramfs with this kernel’s modules appended, and, when it was installed into the running system with the ESP mounted, runskdos-bootctl deploy /. Each step and the reason for it is in A new kernel.- A same-version reinstall into the running system stops after
depmod. WhenPKG_OLD_VERSION(set by kpkgadd) is this$version-$releaseand this boot’s ESP directory holds avmlinuzidentical to/boot/vmlinuz-kdosbeside an initramfs identical to the onekdos-bootctl deploywould take (/boot/initramfs-kdos.cpio.gz, else the image’s/boot/initramfs.cpio.gzon a root that has none, as a fresh install has), the hook printslinux <version> is already on the ESPand builds and deploys nothing. That is what a source build’s restore of the kernel’s development files does to it; a kernel rebuilt at the same version differs from the ESP’s copy and is deployed. - The package is not byte-identical between builds. An ECDSA signature uses a fresh random number each time, so every module’s appended signature differs even with the same key.