From d220150a8c39cd224076361807a68edd88b8fc1a Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 01/15] kernel-configs: add installer fragment The installer image is an iso-hybrid image, which d-i's cdrom-detect and live-boot mount as ISO 9660, so the kernel needs ISO9660_FS. The values match Debian's kernel config. The live squashfs uses live-build's default xz compression, which squashfs.config already enables. Signed-off-by: Christopher Obbard --- kernel-configs/installer.config | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 kernel-configs/installer.config diff --git a/kernel-configs/installer.config b/kernel-configs/installer.config new file mode 100644 index 00000000..cec2f5fa --- /dev/null +++ b/kernel-configs/installer.config @@ -0,0 +1,9 @@ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# the installer is an iso-hybrid image written to a USB stick; d-i's +# cdrom-detect and live-boot mount it as ISO 9660; values as in Debian's +# kernel config +CONFIG_ISO9660_FS=m +CONFIG_JOLIET=y +CONFIG_ZISOFS=y From 16d02588af37e23fb15afd97636cdc28280e248a Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 02/15] installer: add debian-installer build infrastructure Debian's own installer images can't boot Qualcomm devices: they lack the kernel, firmware and DTB handling these need. Add a live-build based script that builds a debian-installer cdrom image as an iso-hybrid image, which can be written to a USB stick and booted by the UEFI firmware, as the base for the customisations that follow. The image only carries the installer and its pool, so live-build's rootfs stages are skipped. Signed-off-by: Christopher Obbard --- installer/.gitignore | 1 + installer/build-installer.sh | 137 ++++++++++++++++++ .../live-build/defaults/cdrom_udeb_include | 6 + 3 files changed, 144 insertions(+) create mode 100644 installer/.gitignore create mode 100755 installer/build-installer.sh create mode 100644 installer/live-build/defaults/cdrom_udeb_include diff --git a/installer/.gitignore b/installer/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/installer/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/installer/build-installer.sh b/installer/build-installer.sh new file mode 100755 index 00000000..cc2beaa9 --- /dev/null +++ b/installer/build-installer.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +set -euo pipefail + +ARCH=arm64 +SUITE="trixie" +USAGE="Usage: $0 [--suite SUITE]" + +while [ "$#" -gt 0 ]; do + case "$1" in + --suite) + SUITE="${2:?Missing value for --suite}" + shift 2 + ;; + *) + echo "$USAGE" >&2 + exit 1 + ;; + esac +done + +if [ "$(id -u)" -ne 0 ]; then + echo "Run this script as root (sudo $0 ...)" >&2 + exit 1 +fi + +if ! command -v lb >/dev/null 2>&1; then + echo 'Error: live-build (lb) is not installed' >&2 + exit 1 +fi + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +INSTALLER_DIR=$SCRIPT_DIR + +# Each suite has its own live-build tree in BUILD_DIR, so e.g. trixie and +# forky don't collide. +BUILD_DIR="$INSTALLER_DIR/build/$SUITE" + +# The build only runs once in a tree, so refuse to reuse one. +if [ -e "$BUILD_DIR" ]; then + echo "$BUILD_DIR already exists, remove it first" >&2 + exit 1 +fi + +mkdir -p "$(dirname "$BUILD_DIR")" +mkdir "$BUILD_DIR" +CALLER_DIR=$PWD +cd "$BUILD_DIR" + +# Print a stage's name. +stage() { + echo "=== $1 ===" +} + +stage "Configure live-build" + +# live-build's rootfs stages are skipped, as the installer installs from +# the pool (see "Skip live-build's rootfs stages" below). +# +# The bootstrap is still cached, in the build tree: installer_debian-installer +# reuses its packages from cache/packages.bootstrap/ and fails without them. +# +# Set the mirrors explicitly, and the parent mirrors too as lb saves them +# separately and doesn't rederive them. Keep the trailing slashes: lb appends +# "dists" to the debian-installer mirror directly. +MIRROR="http://deb.debian.org/debian/" +MIRROR_SECURITY="http://security.debian.org/" +MIRROR_ARGS=() +for mirror in bootstrap chroot debian-installer; do + MIRROR_ARGS+=(--mirror-"$mirror" "$MIRROR" --parent-mirror-"$mirror" "$MIRROR") +done +MIRROR_ARGS+=(--mirror-chroot-security "$MIRROR_SECURITY" + --parent-mirror-chroot-security "$MIRROR_SECURITY") + +# Build an iso-hybrid image, which also boots from a USB stick. The kernel +# needs ISO 9660 support, see kernel-configs/installer.config. +lb config \ + "${MIRROR_ARGS[@]}" \ + --distribution "$SUITE" \ + --architectures "$ARCH" \ + --linux-packages none \ + --debian-installer cdrom \ + --debian-installer-distribution "$SUITE" \ + --debian-installer-gui true \ + --cache-stages "bootstrap" \ + --binary-images iso-hybrid + +# Copy tracked customizations from live-build/ on top of the generated +# config/. + +# Copy a live-build/ file to the build tree, keeping its mode. +overlay() { + mkdir -p "$(dirname "$BUILD_DIR/$2")" + cp -a "$INSTALLER_DIR/live-build/$1" "$BUILD_DIR/$2" +} + +overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include + +stage "Build bootstrap and chroot" + +lb bootstrap +lb chroot + +stage "Build installer" + +lb installer + +# live-build only ships udeb_include lists for amd64, and binary_disk fails +# for cdrom when ${ARCH}_udeb_include is missing. It leaves an existing +# binary/.disk/udeb_include alone, so pre-seed ours from the overlay. +install -D -m 0644 "$BUILD_DIR/config/debian-cd/cdrom_udeb_include" \ + "$BUILD_DIR/binary/.disk/udeb_include" + +# Skip live-build's rootfs stages. binary_chroot copies the chroot and +# binary_rootfs runs mksquashfs on it, then binary_manifest lists its +# packages. None of it is used: the image only boots the installer, and +# d-i installs from the pool. Marking the stages done leaves the chroot as +# binary_rootfs would, and nothing else needs them. ("--chroot-filesystem +# none" can't do this: it replaces the whole binary/ tree with the chroot, +# wiping the installer.) +mkdir -p "$BUILD_DIR/.build" +touch \ + "$BUILD_DIR/.build/binary_chroot" \ + "$BUILD_DIR/.build/binary_rootfs" \ + "$BUILD_DIR/.build/binary_manifest" + +stage "Build image" + +lb binary + +echo "=== Complete ===" + +# Show the image path relative to where the script was run from. +cd "$CALLER_DIR" +ls -lh "$(realpath --relative-to=. "$BUILD_DIR")"/*.iso diff --git a/installer/live-build/defaults/cdrom_udeb_include b/installer/live-build/defaults/cdrom_udeb_include new file mode 100644 index 00000000..fcab55e4 --- /dev/null +++ b/installer/live-build/defaults/cdrom_udeb_include @@ -0,0 +1,6 @@ +# Extra udebs for the cdrom installer. Networking is kept for apt-setup and a +# mirror on the target; the base system still installs from the ISO's pool. +netcfg +ethdetect +choose-mirror-bin +apt-mirror-setup From 330ab0d62748cac33540824fbebd8fae9610fae0 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 03/15] installer: replace the d-i kernel with a custom kernel The stock d-i kernel doesn't support the Qualcomm hardware. Replace the installer's kernel and modules with the ones from the given linux-image package, trimmed to what the installer needs, and add the package to the pool so the target installs the same kernel. Drop the stock kernel's packages and module udebs from the pool, which the custom kernel can't use, along with the udebs for hardware the image doesn't target. Pass the kernel arguments the Qualcomm devices need from kernel/kernel-cmdline to live-build's boot entries, and to the target through d-i's add-kernel-opts, as d-i doesn't copy the arguments before the "---" to the target. Name the build directory after the suite and the kernel, so builds of different kernels don't collide, and add Makefile targets to build and clean it. Unpack the d-i initrds without their device nodes (dev/console and dev/null) and write the nodes back as a second cpio archive after the repacked one, which the kernel unpacks in turn. Unpacking made cpio mknod them, which needs CAP_MKNOD, and a rootless (e.g. podman) container lacks it even with --privileged. fakeroot isn't an option, as it hung in the CI container. Signed-off-by: Christopher Obbard --- Makefile | 24 ++ installer/build-installer.sh | 133 ++++++++++- .../hooks/0060-prune-pool.hook.binary | 151 ++++++++++++ .../defaults/preseed/no-kernel-modules.cfg | 6 + .../kernel/archives/linux-base.pref.chroot | 9 + .../hooks/0050-replace-di-kernel.hook.binary | 26 ++ .../live-build/kernel/initrd-modules.rules | 47 ++++ installer/live-build/kernel/kernel-cmdline | 14 ++ .../kernel/lib/replace-di-kernel.sh | 224 ++++++++++++++++++ .../live-build/kernel/lib/trim-modules.sh | 74 ++++++ .../package-lists/linux-base.list.binary | 6 + 11 files changed, 706 insertions(+), 8 deletions(-) create mode 100755 installer/live-build/defaults/hooks/0060-prune-pool.hook.binary create mode 100644 installer/live-build/defaults/preseed/no-kernel-modules.cfg create mode 100644 installer/live-build/kernel/archives/linux-base.pref.chroot create mode 100755 installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary create mode 100644 installer/live-build/kernel/initrd-modules.rules create mode 100644 installer/live-build/kernel/kernel-cmdline create mode 100755 installer/live-build/kernel/lib/replace-di-kernel.sh create mode 100755 installer/live-build/kernel/lib/trim-modules.sh create mode 100644 installer/live-build/kernel/package-lists/linux-base.list.binary diff --git a/Makefile b/Makefile index 926addcf..fa777b84 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,30 @@ flash: debos-recipes/qualcomm-linux-debian-flash.yaml dtbs.tar.gz # make PYTEST_OPTS=--verbose test PYTEST_OPTS ?= +# The installer boots the kernel from KERNEL_DEB, a linux-image .deb, and +# installs SUITE, e.g.: +# make installer KERNEL_DEB=linux-image-custom.deb SUITE=forky +# INSTALLER_OPTS are passed to the installer build script, e.g.: +# make installer KERNEL_DEB=... INSTALLER_OPTS="--kernel-name qcom-next" +# live-build has to run as root, so the installer targets use sudo unless make +# already runs as root. +KERNEL_DEB ?= +SUITE ?= trixie +INSTALLER_OPTS ?= +INSTALLER_SUDO := $(if $(filter 0,$(shell id -u)),,sudo) + +.PHONY: installer +installer: + @if [ -z "$(KERNEL_DEB)" ]; then \ + echo "Set KERNEL_DEB to the kernel's linux-image .deb" >&2; \ + exit 1; \ + fi + $(INSTALLER_SUDO) installer/build-installer.sh --suite $(SUITE) $(INSTALLER_OPTS) $(KERNEL_DEB) + +.PHONY: clean-installer +clean-installer: + $(INSTALLER_SUDO) rm -rf installer/build + # run all the tests .PHONY: test test: test-qemu test-unit diff --git a/installer/build-installer.sh b/installer/build-installer.sh index cc2beaa9..f8ad6b3e 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -6,7 +6,9 @@ set -euo pipefail ARCH=arm64 SUITE="trixie" -USAGE="Usage: $0 [--suite SUITE]" +KERNEL_NAME="" +KERNEL_DEB="" +USAGE="Usage: $0 [--suite SUITE] [--kernel-name NAME] KERNEL.deb" while [ "$#" -gt 0 ]; do case "$1" in @@ -14,13 +16,29 @@ while [ "$#" -gt 0 ]; do SUITE="${2:?Missing value for --suite}" shift 2 ;; + # Names the build directory, e.g. qcom-next; defaults to the + # kernel's version. + --kernel-name) + KERNEL_NAME="${2:?Missing value for --kernel-name}" + shift 2 + ;; + # The kernel's linux-image package, with its modules and DTBs. *) - echo "$USAGE" >&2 - exit 1 + if [ -n "$KERNEL_DEB" ]; then + echo "$USAGE" >&2 + exit 1 + fi + KERNEL_DEB=$(realpath "$1") + shift ;; esac done +if [ -z "$KERNEL_DEB" ]; then + echo "$USAGE" >&2 + exit 1 +fi + if [ "$(id -u)" -ne 0 ]; then echo "Run this script as root (sudo $0 ...)" >&2 exit 1 @@ -34,13 +52,24 @@ fi SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) INSTALLER_DIR=$SCRIPT_DIR -# Each suite has its own live-build tree in BUILD_DIR, so e.g. trixie and -# forky don't collide. -BUILD_DIR="$INSTALLER_DIR/build/$SUITE" +# The kernel's package and version. +KERNEL_PACKAGE=$(dpkg-deb -f "$KERNEL_DEB" Package) +case "$KERNEL_PACKAGE" in + linux-image-*) ;; + *) + echo "$KERNEL_DEB is not a linux-image package" >&2 + exit 1 + ;; +esac +KVER="${KERNEL_PACKAGE#linux-image-}" + +# Each kernel and suite has its own live-build tree in BUILD_DIR, so e.g. +# trixie and forky don't collide. +BUILD_DIR="$INSTALLER_DIR/build/$SUITE-${KERNEL_NAME:-$KVER}" # The build only runs once in a tree, so refuse to reuse one. if [ -e "$BUILD_DIR" ]; then - echo "$BUILD_DIR already exists, remove it first" >&2 + echo "$BUILD_DIR already exists, remove it first (make clean-installer)" >&2 exit 1 fi @@ -56,6 +85,10 @@ stage() { stage "Configure live-build" +# The kernel arguments the Qualcomm machines need, from comment-stripped +# kernel/kernel-cmdline. +KERNEL_ARGS="$(grep -v '^#' "$INSTALLER_DIR/live-build/kernel/kernel-cmdline" | xargs)" + # live-build's rootfs stages are skipped, as the installer installs from # the pool (see "Skip live-build's rootfs stages" below). # @@ -74,10 +107,22 @@ done MIRROR_ARGS+=(--mirror-chroot-security "$MIRROR_SECURITY" --parent-mirror-chroot-security "$MIRROR_SECURITY") +# Only stable suites have backports. On trixie, the pool needs some +# packages from them: see the package lists of the kernel topic. +BACKPORTS_ARGS=() +if [ "$SUITE" = "trixie" ]; then + BACKPORTS_ARGS=(--backports true) +fi + # Build an iso-hybrid image, which also boots from a USB stick. The kernel # needs ISO 9660 support, see kernel-configs/installer.config. +# +# live-build's GRUB menu passes the kernel arguments to the installer: +# --bootappend-install ends up before the "---", so d-i doesn't give it to +# the target (the preseed's add-kernel-opts does). lb config \ "${MIRROR_ARGS[@]}" \ + "${BACKPORTS_ARGS[@]}" \ --distribution "$SUITE" \ --architectures "$ARCH" \ --linux-packages none \ @@ -85,7 +130,8 @@ lb config \ --debian-installer-distribution "$SUITE" \ --debian-installer-gui true \ --cache-stages "bootstrap" \ - --binary-images iso-hybrid + --binary-images iso-hybrid \ + --bootappend-install "$KERNEL_ARGS" # Copy tracked customizations from live-build/ on top of the generated # config/. @@ -96,8 +142,45 @@ overlay() { cp -a "$INSTALLER_DIR/live-build/$1" "$BUILD_DIR/$2" } +# Installer defaults: the pool, the udebs and the tasks. +overlay defaults/hooks/0060-prune-pool.hook.binary \ + config/hooks/normal/0060-prune-pool.hook.binary + +# The custom kernel, in the installer and the pool. +overlay kernel/package-lists/linux-base.list.binary \ + config/package-lists/linux-base.list.binary +overlay kernel/hooks/0050-replace-di-kernel.hook.binary \ + config/hooks/normal/0050-replace-di-kernel.hook.binary +if [ "$SUITE" = "trixie" ]; then + overlay kernel/archives/linux-base.pref.chroot \ + config/archives/linux-base.pref.chroot +fi + overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include +# live-build's config/preseed/ only ends up as /install/preseed.cfg on the +# image, which d-i ignores without a file= boot argument. So +# replace-di-kernel.sh puts the preseed in the initrd as /preseed.cfg +# instead, which d-i always loads, before anything else runs. (Not via +# config/includes.installer: live-build unpacks the initrd without fakeroot, +# which can't mknod in a container.) +PRESEED="$BUILD_DIR/config/installer-preseed.cfg" +cat "$INSTALLER_DIR/live-build/defaults/preseed/no-kernel-modules.cfg" \ + > "$PRESEED" + +stage "Prepare installer" + +# Add the custom kernel to the pool, so base-installer installs it on the +# target instead of the stock one. lb installer copies the debs in +# config/packages.binary/ into the pool. They're named as apt would name them, +# which lb installer's *_$ARCH.deb and *_all.deb globs rely on. The +# 0060-prune-pool hook drops the stock kernel, keeping the debs listed +# in config/kernel-debs.list. +KERNEL_VERSION=$(dpkg-deb -f "$KERNEL_DEB" Version) +POOL_NAME="${KERNEL_PACKAGE}_${KERNEL_VERSION#*:}_$(dpkg-deb -f "$KERNEL_DEB" Architecture).deb" +install -D -m 0644 "$KERNEL_DEB" "$BUILD_DIR/config/packages.binary/$POOL_NAME" +echo "$POOL_NAME" > "$BUILD_DIR/config/kernel-debs.list" + stage "Build bootstrap and chroot" lb bootstrap @@ -107,6 +190,37 @@ stage "Build installer" lb installer +stage "Unpack kernel" + +# For 0050-replace-di-kernel.hook.binary, which runs during lb binary. +KERNEL_DIR="$BUILD_DIR/kernel" +rm -rf "$KERNEL_DIR" +mkdir -p "$KERNEL_DIR" +trap 'rm -rf "$KERNEL_DIR"' EXIT + +echo "Unpacking $KERNEL_DEB" +dpkg-deb -x "$KERNEL_DEB" "$KERNEL_DIR" + +stage "Configure installer kernel" + +# The topics' preseeds are gathered into $PRESEED above. Add the custom +# kernel to it: base-installer would otherwise look for the stock kernel's +# package. +cat >> "$PRESEED" < "$BUILD_DIR/config/replace-di-kernel.conf" + # live-build only ships udeb_include lists for amd64, and binary_disk fails # for cdrom when ${ARCH}_udeb_include is missing. It leaves an existing # binary/.disk/udeb_include alone, so pre-seed ours from the overlay. @@ -130,6 +244,9 @@ stage "Build image" lb binary +rm -rf "$KERNEL_DIR" +trap - EXIT + echo "=== Complete ===" # Show the image path relative to where the script was run from. diff --git a/installer/live-build/defaults/hooks/0060-prune-pool.hook.binary b/installer/live-build/defaults/hooks/0060-prune-pool.hook.binary new file mode 100755 index 00000000..910f5320 --- /dev/null +++ b/installer/live-build/defaults/hooks/0060-prune-pool.hook.binary @@ -0,0 +1,151 @@ +#!/bin/bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build binary-stage hook (config/hooks/normal/*.binary). +# +# Runs non-chrooted, cwd=binary/, after lb installer has filled the pool and +# generated its indices, and before binary_checksums and binary_iso. +# +# Removes the packages the installer doesn't need from the ISO's package +# pool, which shrinks the ISO, then regenerates the Packages indices and +# each dists/*/Release, which lists their hashes. +set -euo pipefail + +if ! command -v apt-ftparchive >/dev/null 2>&1; then + echo "0060-prune-pool: apt-ftparchive not found (install apt-utils)" >&2 + exit 1 +fi + +REMOVED=() +shopt -s nullglob + +# Adds the pool-udeb/ files of the given udeb packages, if on the ISO. +remove_udebs() { + local pkg f + + for pkg in "$@"; do + for f in pool-udeb/*/*/*/"${pkg}"_*.udeb; do + REMOVED+=("$f") + done + done +} + +# The stock kernel module udebs (pool-udeb/*/l/linux*/, ~71 MB): lb +# installer adds them regardless of --linux-packages none, but the installer +# boots the custom kernel from replace-di-kernel.sh, which can't load them. +for f in pool-udeb/*/l/linux/*.udeb pool-udeb/*/l/linux-signed-*/*.udeb; do + REMOVED+=("$f") +done + +# The stock kernel debs (linux-image-*, and Debian's split linux-base-*, +# linux-binary-*, linux-modules-*): build-installer.sh adds the custom kernel to the +# pool and preseeds base-installer to install it on the target. The debs +# build-installer.sh added are listed in config/kernel-debs.list and stay, since the +# stock kernel can share their pool directory. +HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +KERNEL_DEBS_LIST="$HOOK_DIR/../../kernel-debs.list" +for f in pool/*/l/linux/*.deb pool/*/l/linux-signed-*/*.deb; do + case "${f##*/}" in + linux-image-* | linux-base-[0-9]* | linux-binary-* | linux-modules-*) ;; + *) continue ;; + esac + if grep -qxF "${f##*/}" "$KERNEL_DEBS_LIST"; then + continue + fi + REMOVED+=("$f") +done + +# shim and mokutil stay: grub-installer installs shim-signed on the target +# from the pool. + +# The udebs for hardware the ISO doesn't target (it boots UEFI machines): +# depthcharge-tools-installer and partman-cros (ChromeOS bootloader), +# flash-kernel-installer (U-Boot and other non-UEFI boards), pcmciautils-udeb +# (PCMCIA) and console-keymaps-* (keyboards of old non-PC machines). +remove_udebs \ + depthcharge-tools-installer \ + partman-cros \ + flash-kernel-installer \ + pcmciautils-udeb \ + console-keymaps-acorn \ + console-keymaps-amiga \ + console-keymaps-atari \ + console-keymaps-dec \ + console-keymaps-mac \ + console-keymaps-sun + +# The debugging udebs (strace, screen): the installer doesn't need them. +# pciutils-udeb stays: disk-detect and ethdetect depend on it. +remove_udebs \ + strace-udeb \ + screen-udeb + +[ "${#REMOVED[@]}" -gt 0 ] || exit 0 + +echo "Removing from the pool:" +printf ' %s\n' "${REMOVED[@]##*/}" + +rm -f "${REMOVED[@]}" +# Once each: a directory holding several of them is gone after the first. +mapfile -t REMOVED_DIRS < <(printf '%s\n' "${REMOVED[@]%/*}" | sort -u) +rmdir --ignore-fail-on-non-empty "${REMOVED_DIRS[@]}" + +# Regenerate an index the same way lb installer does. +regenerate_packages() { + local pool_dir="$1" index_dir="$2" + + [ -d "$index_dir" ] || return 0 + + echo "Regenerating $index_dir/Packages" + apt-ftparchive packages "$pool_dir" > "$index_dir/Packages" + if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then + touch -d "@$SOURCE_DATE_EPOCH" "$index_dir/Packages" + fi + gzip -9 -n -c "$index_dir/Packages" > "$index_dir/Packages.gz" +} + +for dist_dir in dists/*/; do + dist_dir="${dist_dir%/}" + release="$dist_dir/Release" + + [ -f "$release" ] || continue + # e.g. a stable -> trixie symlink + [ -L "$dist_dir" ] && continue + + for index_dir in "$dist_dir"/*/binary-*; do + component=$(basename "$(dirname "$index_dir")") + regenerate_packages "pool/$component" "$index_dir" + done + + for index_dir in "$dist_dir"/*/debian-installer/binary-*; do + component=$(basename "$(dirname "$(dirname "$index_dir")")") + regenerate_packages "pool-udeb/$component" "$index_dir" + done + + # Keep lb installer's header fields, and write the new Release + # outside the dist so it doesn't hash itself. + field() { + sed -n "s/^$1: //p" "$release" + } + + echo "Regenerating $release" + new_release=$(mktemp) + apt-ftparchive \ + -o APT::FTPArchive::Release::Origin="$(field Origin)" \ + -o APT::FTPArchive::Release::Label="$(field Label)" \ + -o APT::FTPArchive::Release::Suite="$(field Suite)" \ + -o APT::FTPArchive::Release::Version="$(field Version)" \ + -o APT::FTPArchive::Release::Codename="$(field Codename)" \ + -o APT::FTPArchive::Release::Date="$(field Date)" \ + -o APT::FTPArchive::Release::Architectures="$(field Architectures)" \ + -o APT::FTPArchive::Release::Components="$(field Components)" \ + -o APT::FTPArchive::Release::Description="$(field Description)" \ + release "$dist_dir" > "$new_release" + rm -f "$release" + mv "$new_release" "$release" + chmod 0644 "$release" + if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then + touch -d "@$SOURCE_DATE_EPOCH" "$release" + fi +done diff --git a/installer/live-build/defaults/preseed/no-kernel-modules.cfg b/installer/live-build/defaults/preseed/no-kernel-modules.cfg new file mode 100644 index 00000000..2df0f952 --- /dev/null +++ b/installer/live-build/defaults/preseed/no-kernel-modules.cfg @@ -0,0 +1,6 @@ +# 0060-prune-pool.hook.binary removes the stock kernel's module +# udebs from the pool, since the custom kernel from replace-di-kernel.sh +# can't load them. anna then finds no kernel modules on the ISO and asks +# whether to continue without them. Always continue: all the modules are +# already in the initrd. +d-i anna/no_kernel_modules boolean true diff --git a/installer/live-build/kernel/archives/linux-base.pref.chroot b/installer/live-build/kernel/archives/linux-base.pref.chroot new file mode 100644 index 00000000..2b5d7398 --- /dev/null +++ b/installer/live-build/kernel/archives/linux-base.pref.chroot @@ -0,0 +1,9 @@ +# Only on trixie, with lb config --backports true (see build-installer.sh). +# +# The custom kernel depends on a newer linux-base than trixie's, so take +# it from trixie-backports, which apt otherwise only uses when asked +# (NotAutomatic). This resolves it for the ISO's pool +# (package-lists/linux-base.list.binary). +Package: src:linux-base +Pin: release n=trixie-backports +Pin-Priority: 900 diff --git a/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary b/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary new file mode 100755 index 00000000..7edcaa2f --- /dev/null +++ b/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build binary-stage hook (config/hooks/normal/*.binary). +# +# Runs non-chrooted, cwd=binary/, after lb binary's binary_package-lists has +# added the packages of *.list.binary to the pool, and before +# 0060-prune-pool.hook.binary and the GRUB hooks. +# +# Replaces the kernel in the installer's initrds with the custom one, which +# build-installer.sh unpacks to $KERNEL_DIR, using lib/replace-di-kernel.sh. +# +# build-installer.sh writes INSTALLER_DIR and KERNEL_DIR to +# config/replace-di-kernel.conf. +set -euo pipefail + +# shellcheck source=/dev/null +. ../config/replace-di-kernel.conf + +# The rules leave the modules the installer doesn't need out of its initrds. +"$INSTALLER_DIR/live-build/kernel/lib/replace-di-kernel.sh" \ + ../config/installer-preseed.cfg \ + "$INSTALLER_DIR/live-build/kernel/initrd-modules.rules" \ + "$KERNEL_DIR" \ + install diff --git a/installer/live-build/kernel/initrd-modules.rules b/installer/live-build/kernel/initrd-modules.rules new file mode 100644 index 00000000..5f5527b1 --- /dev/null +++ b/installer/live-build/kernel/initrd-modules.rules @@ -0,0 +1,47 @@ +# Kernel modules to leave out of the installer initrds, for +# live-build/kernel/lib/trim-modules.sh: one glob per line, relative to +# lib/modules/$KVER/kernel/ ("*" also matches "/"). A plain glob drops, +# "!" keeps again, the last match wins. Whatever a kept module depends on is +# kept anyway, e.g. drm.ko for msm. + +# Audio, cameras, video codecs: the installer doesn't use them. +sound/* +drivers/media/* + +# Display: only the Qualcomm GPU/display driver and the panels and bridges +# its boards use. +drivers/gpu/* +!drivers/gpu/drm/msm/* +!drivers/gpu/drm/panel/* +!drivers/gpu/drm/bridge/* + +# Wifi: the installer installs from its own pool, and its initrds have no +# wifi firmware. +drivers/net/wireless/* +net/wireless/* +net/mac80211/* + +# Wired: only the NICs Qualcomm boards use. USB network adapters +# (drivers/net/usb) stay. +drivers/net/ethernet/* +!drivers/net/ethernet/stmicro/* +!drivers/net/ethernet/qualcomm/* +!drivers/net/ethernet/realtek/* + +# Nothing the installer needs. +net/bluetooth/* +drivers/bluetooth/* +net/nfc/* +drivers/nfc/* +drivers/net/can/* +net/can/* +drivers/net/dsa/* +net/dsa/* +drivers/staging/* +drivers/iio/* +drivers/hwtracing/* +drivers/greybus/* +drivers/fpga/* +drivers/xen/* +drivers/gnss/* +drivers/perf/* diff --git a/installer/live-build/kernel/kernel-cmdline b/installer/live-build/kernel/kernel-cmdline new file mode 100644 index 00000000..39dc7829 --- /dev/null +++ b/installer/live-build/kernel/kernel-cmdline @@ -0,0 +1,14 @@ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Extra kernel arguments for the installer's GRUB entries and, through +# d-i's add-kernel-opts, the target's. +# Read by build-installer.sh, which skips the # comment lines and joins the +# rest; not shipped in the ISO itself. +clk_ignore_unused pd_ignore_unused + +# Some DTs (e.g. the Glymur CRD's) set /chosen/stdout-path to the serial +# port, which then becomes /dev/console. d-i runs on /dev/console, so it +# would start on serial and leave the screen blank. An explicit console= overrides stdout-path: run the +# installer (and the target's console) on the screen. +console=tty0 diff --git a/installer/live-build/kernel/lib/replace-di-kernel.sh b/installer/live-build/kernel/lib/replace-di-kernel.sh new file mode 100755 index 00000000..ad010f37 --- /dev/null +++ b/installer/live-build/kernel/lib/replace-di-kernel.sh @@ -0,0 +1,224 @@ +#!/usr/bin/env bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +set -euo pipefail + +USAGE="Usage: $0 PRESEED.cfg MODULE_RULES KERNEL_DIR INSTALLER_DIR" +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) + +if [ "$#" -ne 4 ]; then + echo "$USAGE" >&2 + exit 1 +fi + +# The preseed, added to the installer initrds as /preseed.cfg, and the rules +# for trim-modules.sh: modules to leave out. +PRESEED=$(realpath "$1") +MODULE_RULES=$(realpath "$2") + +if [ ! -f "$PRESEED" ]; then + echo "Missing preseed: $PRESEED" >&2 + exit 1 +fi + +if [ ! -f "$MODULE_RULES" ]; then + echo "Missing module rules: $MODULE_RULES" >&2 + exit 1 +fi + +# The custom kernel's package, unpacked. +KERNEL=$(realpath "$3") +INSTALL=$(realpath "$4") + +if [ "$(id -u)" -ne 0 ]; then + echo "Run this script as root" >&2 + exit 1 +fi + +if [ ! -d "$KERNEL" ]; then + echo "Missing kernel directory: $KERNEL" >&2 + exit 1 +fi + +if [ ! -d "$INSTALL" ]; then + echo "Missing $INSTALL; run lb installer first" >&2 + exit 1 +fi + +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT + +# Write a data-less newc cpio entry owned by root: NAME MODE NLINK +# RDEVMAJOR RDEVMINOR, MODE in decimal including the file type bits. +newc_entry() { + local namesize=$((${#1} + 1)) + + printf '070701%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X' \ + 0 "$2" 0 0 "$3" 0 0 0 0 "$4" "$5" "$namesize" 0 + printf '%s\0' "$1" + # Pad the 110-byte header and the name to a multiple of 4 bytes. + head -c $(((4 - (110 + namesize) % 4) % 4)) /dev/zero +} + +# Support both traditional and merged-/usr kernel packages. +MODULES="$KERNEL/lib/modules" + +if [ ! -d "$MODULES" ]; then + MODULES="$KERNEL/usr/lib/modules" +fi + +if [ ! -d "$MODULES" ]; then + echo "Kernel package(s) contain no modules" >&2 + exit 1 +fi + +mapfile -t VERSIONS < <( + find "$MODULES" \ + -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n' +) + +if [ "${#VERSIONS[@]}" -ne 1 ]; then + echo "Expected exactly one kernel release" >&2 + exit 1 +fi + +KVER="${VERSIONS[0]}" +VMLINUX="$KERNEL/boot/vmlinuz-$KVER" + +if [ ! -f "$VMLINUX" ]; then + echo "Missing kernel image: $VMLINUX" >&2 + exit 1 +fi + +echo "Custom kernel: $KVER" + +# Kernel packages don't necessarily ship modules.dep (their postinst may +# generate it), and trim-modules.sh needs it. depmod looks in lib/modules, so give a +# merged-/usr tree the usual /lib symlink. +if [ ! -e "$KERNEL/lib" ]; then + ln -s usr/lib "$KERNEL/lib" +fi + +depmod -b "$KERNEL" "$KVER" + +# Trim the modules once here, rather than in each initrd. +echo "Trimming modules with $MODULE_RULES" +"$SCRIPT_DIR/trim-modules.sh" "$MODULES/$KVER" "$MODULE_RULES" + +COUNT=0 + +for INITRD in \ + "$INSTALL/initrd.gz" \ + "$INSTALL/gtk/initrd.gz" +do + if [ ! -f "$INITRD" ]; then + echo "Missing $INITRD; run lb installer first" >&2 + exit 1 + fi + + DIR=$(dirname "$INITRD") + ROOT="$WORK/initrd-$COUNT" + + mkdir -p "$ROOT" + + echo "Processing $INITRD" + + # The initrd's device nodes (dev/console, dev/null), as "NAME MODE + # MAJOR MINOR" lines. Creating them needs CAP_MKNOD, which a rootless + # (e.g. podman) container lacks even with --privileged, and fakeroot + # hung in the CI container; so leave them out when unpacking and add + # them back to the archive when repacking. + NODES="$WORK/nodes-$COUNT" + gzip -dc "$INITRD" | + cpio -itv --quiet | + awk '$1 ~ /^[cb]/ { + mode = substr($1, 1, 1) == "c" ? 8192 : 24576 + for (i = 2; i <= 10; i++) + if (substr($1, i, 1) != "-") + mode += 2 ^ (10 - i) + sub(",", "", $5) + print $NF, mode, $5, $6 + }' > "$NODES" + + EXCLUDE=() + if [ -s "$NODES" ]; then + cut -d ' ' -f 1 "$NODES" > "$NODES.names" + EXCLUDE=(--nonmatching --pattern-file="$NODES.names") + fi + + # Extract the existing Debian Installer userspace. + echo " Unpacking" + ( + cd "$ROOT" + + gzip -dc "$INITRD" | + cpio -idmu --quiet --no-absolute-filenames "${EXCLUDE[@]}" + ) + + # Handle traditional and merged-/usr installer initrds. + if [ -L "$ROOT/lib" ]; then + if [ "$(readlink "$ROOT/lib")" != "usr/lib" ]; then + echo "Unsupported /lib symlink" >&2 + exit 1 + fi + + MODULE_DEST="$ROOT/usr/lib/modules" + else + MODULE_DEST="$ROOT/lib/modules" + fi + + # Remove modules belonging to the original d-i kernel. + echo " Replacing modules" + rm -rf "$MODULE_DEST" + + # Include the custom kernel's (trimmed) modules. + mkdir -p "$MODULE_DEST" + + cp -a \ + "$MODULES/$KVER" \ + "$MODULE_DEST/" + + # Generate module dependency metadata. + depmod -b "$ROOT" "$KVER" + + # d-i loads /preseed.cfg from the initrd before anything else runs. + install -m 0644 "$PRESEED" "$ROOT/preseed.cfg" + + # Rebuild the installer initrd, with everything owned by root whoever + # owns it on disk (e.g. a checkout owned by a non-root user). xz rather + # than d-i's gzip, to shrink the initrd GRUB has to load. The kernel + # finds the format from the data, so the file keeps its initrd.gz name + # (which grub.cfg uses); its xz decompressor needs --check=crc32. One + # thread, so xz compresses everything as one block. + echo " Repacking" + # The device nodes go in a second cpio archive after the first, which + # has created dev/: the kernel unpacks concatenated archives in turn. + ( + cd "$ROOT" + + { + find . -print0 | + cpio --null -o -H newc --quiet -R 0:0 + + if [ -s "$NODES" ]; then + while read -r NAME MODE MAJOR MINOR; do + newc_entry "$NAME" "$MODE" 1 "$MAJOR" "$MINOR" + done < "$NODES" + newc_entry TRAILER!!! 0 1 0 0 + fi + } | xz -9 --check=crc32 --threads=1 + ) > "$INITRD.new" + + mv "$INITRD.new" "$INITRD" + + # Replace the kernel used by this installer entry. + cp "$VMLINUX" "$DIR/vmlinuz" + + COUNT=$((COUNT + 1)) +done + +echo +echo "Replaced $COUNT installer kernel/initrd pair(s)" +echo "Kernel release: $KVER" diff --git a/installer/live-build/kernel/lib/trim-modules.sh b/installer/live-build/kernel/lib/trim-modules.sh new file mode 100755 index 00000000..a861d29b --- /dev/null +++ b/installer/live-build/kernel/lib/trim-modules.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build/kernel/lib/trim-modules.sh MODULE_DIR RULES... +# +# Deletes the kernel modules the installer doesn't need from MODULE_DIR (a +# lib/modules/$KVER tree with its modules.dep), to keep the installer initrds +# small: GRUB reads them through the firmware, which is slow. +# +# Each RULES file has one shell glob per line, matched against the module's +# path relative to MODULE_DIR/kernel/ ("*" also matches "/"). A plain glob +# drops the matching modules, a "!" prefix keeps them again, and the last +# matching line wins, like .gitignore. Blank lines and "#" comments are +# ignored. Every module that a kept module depends on is also kept, so +# rules can drop whole subsystems without breaking what's left. +# +# Doesn't regenerate modules.dep etc.: run depmod afterwards. +set -euo pipefail + +MODULE_DIR=${1:?Usage: $0 MODULE_DIR RULES...} +shift + +RULES=() +for rules in "$@"; do + while IFS= read -r line || [ -n "$line" ]; do + line=${line%%#*} + line=${line//[[:space:]]/} + [ -n "$line" ] && RULES+=("$line") + done < "$rules" +done + +if [ ! -f "$MODULE_DIR/modules.dep" ]; then + echo "trim-modules: missing $MODULE_DIR/modules.dep" >&2 + exit 1 +fi + +# modules.dep lists each module's dependencies transitively, as paths +# relative to MODULE_DIR: "kernel/a.ko: kernel/b.ko kernel/c.ko". +declare -A DEPS KEEP +while IFS= read -r line; do + DEPS[${line%%:*}]=${line#*:} +done < "$MODULE_DIR/modules.dep" + +for mod in "${!DEPS[@]}"; do + keep=1 + for rule in "${RULES[@]}"; do + if [ "${rule#!}" != "$rule" ]; then + # shellcheck disable=SC2053 # the rule is a glob + [[ ${mod#kernel/} == ${rule#!} ]] && keep=1 + else + # shellcheck disable=SC2053 + [[ ${mod#kernel/} == $rule ]] && keep=0 + fi + done + [ "$keep" = 1 ] || continue + + KEEP[$mod]=1 + for dep in ${DEPS[$mod]}; do + KEEP[$dep]=1 + done +done + +dropped=0 +for mod in "${!DEPS[@]}"; do + [ -n "${KEEP[$mod]:-}" ] && continue + rm -f "${MODULE_DIR:?}/$mod" + dropped=$((dropped + 1)) +done + +# Directories left empty. +find "$MODULE_DIR/kernel" -mindepth 1 -type d -empty -delete + +echo "trim-modules: kept ${#KEEP[@]} modules, dropped $dropped" diff --git a/installer/live-build/kernel/package-lists/linux-base.list.binary b/installer/live-build/kernel/package-lists/linux-base.list.binary new file mode 100644 index 00000000..ee35dca9 --- /dev/null +++ b/installer/live-build/kernel/package-lists/linux-base.list.binary @@ -0,0 +1,6 @@ +# base-installer installs the kernel from the pool before apt-setup adds +# backports on the target, so the pool needs anything newer the kernel +# depends on. On trixie that's linux-base from trixie-backports (lb config +# --backports true in build-installer.sh), which +# archives/linux-base.pref.chroot pins. +linux-base From 0f731c8aaed9432a95d7de595160aa0b00a30bd8 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 04/15] installer: add what an offline install needs to the pool live-build's pool only holds the bootstrap packages and lb installer's short list, all without Recommends, so steps of the install that install more packages into the target fail without a network. Add the packages d-i installs itself, and tasksel's standard task, so a standard system can be installed offline. Signed-off-by: Christopher Obbard --- installer/build-installer.sh | 4 +++ .../package-lists/installer-pool.list.binary | 32 +++++++++++++++++++ .../package-lists/standard-task.list.binary | 5 +++ 3 files changed, 41 insertions(+) create mode 100644 installer/live-build/defaults/package-lists/installer-pool.list.binary create mode 100644 installer/live-build/defaults/package-lists/standard-task.list.binary diff --git a/installer/build-installer.sh b/installer/build-installer.sh index f8ad6b3e..f58cf99f 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -145,6 +145,10 @@ overlay() { # Installer defaults: the pool, the udebs and the tasks. overlay defaults/hooks/0060-prune-pool.hook.binary \ config/hooks/normal/0060-prune-pool.hook.binary +overlay defaults/package-lists/installer-pool.list.binary \ + config/package-lists/installer-pool.list.binary +overlay defaults/package-lists/standard-task.list.binary \ + config/package-lists/standard-task.list.binary # The custom kernel, in the installer and the pool. overlay kernel/package-lists/linux-base.list.binary \ diff --git a/installer/live-build/defaults/package-lists/installer-pool.list.binary b/installer/live-build/defaults/package-lists/installer-pool.list.binary new file mode 100644 index 00000000..48f5f00f --- /dev/null +++ b/installer/live-build/defaults/package-lists/installer-pool.list.binary @@ -0,0 +1,32 @@ +# Extra .debs for the ISO's pool (binary/pool), not installed into the chroot. +# +# live-build downloads grub/shim for d-i without Recommends, but d-i's +# apt-install installs them, so grub-installer also wants os-prober +# (Recommended by grub-efi-*). Without it on the ISO, installing GRUB falls +# back to the network and fails offline. +os-prober + +# cdrom installer: unlike a debian-cd ISO, live-build's pool only holds the +# bootstrap debs and lb installer's own short list (the kernel, GRUB, shim, +# busybox, lvm2 etc.), all without Recommends. Everything else d-i installs +# into the target itself must be listed here, or that step fails offline: +# +# - zstd: base-installer, to compress the initramfs +# - initramfs-tools: base-installer's initramfs generator. On trixie the +# kernel's dependencies already bring it, but on forky they're +# "dracut | initramfs-tools | linux-initramfs-tool", so only dracut lands +# in the pool +# - locales: localechooser, to set up the chosen locale +# - tasksel, popularity-contest, installation-report: pkgsel +# - task-ssh-server: tasksel only offers a task whose Key: package is +# available, so without it "SSH server" is missing offline +# - the packages of tasksel's "standard system utilities" task (every +# Priority: standard package): see standard-task.list.binary +# +zstd +initramfs-tools +locales +tasksel +popularity-contest +installation-report +task-ssh-server diff --git a/installer/live-build/defaults/package-lists/standard-task.list.binary b/installer/live-build/defaults/package-lists/standard-task.list.binary new file mode 100644 index 00000000..9300038d --- /dev/null +++ b/installer/live-build/defaults/package-lists/standard-task.list.binary @@ -0,0 +1,5 @@ +# tasksel's "standard system utilities" task (every package of Priority: +# standard) for the ISO's pool, so pkgsel installs all of it offline (see +# installer-pool.list.binary). A separate list, to keep the "!" line +# apart from the package names. +! grep-aptavail -n -s Package -F Priority -X standard From 290aed97ce9b0f69c9ff36dcb73c9bab4733c61a Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 05/15] installer: add the SoC and wifi firmware to the pool The target needs the device firmware to bring up storage, display, DSPs and wifi. Add the firmware packages to the pool and install them on the target, and enable non-free-firmware there. Stop lb installer from adding every package that ships firmware to the pool, which pulls in many unrelated packages, and move the firmware from the pool's non-free component, where live-build files it, to non-free-firmware, which the image's Release lists. On trixie, take the firmware from trixie-backports, as trixie's is too old for newer kernels. Signed-off-by: Christopher Obbard --- installer/build-installer.sh | 49 +++++++++++ .../defaults/preseed/non-free-firmware.cfg | 2 + .../firmware/archives/firmware.pref.chroot | 8 ++ .../hooks/0040-non-free-firmware.hook.binary | 87 +++++++++++++++++++ .../package-lists/firmware.list.binary | 7 ++ 5 files changed, 153 insertions(+) create mode 100644 installer/live-build/defaults/preseed/non-free-firmware.cfg create mode 100644 installer/live-build/firmware/archives/firmware.pref.chroot create mode 100755 installer/live-build/firmware/hooks/0040-non-free-firmware.hook.binary create mode 100644 installer/live-build/firmware/package-lists/firmware.list.binary diff --git a/installer/build-installer.sh b/installer/build-installer.sh index f58cf99f..235d53d0 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -95,6 +95,20 @@ KERNEL_ARGS="$(grep -v '^#' "$INSTALLER_DIR/live-build/kernel/kernel-cmdline" | # The bootstrap is still cached, in the build tree: installer_debian-installer # reuses its packages from cache/packages.bootstrap/ and fails without them. # +# Don't let lb installer add firmware packages to the pool (and /firmware/): +# by default it adds every package in the archive's Contents that ships +# anything under /usr/lib/firmware, e.g. indi-dsi (for one .hex file), which +# drags in libindi, libnova, cfitsio, fftw3, theora etc., plus +# firmware-linux-free, ath9k-htc, carl9170 etc. None of it is for this +# hardware: the SoC and wifi firmware packages are listed in +# firmware/package-lists/firmware.list.binary instead. +# +# List non-free-firmware in the archive areas: the chroot's apt downloads +# them from it, and apt on the target skips any component the ISO's Release +# doesn't list, which only has the parent archive areas' components. (lb +# files them under non-free; firmware/hooks/0040-non-free-firmware.hook.binary +# moves them back.) +# # Set the mirrors explicitly, and the parent mirrors too as lb saves them # separately and doesn't rederive them. Keep the trailing slashes: lb appends # "dists" to the debian-installer mirror directly. @@ -125,10 +139,13 @@ lb config \ "${BACKPORTS_ARGS[@]}" \ --distribution "$SUITE" \ --architectures "$ARCH" \ + --archive-areas "main non-free-firmware" \ + --parent-archive-areas "main non-free-firmware" \ --linux-packages none \ --debian-installer cdrom \ --debian-installer-distribution "$SUITE" \ --debian-installer-gui true \ + --firmware-binary false \ --cache-stages "bootstrap" \ --binary-images iso-hybrid \ --bootappend-install "$KERNEL_ARGS" @@ -160,6 +177,15 @@ if [ "$SUITE" = "trixie" ]; then config/archives/linux-base.pref.chroot fi +# The firmware, in the pool for the target (see POOL_INCLUDE below). +overlay firmware/package-lists/firmware.list.binary \ + config/package-lists/firmware.list.binary +overlay firmware/hooks/0040-non-free-firmware.hook.binary \ + config/hooks/normal/0040-non-free-firmware.hook.binary +if [ "$SUITE" = "trixie" ]; then + overlay firmware/archives/firmware.pref.chroot \ + config/archives/firmware.pref.chroot +fi overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include # live-build's config/preseed/ only ends up as /install/preseed.cfg on the @@ -170,6 +196,7 @@ overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include # which can't mknod in a container.) PRESEED="$BUILD_DIR/config/installer-preseed.cfg" cat "$INSTALLER_DIR/live-build/defaults/preseed/no-kernel-modules.cfg" \ + "$INSTALLER_DIR/live-build/defaults/preseed/non-free-firmware.cfg" \ > "$PRESEED" stage "Prepare installer" @@ -185,6 +212,23 @@ POOL_NAME="${KERNEL_PACKAGE}_${KERNEL_VERSION#*:}_$(dpkg-deb -f "$KERNEL_DEB" Ar install -D -m 0644 "$KERNEL_DEB" "$BUILD_DIR/config/packages.binary/$POOL_NAME" echo "$POOL_NAME" > "$BUILD_DIR/config/kernel-debs.list" +# Packages from the pool for pkgsel to install on the target, on top of +# the base system and the standard task. +POOL_INCLUDE=() + +# Add the packages of a list in config/package-lists/ to POOL_INCLUDE, so +# they're only listed once. Comments are dropped. +pool_include() { + local pkgs + mapfile -t pkgs < <(sed 's/#.*//' "$BUILD_DIR/config/package-lists/$1" | + xargs -r -n1) + POOL_INCLUDE+=("${pkgs[@]}") +} + +# The firmware, which lb binary adds to the pool's non-free-firmware +# component. lb installer adds none of it (see the lb config call above). +pool_include firmware.list.binary + stage "Build bootstrap and chroot" lb bootstrap @@ -217,6 +261,11 @@ d-i base-installer/kernel/image string $KERNEL_PACKAGE # The kernel arguments for the target's boot entries. d-i debian-installer/add-kernel-opts string $KERNEL_ARGS EOF +# pkgsel/include is a single setting, so list all of the packages at once. +cat >> "$PRESEED" </dev/null 2>&1; then + echo "0040-non-free-firmware: apt-ftparchive not found (install apt-utils)" >&2 + exit 1 +fi + +shopt -s nullglob + +echo "Moving pool/non-free/ to pool/non-free-firmware/" +for src_dir in pool/non-free/*/*/; do + src_dir="${src_dir%/}" + dest_dir="pool/non-free-firmware/${src_dir#pool/non-free/}" + mkdir -p "$dest_dir" + mv "$src_dir"/* "$dest_dir/" +done +rm -rf pool/non-free + +for dist_dir in dists/*/; do + dist_dir="${dist_dir%/}" + release="$dist_dir/Release" + + [ -d "$dist_dir/non-free" ] || continue + # e.g. a stable -> trixie symlink + [ -L "$dist_dir" ] && continue + + for index_dir in "$dist_dir"/non-free/binary-*; do + index_dir="$dist_dir/non-free-firmware/${index_dir##*/}" + mkdir -p "$index_dir" + + echo "Regenerating $index_dir/Packages" + apt-ftparchive packages pool/non-free-firmware > "$index_dir/Packages" + if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then + touch -d "@$SOURCE_DATE_EPOCH" "$index_dir/Packages" + fi + gzip -9 -n -c "$index_dir/Packages" > "$index_dir/Packages.gz" + done + rm -rf "$dist_dir/non-free" + + [ -f "$release" ] || continue + + # Keep binary_package-lists' header fields, and write the new Release + # outside the dist so it doesn't hash itself. + field() { + sed -n "s/^$1: //p" "$release" + } + + echo "Regenerating $release" + new_release=$(mktemp) + apt-ftparchive \ + -o APT::FTPArchive::Release::Origin="$(field Origin)" \ + -o APT::FTPArchive::Release::Label="$(field Label)" \ + -o APT::FTPArchive::Release::Suite="$(field Suite)" \ + -o APT::FTPArchive::Release::Version="$(field Version)" \ + -o APT::FTPArchive::Release::Codename="$(field Codename)" \ + -o APT::FTPArchive::Release::Date="$(field Date)" \ + -o APT::FTPArchive::Release::Architectures="$(field Architectures)" \ + -o APT::FTPArchive::Release::Components="$(field Components)" \ + -o APT::FTPArchive::Release::Description="$(field Description)" \ + release "$dist_dir" > "$new_release" + rm -f "$release" + mv "$new_release" "$release" + chmod 0644 "$release" + if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then + touch -d "@$SOURCE_DATE_EPOCH" "$release" + fi +done diff --git a/installer/live-build/firmware/package-lists/firmware.list.binary b/installer/live-build/firmware/package-lists/firmware.list.binary new file mode 100644 index 00000000..76ec145f --- /dev/null +++ b/installer/live-build/firmware/package-lists/firmware.list.binary @@ -0,0 +1,7 @@ +# Firmware to download into the pool; hooks/0040-non-free-firmware.hook.binary +# files them under the non-free-firmware component. build-installer.sh reads +# this list for pkgsel to install them on the target. + +firmware-atheros +firmware-qcom-soc +firmware-qcom-dsp From 95ae0032b613575e4616f781189be498a03d8ac1 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 06/15] installer: boot the image and the target through dtb-loader The device's firmware doesn't provide a usable device tree, so the kernel can't boot from GRUB on its own. Wrap the installer kernel with Stubble, bundling the DTBs from the kernel package that have a Stubble HWID entry, so that the right device tree is loaded for the machine. The installed system needs the same handling, but no package ships the files it needs. Run a post-install step from d-i's late_command, which sources the postinst.d parts from the image in the target, and add a part that installs the dtb-loader kernel hooks there, from the rootfs overlay in debos-recipes/overlays/ so the images and the installer agree. Install stubble and systemd-boot-efi from the pool for them. Signed-off-by: Christopher Obbard --- installer/build-installer.sh | 41 +++++- .../dtb-loader/dtb-loader.postinst.sh | 22 ++++ .../hooks/0100-dtb-loader.hook.binary | 118 ++++++++++++++++++ .../package-lists/dtb-loader.list.binary | 10 ++ .../hooks/0050-replace-di-kernel.hook.binary | 3 +- installer/live-build/postinst/postinst.sh | 48 +++++++ .../live-build/postinst/preseed/postinst.cfg | 6 + 7 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 installer/live-build/dtb-loader/dtb-loader.postinst.sh create mode 100755 installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary create mode 100644 installer/live-build/dtb-loader/package-lists/dtb-loader.list.binary create mode 100755 installer/live-build/postinst/postinst.sh create mode 100644 installer/live-build/postinst/preseed/postinst.cfg diff --git a/installer/build-installer.sh b/installer/build-installer.sh index 235d53d0..3bc76691 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -122,7 +122,8 @@ MIRROR_ARGS+=(--mirror-chroot-security "$MIRROR_SECURITY" --parent-mirror-chroot-security "$MIRROR_SECURITY") # Only stable suites have backports. On trixie, the pool needs some -# packages from them: see the package lists of the kernel topic. +# packages from them: see the package lists of the kernel and dtb-loader +# topics. BACKPORTS_ARGS=() if [ "$SUITE" = "trixie" ]; then BACKPORTS_ARGS=(--backports true) @@ -188,6 +189,17 @@ if [ "$SUITE" = "trixie" ]; then fi overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include +# The target's post-install step, which runs the postinst.d parts. +overlay postinst/postinst.sh config/includes.binary/qli/postinst.sh + +# The DTB loader, on the stick and on the target. +overlay dtb-loader/package-lists/dtb-loader.list.binary \ + config/package-lists/dtb-loader.list.binary +overlay dtb-loader/hooks/0100-dtb-loader.hook.binary \ + config/hooks/normal/0100-dtb-loader.hook.binary +overlay dtb-loader/dtb-loader.postinst.sh \ + config/includes.binary/qli/postinst.d/dtb-loader.postinst.sh + # live-build's config/preseed/ only ends up as /install/preseed.cfg on the # image, which d-i ignores without a file= boot argument. So # replace-di-kernel.sh puts the preseed in the initrd as /preseed.cfg @@ -197,8 +209,16 @@ overlay defaults/cdrom_udeb_include config/debian-cd/cdrom_udeb_include PRESEED="$BUILD_DIR/config/installer-preseed.cfg" cat "$INSTALLER_DIR/live-build/defaults/preseed/no-kernel-modules.cfg" \ "$INSTALLER_DIR/live-build/defaults/preseed/non-free-firmware.cfg" \ + "$INSTALLER_DIR/live-build/postinst/preseed/postinst.cfg" \ > "$PRESEED" +# The postinst.d parts install files no package ships from the dtb-loader +# rootfs overlay, so ship it on the image as /qli/overlays/dtb-loader/, laid +# out like the target filesystem. +mkdir -p "$BUILD_DIR/config/includes.binary/qli/overlays/dtb-loader" +cp -a "$INSTALLER_DIR/../debos-recipes/overlays/dtb-loader/." \ + "$BUILD_DIR/config/includes.binary/qli/overlays/dtb-loader/" + stage "Prepare installer" # Add the custom kernel to the pool, so base-installer installs it on the @@ -229,6 +249,9 @@ pool_include() { # component. lb installer adds none of it (see the lb config call above). pool_include firmware.list.binary +# The DTB loader, which lb binary adds to the pool with its dependencies. +pool_include dtb-loader.list.binary + stage "Build bootstrap and chroot" lb bootstrap @@ -274,6 +297,22 @@ EOF printf 'KERNEL_DIR=%q\n' "$KERNEL_DIR" } > "$BUILD_DIR/config/replace-di-kernel.conf" +stage "Extract DTBs" + +# All of the kernel's DTBs, not just the ones the ISO ships: the +# 0100-dtb-loader binary hook bundles only those with a Stubble HWID +# entry into the Stubble EFI binary. The rest stay in config/. +mkdir -p "$BUILD_DIR/config/dtbs" + +# The kernel package ships them in /usr/lib/linux-image-$KVER/. +find "$KERNEL_DIR/usr/lib/linux-image-$KVER" -name '*.dtb' -type f \ + -exec cp -t "$BUILD_DIR/config/dtbs/" {} + + +if ! compgen -G "$BUILD_DIR/config/dtbs/*.dtb" >/dev/null; then + echo "Kernel package contains no DTBs" >&2 + exit 1 +fi + # live-build only ships udeb_include lists for amd64, and binary_disk fails # for cdrom when ${ARCH}_udeb_include is missing. It leaves an existing # binary/.disk/udeb_include alone, so pre-seed ours from the overlay. diff --git a/installer/live-build/dtb-loader/dtb-loader.postinst.sh b/installer/live-build/dtb-loader/dtb-loader.postinst.sh new file mode 100644 index 00000000..0ac397d6 --- /dev/null +++ b/installer/live-build/dtb-loader/dtb-loader.postinst.sh @@ -0,0 +1,22 @@ +# shellcheck shell=sh disable=SC2154 # TARGET, SRC: set by postinst.sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Sourced by postinst.sh. Installs the Stubble files: a kernel hook that +# wraps each kernel in Stubble (bundling the kernel's DTBs), so GRUB's +# stock entries boot it, and the kernel-install variant of it (unused by +# GRUB, but there for a switch to systemd-boot). + +install_overlay_file dtb-loader etc/kernel/postinst.d/50-stubble 0755 +install_overlay_file dtb-loader etc/kernel/install.d/95-dtb-loader.install 0755 + +# The kernel was installed before the Stubble hook, so wrap it now; the +# hook wraps later kernels. It wraps them in place, so grub.cfg needs no +# update. +for image in "$TARGET"/boot/vmlinuz-*; do + [ -f "$image" ] || continue + version=${image##*/vmlinuz-} + log "wrapping /boot/vmlinuz-$version in Stubble" + chroot "$TARGET" /etc/kernel/postinst.d/50-stubble "$version" \ + "/boot/vmlinuz-$version" +done diff --git a/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary b/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary new file mode 100755 index 00000000..76367c47 --- /dev/null +++ b/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary @@ -0,0 +1,118 @@ +#!/bin/bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build binary-stage hook (config/hooks/normal/*.binary). +# +# Runs non-chrooted, cwd=binary/, after binary_grub_cfg but before binary_iso. +# Uses the DTBs that build-installer.sh extracts from the kernel .deb into +# config/dtbs/, the AArch64 systemd-stub from the systemd-boot-efi arm64 +# package in the pool (dtb-loader.list.binary), and stubblify and the HWID +# database from the build host's stubble package. +# +# Wraps the installer kernel (install/vmlinuz) in place in a DTB-loading EFI +# stub bundling every DTB that has a Stubble HWID entry, selected automatically at +# boot via HWID matching. +# +# The graphical and text installers only differ in their initrd and args: +# replace-di-kernel.sh puts the same kernel in install/vmlinuz and +# install/gtk/vmlinuz. So install/vmlinuz is wrapped, and the wrapped kernel +# copied over install/gtk/vmlinuz. +set -euo pipefail + +DTB_SRC_DIR="../config/dtbs" +HWIDS="/usr/share/stubble/hwids" +STUBBLIFY="/usr/bin/stubblify" +FINDDTBS="/usr/libexec/stubble/finddtbs.py" + +die() { + echo "0100-dtb-loader: $*" >&2 + exit 1 +} + +# Extracts the given file from the pool's only package matching the given +# glob to stdout. +extract_from_pool() { + local glob="$1" file="$2" debs + + mapfile -t debs < <(compgen -G "$glob" || true) + [ "${#debs[@]}" -eq 1 ] || + die "expected exactly one $glob, found: ${debs[*]}" + dpkg-deb --fsys-tarfile "${debs[0]}" | tar -xO "$file" +} + +# The AArch64 stub, from the target's package in the pool: the host +# package's stub matches the build host's architecture, not the target's. +extract_from_pool "pool/*/*/*/systemd-boot-efi_*_arm64.deb" \ + ./usr/lib/systemd/boot/efi/linuxaa64.efi.stub \ + > ../config/linuxaa64.efi.stub +STUB="../config/linuxaa64.efi.stub" + +[ -d "$DTB_SRC_DIR" ] || die "$DTB_SRC_DIR not found (build-installer.sh extracts it from the kernel .deb)" +for f in "$STUB" "$STUBBLIFY" "$FINDDTBS"; do + [ -e "$f" ] || die "$f not found" +done +[ -d "$HWIDS" ] || die "$HWIDS not found (install stubble)" + +# Only bundle DTBs whose root compatible has a Stubble HWID entry; the rest +# could never be selected. +mapfile -t STUBBLE_DTBS < <("$FINDDTBS" "$DTB_SRC_DIR" "$HWIDS" | sort) +[ "${#STUBBLE_DTBS[@]}" -gt 0 ] || die "no DTBs in $DTB_SRC_DIR match $HWIDS" + +echo "Stubble DTBs:" +printf ' %s\n' "${STUBBLE_DTBS[@]##*/}" + +BOOT_KERNEL="install/vmlinuz" +GTK_KERNEL="install/gtk/vmlinuz" +[ -f "$BOOT_KERNEL" ] || die "$BOOT_KERNEL not found" +if [ -f "$GTK_KERNEL" ] && ! cmp -s "$GTK_KERNEL" "$BOOT_KERNEL"; then + die "$GTK_KERNEL differs from $BOOT_KERNEL, so can't be replaced" +fi + +DTB_ARGS=() +for dtb in "${STUBBLE_DTBS[@]}"; do + DTB_ARGS+=("--devicetree-auto=$dtb") +done + +KERNEL_TMP="" +trap 'rm -f "$KERNEL_TMP"' EXIT HUP INT TERM + +# Wraps the given kernel in place, as the dtb-loader overlay's kernel hook +# does. It's not a full UKI, as the empty --os-release suppresses the .osrel +# section and there is no --initrd or --cmdline, so it stays an ordinary +# kernel image for GRUB. It's built beside the kernel and moved over it, so +# a failure leaves the original in place. +dtb_loader_wrap() { + local kernel="$1" + + # Wrapping an already wrapped image would nest a second stub, and a + # real UKI (.osrel) is not ours to post-process. + if "$STUBBLIFY" inspect "$kernel" 2>/dev/null | + grep -Eq '^\.(hwids|osrel):'; then + die "wrapper already present on $kernel" + fi + + echo "DTB loader: $kernel" + + KERNEL_TMP="$kernel.dtb-loader.tmp" + "$STUBBLIFY" build \ + --efi-arch=aa64 \ + --stub="$STUB" \ + --linux="$kernel" \ + --os-release= \ + --hwids="$HWIDS" \ + "${DTB_ARGS[@]}" \ + --output="$KERNEL_TMP" + + # stubblify creates it 0600; keep the kernel's mode. + chmod --reference="$kernel" "$KERNEL_TMP" + mv "$KERNEL_TMP" "$kernel" + KERNEL_TMP="" +} + +dtb_loader_wrap "$BOOT_KERNEL" + +# The graphical installer's entries boot the same wrapped kernel. +[ ! -f "$GTK_KERNEL" ] || cp -p "$BOOT_KERNEL" "$GTK_KERNEL" + +echo "0100-dtb-loader: done" diff --git a/installer/live-build/dtb-loader/package-lists/dtb-loader.list.binary b/installer/live-build/dtb-loader/package-lists/dtb-loader.list.binary new file mode 100644 index 00000000..dd935b6e --- /dev/null +++ b/installer/live-build/dtb-loader/package-lists/dtb-loader.list.binary @@ -0,0 +1,10 @@ +# The target builds a Stubble image per kernel, as the device's firmware +# provides no DTB: see dtb-loader.postinst.sh. Its kernel hook prefers +# systemd-boot-efi's systemd-stub to Stubble's own stub, so install that +# too. live-build adds their dependencies to the pool, and build-installer.sh +# reads this list for pkgsel to install them on the target. On trixie, +# stubble is only in trixie-backports (lb config --backports true in +# build-installer.sh). The 0100-dtb-loader binary hook also takes the +# AArch64 systemd-stub from systemd-boot-efi. +stubble +systemd-boot-efi diff --git a/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary b/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary index 7edcaa2f..9833ec16 100755 --- a/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary +++ b/installer/live-build/kernel/hooks/0050-replace-di-kernel.hook.binary @@ -6,7 +6,8 @@ # # Runs non-chrooted, cwd=binary/, after lb binary's binary_package-lists has # added the packages of *.list.binary to the pool, and before -# 0060-prune-pool.hook.binary and the GRUB hooks. +# 0060-prune-pool.hook.binary, the GRUB hooks and 0100-dtb-loader.hook.binary, +# which wraps the kernel this puts in install/. # # Replaces the kernel in the installer's initrds with the custom one, which # build-installer.sh unpacks to $KERNEL_DIR, using lib/replace-di-kernel.sh. diff --git a/installer/live-build/postinst/postinst.sh b/installer/live-build/postinst/postinst.sh new file mode 100755 index 00000000..4db3b3fc --- /dev/null +++ b/installer/live-build/postinst/postinst.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Run by d-i's preseed/late_command, after GRUB is installed, to get the +# installed system booting on Qualcomm devices. Everything else comes +# natively from d-i and the pool; the parts in postinst.d/ only install the +# files from the ISO's /qli/ that no package ships, then rebuild what +# depends on them. +# +# The parts are sourced, so they share log(), install_file(), +# install_overlay_file() and set -e, and need no exec bit. They run in +# lexical order, but must not depend on each other. +set -e + +TARGET=${1:-/target} +SRC=/cdrom/qli + +log() { + echo "postinst: $*" + logger -t postinst "$*" 2>/dev/null || true +} + +# Copy to /target/ with ; busybox has no install. +install_file() { + if [ ! -f "$1" ]; then + log "missing $1" + exit 1 + fi + + log "installing $2" + mkdir -p "$(dirname "$TARGET$2")" + cp "$1" "$TARGET$2" + chmod "$3" "$TARGET$2" +} + +# Install / with from the rootfs overlay , which +# build-installer.sh ships as overlays//, laid out like the target. +install_overlay_file() { + install_file "$SRC/overlays/$1/$2" "/$2" "$3" +} + +for part in "$SRC"/postinst.d/*; do + [ -f "$part" ] || continue + log "running ${part##*/}" + # shellcheck source=/dev/null + . "$part" +done diff --git a/installer/live-build/postinst/preseed/postinst.cfg b/installer/live-build/postinst/preseed/postinst.cfg new file mode 100644 index 00000000..28ba97d3 --- /dev/null +++ b/installer/live-build/postinst/preseed/postinst.cfg @@ -0,0 +1,6 @@ +# Install the Stubble kernel hooks from the ISO's /qli/, which no package +# ships, and wrap the target's kernel in Stubble: see +# live-build/postinst/postinst.sh. late_command runs after GRUB is +# installed, while the ISO is still mounted at /cdrom. Packaging these +# files would make it unnecessary. +d-i preseed/late_command string sh /cdrom/qli/postinst.sh /target From dc2e35986284a38eb6632ce34f6adb97cab9fe40 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 07/15] installer: offer a network mirror on the target Installing from the pool alone leaves the target without an APT mirror, so it can't install updates or more packages. Offer a network mirror (and backports on stable suites) in the installer, which needs apt-mirror-setup that live-build's udeb_exclude would otherwise drop. Also skip the root login and swap questions, which don't make sense for these machines, and add sudo to the pool for the first user. Signed-off-by: Christopher Obbard --- installer/build-installer.sh | 22 +++++++++++++ .../package-lists/installer-pool.list.binary | 5 +++ .../live-build/defaults/preseed/backports.cfg | 3 ++ .../defaults/preseed/network-mirror.cfg | 33 +++++++++++++++++++ .../defaults/preseed/no-root-login.cfg | 8 +++++ .../defaults/preseed/no-swap-prompt.cfg | 5 +++ 6 files changed, 76 insertions(+) create mode 100644 installer/live-build/defaults/preseed/backports.cfg create mode 100644 installer/live-build/defaults/preseed/network-mirror.cfg create mode 100644 installer/live-build/defaults/preseed/no-root-login.cfg create mode 100644 installer/live-build/defaults/preseed/no-swap-prompt.cfg diff --git a/installer/build-installer.sh b/installer/build-installer.sh index 3bc76691..e225cba6 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -208,10 +208,18 @@ overlay dtb-loader/dtb-loader.postinst.sh \ # which can't mknod in a container.) PRESEED="$BUILD_DIR/config/installer-preseed.cfg" cat "$INSTALLER_DIR/live-build/defaults/preseed/no-kernel-modules.cfg" \ + "$INSTALLER_DIR/live-build/defaults/preseed/network-mirror.cfg" \ + "$INSTALLER_DIR/live-build/defaults/preseed/no-root-login.cfg" \ + "$INSTALLER_DIR/live-build/defaults/preseed/no-swap-prompt.cfg" \ "$INSTALLER_DIR/live-build/defaults/preseed/non-free-firmware.cfg" \ "$INSTALLER_DIR/live-build/postinst/preseed/postinst.cfg" \ > "$PRESEED" +# Only stable suites have backports. +if [ "$SUITE" = "trixie" ]; then + cat "$INSTALLER_DIR/live-build/defaults/preseed/backports.cfg" >> "$PRESEED" +fi + # The postinst.d parts install files no package ships from the dtb-loader # rootfs overlay, so ship it on the image as /qli/overlays/dtb-loader/, laid # out like the target filesystem. @@ -221,6 +229,20 @@ cp -a "$INSTALLER_DIR/../debos-recipes/overlays/dtb-loader/." \ stage "Prepare installer" +# live-build's udeb_exclude (copied from debian-cd) drops +# apt-mirror-setup, which asks "use a network mirror?", so the installer +# never sets up a mirror and tasksel only sees the ISO's pool. lb installer +# only builds its exclude list when ./exclude doesn't exist yet (and removes +# it afterwards), and config/debian-installer/udeb_exclude can only add to +# it. So pre-seed the same list without apt-mirror-setup. +LB_UDEB_DATA="/usr/share/live/build/data/debian-cd/$SUITE" +if [ -d "$LB_UDEB_DATA" ]; then + cat "$LB_UDEB_DATA/udeb_exclude" \ + "$LB_UDEB_DATA/exclude-udebs" \ + "$LB_UDEB_DATA/exclude-udebs-$ARCH" 2>/dev/null | + grep -v -e '^#' -e '^apt-mirror-setup$' > exclude || true +fi + # Add the custom kernel to the pool, so base-installer installs it on the # target instead of the stock one. lb installer copies the debs in # config/packages.binary/ into the pool. They're named as apt would name them, diff --git a/installer/live-build/defaults/package-lists/installer-pool.list.binary b/installer/live-build/defaults/package-lists/installer-pool.list.binary index 48f5f00f..8dcae7d8 100644 --- a/installer/live-build/defaults/package-lists/installer-pool.list.binary +++ b/installer/live-build/defaults/package-lists/installer-pool.list.binary @@ -20,6 +20,10 @@ os-prober # - tasksel, popularity-contest, installation-report: pkgsel # - task-ssh-server: tasksel only offers a task whose Key: package is # available, so without it "SSH server" is missing offline +# - sudo: user-setup, to give the first user sudo when the root account is +# disabled (no-root-login.cfg). It's Priority: optional, so it isn't in +# the standard task, and offline installs otherwise end up with root +# locked and no sudo # - the packages of tasksel's "standard system utilities" task (every # Priority: standard package): see standard-task.list.binary # @@ -30,3 +34,4 @@ tasksel popularity-contest installation-report task-ssh-server +sudo diff --git a/installer/live-build/defaults/preseed/backports.cfg b/installer/live-build/defaults/preseed/backports.cfg new file mode 100644 index 00000000..6a7b99e2 --- /dev/null +++ b/installer/live-build/defaults/preseed/backports.cfg @@ -0,0 +1,3 @@ +# Add backports on the target, for the hardware enablement packages. Only +# stable suites have backports, so build-installer.sh only adds this on trixie. +d-i apt-setup/services-select multiselect security, updates, backports diff --git a/installer/live-build/defaults/preseed/network-mirror.cfg b/installer/live-build/defaults/preseed/network-mirror.cfg new file mode 100644 index 00000000..f1cccabf --- /dev/null +++ b/installer/live-build/defaults/preseed/network-mirror.cfg @@ -0,0 +1,33 @@ +### Networking +# Prefer an interface with an active link, such as USB Ethernet, over a +# detected but unsupported Wi-Fi adapter. Allow extra time for USB network +# adapters to initialise before checking for a link. +d-i netcfg/choose_interface select auto +d-i netcfg/link_wait_timeout string 10 + +# If automatic network configuration fails, continue offline. +d-i netcfg/dhcp_failed note +d-i netcfg/dhcp_options select Do not configure the network at this time + +### Mirror +# Use the configured Debian mirror when networking is available. +d-i mirror/country string manual +d-i mirror/http/hostname string deb.debian.org +d-i mirror/http/directory string /debian +d-i mirror/http/proxy string + +# Use the network mirror for the installed system's apt sources, so the +# mirror, updates and backports entries are added, and tasksel can offer +# tasks whose packages are not on the ISO. +d-i apt-setup/use_mirror boolean true + +# netcfg/dhcp_options above stays set even when DHCP succeeds, and +# apt-setup takes it to mean there is no network: it skips the mirror and +# comments out security, updates and backports. Partitioning runs after +# netcfg and before apt-setup, so fix both up there: with a default route, +# clear dhcp_options; without one, turn the mirror off so choose-mirror +# doesn't stop at "Bad archive mirror". +d-i partman/early_command string if ip route show default | grep -q .; then debconf-set netcfg/dhcp_options ""; else debconf-set apt-setup/use_mirror false; fi + +# Allow installation to continue without a network mirror. +d-i apt-setup/no_mirror boolean true diff --git a/installer/live-build/defaults/preseed/no-root-login.cfg b/installer/live-build/defaults/preseed/no-root-login.cfg new file mode 100644 index 00000000..1c76c164 --- /dev/null +++ b/installer/live-build/defaults/preseed/no-root-login.cfg @@ -0,0 +1,8 @@ +# Skip the root password step: disable the root account and give the first +# user sudo instead, like Ubuntu. Users who leave the root password blank +# get this anyway, but many users set one without realising they then get +# no sudo, and are stuck unable to administer the system from their own +# account. +# user-setup installs sudo into the target, from the ISO's pool +# (installer-pool.list.binary) when there's no network. +d-i passwd/root-login boolean false diff --git a/installer/live-build/defaults/preseed/no-swap-prompt.cfg b/installer/live-build/defaults/preseed/no-swap-prompt.cfg new file mode 100644 index 00000000..d9ad229c --- /dev/null +++ b/installer/live-build/defaults/preseed/no-swap-prompt.cfg @@ -0,0 +1,5 @@ +# Don't stop to ask for confirmation when the partitioning has no swap. +# Guided partitioning on small disks, and manual layouts that leave swap +# out on purpose, otherwise hit a "no swap space" prompt that blocks an +# unattended install. Continue without swap instead. +d-i partman-basicfilesystems/no_swap boolean false From 3fc58fb59b61285dfac00f06a9ee5fea898294cd Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 08/15] installer: add a live GNOME system with Calamares Let the hardware be tried out before installing anything: build a live GNOME system from live-build's chroot, with the custom kernel and the firmware, and boot it by default from live-build's menu. Use the kernel's version as the flavour so the live entry finds it, pass it the kernel arguments too, and drop the fail-safe entry, which lacks them. Add Calamares to it to install the live system to disk, running the same post-install step as d-i does on the target. The installer stays the same, and installs from the pool as before. Also add GNOME's task to the pool and tick it by default in tasksel, so the target can get the same desktop offline. Signed-off-by: Christopher Obbard --- installer/build-installer.sh | 84 ++++++++++++++----- .../defaults/package-lists/gnome.list.binary | 3 + .../package-lists/installer-pool.list.binary | 4 + .../defaults/preseed/tasksel-gnome.cfg | 6 ++ .../hooks/0100-dtb-loader.hook.binary | 12 ++- .../firmware/archives/firmware.pref.chroot | 3 +- .../package-lists/firmware.list.binary | 3 +- .../kernel/archives/linux-base.pref.chroot | 3 +- installer/live-build/kernel/kernel-cmdline | 4 +- .../live/calamares/qli-postinst.conf | 13 +++ .../live/hooks/0050-initramfs.hook.chroot | 25 ++++++ .../live/hooks/0060-calamares.hook.chroot | 57 +++++++++++++ .../live/package-lists/calamares.list.binary | 5 ++ .../live/package-lists/calamares.list.chroot | 9 ++ .../live/package-lists/gnome.list.chroot | 4 + installer/live-build/postinst/postinst.sh | 6 +- 16 files changed, 211 insertions(+), 30 deletions(-) create mode 100644 installer/live-build/defaults/package-lists/gnome.list.binary create mode 100644 installer/live-build/defaults/preseed/tasksel-gnome.cfg create mode 100644 installer/live-build/live/calamares/qli-postinst.conf create mode 100755 installer/live-build/live/hooks/0050-initramfs.hook.chroot create mode 100755 installer/live-build/live/hooks/0060-calamares.hook.chroot create mode 100644 installer/live-build/live/package-lists/calamares.list.binary create mode 100644 installer/live-build/live/package-lists/calamares.list.chroot create mode 100644 installer/live-build/live/package-lists/gnome.list.chroot diff --git a/installer/build-installer.sh b/installer/build-installer.sh index e225cba6..7b006a7b 100755 --- a/installer/build-installer.sh +++ b/installer/build-installer.sh @@ -52,7 +52,8 @@ fi SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) INSTALLER_DIR=$SCRIPT_DIR -# The kernel's package and version. +# The kernel's package and version. The version is also the flavour, which +# makes live-build look for chroot/boot/vmlinuz-$KVER for the live system. KERNEL_PACKAGE=$(dpkg-deb -f "$KERNEL_DEB" Package) case "$KERNEL_PACKAGE" in linux-image-*) ;; @@ -89,12 +90,15 @@ stage "Configure live-build" # kernel/kernel-cmdline. KERNEL_ARGS="$(grep -v '^#' "$INSTALLER_DIR/live-build/kernel/kernel-cmdline" | xargs)" -# live-build's rootfs stages are skipped, as the installer installs from -# the pool (see "Skip live-build's rootfs stages" below). +# The image has a live GNOME system, from the chroot's filesystem.squashfs, +# and the installer, which installs the target from the pool. # -# The bootstrap is still cached, in the build tree: installer_debian-installer +# The bootstrap is cached, in the build tree: installer_debian-installer # reuses its packages from cache/packages.bootstrap/ and fails without them. # +# Use live-build's cdrom installer: its live installer would copy the live +# system to the target instead of installing from the pool. +# # Don't let lb installer add firmware packages to the pool (and /firmware/): # by default it adds every package in the archive's Contents that ships # anything under /usr/lib/firmware, e.g. indi-dsi (for one .hex file), which @@ -132,9 +136,10 @@ fi # Build an iso-hybrid image, which also boots from a USB stick. The kernel # needs ISO 9660 support, see kernel-configs/installer.config. # -# live-build's GRUB menu passes the kernel arguments to the installer: -# --bootappend-install ends up before the "---", so d-i doesn't give it to -# the target (the preseed's add-kernel-opts does). +# live-build's GRUB menu passes the kernel arguments to the installer and +# the live system: --bootappend-install ends up before the "---", so d-i +# doesn't give it to the target (the preseed's add-kernel-opts does), and +# the failsafe entry, which lacks them, is dropped. lb config \ "${MIRROR_ARGS[@]}" \ "${BACKPORTS_ARGS[@]}" \ @@ -147,9 +152,13 @@ lb config \ --debian-installer-distribution "$SUITE" \ --debian-installer-gui true \ --firmware-binary false \ + --chroot-filesystem squashfs \ --cache-stages "bootstrap" \ --binary-images iso-hybrid \ - --bootappend-install "$KERNEL_ARGS" + --linux-flavours "$KVER" \ + --bootappend-install "$KERNEL_ARGS" \ + --bootappend-live "boot=live components quiet splash $KERNEL_ARGS" \ + --bootappend-live-failsafe none # Copy tracked customizations from live-build/ on top of the generated # config/. @@ -178,11 +187,14 @@ if [ "$SUITE" = "trixie" ]; then config/archives/linux-base.pref.chroot fi -# The firmware, in the pool for the target (see POOL_INCLUDE below). +# The firmware, in the pool for the target (see POOL_INCLUDE below) and in +# the live system. overlay firmware/package-lists/firmware.list.binary \ config/package-lists/firmware.list.binary overlay firmware/hooks/0040-non-free-firmware.hook.binary \ config/hooks/normal/0040-non-free-firmware.hook.binary +overlay firmware/package-lists/firmware.list.binary \ + config/package-lists/firmware.list.chroot if [ "$SUITE" = "trixie" ]; then overlay firmware/archives/firmware.pref.chroot \ config/archives/firmware.pref.chroot @@ -200,6 +212,34 @@ overlay dtb-loader/hooks/0100-dtb-loader.hook.binary \ overlay dtb-loader/dtb-loader.postinst.sh \ config/includes.binary/qli/postinst.d/dtb-loader.postinst.sh +# GNOME, in the pool for the installer to offer and in the live system. +overlay defaults/package-lists/gnome.list.binary \ + config/package-lists/gnome.list.binary +overlay live/package-lists/gnome.list.chroot \ + config/package-lists/gnome.list.chroot +overlay live/hooks/0050-initramfs.hook.chroot \ + config/hooks/normal/0050-initramfs.hook.chroot + +# Calamares, in the live system, to install it to disk. +overlay live/package-lists/calamares.list.chroot \ + config/package-lists/calamares.list.chroot +overlay live/package-lists/calamares.list.binary \ + config/package-lists/calamares.list.binary +overlay live/hooks/0060-calamares.hook.chroot \ + config/hooks/normal/0060-calamares.hook.chroot +overlay live/calamares/qli-postinst.conf \ + config/includes.chroot/etc/calamares/modules/qli-postinst.conf + +# Calamares doesn't give the target the kernel arguments (d-i does, through +# add-kernel-opts below), so give the live system, and so the target, a GRUB +# snippet with them. +GRUB_D="$BUILD_DIR/config/includes.chroot/etc/default/grub.d" +mkdir -p "$GRUB_D" +cat > "$GRUB_D/qcom-deb-images.cfg" < "$PRESEED" @@ -249,9 +290,13 @@ fi # which lb installer's *_$ARCH.deb and *_all.deb globs rely on. The # 0060-prune-pool hook drops the stock kernel, keeping the debs listed # in config/kernel-debs.list. +# +# Also install the kernel in the live system: lb chroot installs every deb +# in config/packages.chroot/. KERNEL_VERSION=$(dpkg-deb -f "$KERNEL_DEB" Version) POOL_NAME="${KERNEL_PACKAGE}_${KERNEL_VERSION#*:}_$(dpkg-deb -f "$KERNEL_DEB" Architecture).deb" install -D -m 0644 "$KERNEL_DEB" "$BUILD_DIR/config/packages.binary/$POOL_NAME" +install -D -m 0644 "$KERNEL_DEB" "$BUILD_DIR/config/packages.chroot/$POOL_NAME" echo "$POOL_NAME" > "$BUILD_DIR/config/kernel-debs.list" # Packages from the pool for pkgsel to install on the target, on top of @@ -276,9 +321,17 @@ pool_include dtb-loader.list.binary stage "Build bootstrap and chroot" +# After the kernel is added: lb chroot installs config/packages.chroot/. lb bootstrap lb chroot +# --linux-packages none makes binary_linux-image skip the live system's +# kernel and initrd, so put them in binary/live/ via config/includes.binary/. +# The 0100-dtb-loader binary hook wraps the kernel with Stubble. +LIVE_BOOT="$BUILD_DIR/config/includes.binary/live" +mkdir -p "$LIVE_BOOT" +cp -L chroot/boot/vmlinuz-* chroot/boot/initrd.img-* "$LIVE_BOOT/" + stage "Build installer" lb installer @@ -341,19 +394,6 @@ fi install -D -m 0644 "$BUILD_DIR/config/debian-cd/cdrom_udeb_include" \ "$BUILD_DIR/binary/.disk/udeb_include" -# Skip live-build's rootfs stages. binary_chroot copies the chroot and -# binary_rootfs runs mksquashfs on it, then binary_manifest lists its -# packages. None of it is used: the image only boots the installer, and -# d-i installs from the pool. Marking the stages done leaves the chroot as -# binary_rootfs would, and nothing else needs them. ("--chroot-filesystem -# none" can't do this: it replaces the whole binary/ tree with the chroot, -# wiping the installer.) -mkdir -p "$BUILD_DIR/.build" -touch \ - "$BUILD_DIR/.build/binary_chroot" \ - "$BUILD_DIR/.build/binary_rootfs" \ - "$BUILD_DIR/.build/binary_manifest" - stage "Build image" lb binary diff --git a/installer/live-build/defaults/package-lists/gnome.list.binary b/installer/live-build/defaults/package-lists/gnome.list.binary new file mode 100644 index 00000000..26bf535f --- /dev/null +++ b/installer/live-build/defaults/package-lists/gnome.list.binary @@ -0,0 +1,3 @@ +# tasksel's GNOME task for the ISO's pool, so it can be installed offline +# (see defaults/package-lists/installer-pool.list.binary). +task-gnome-desktop diff --git a/installer/live-build/defaults/package-lists/installer-pool.list.binary b/installer/live-build/defaults/package-lists/installer-pool.list.binary index 8dcae7d8..476eac3f 100644 --- a/installer/live-build/defaults/package-lists/installer-pool.list.binary +++ b/installer/live-build/defaults/package-lists/installer-pool.list.binary @@ -20,6 +20,10 @@ os-prober # - tasksel, popularity-contest, installation-report: pkgsel # - task-ssh-server: tasksel only offers a task whose Key: package is # available, so without it "SSH server" is missing offline +# - task-gnome-desktop: likewise for "GNOME", which the installer ticks +# by default (tasksel-gnome.cfg); live-build adds the task's +# dependencies, so the desktop can be installed offline. It's in its own +# list (defaults/package-lists/gnome.list.binary) # - sudo: user-setup, to give the first user sudo when the root account is # disabled (no-root-login.cfg). It's Priority: optional, so it isn't in # the standard task, and offline installs otherwise end up with root diff --git a/installer/live-build/defaults/preseed/tasksel-gnome.cfg b/installer/live-build/defaults/preseed/tasksel-gnome.cfg new file mode 100644 index 00000000..33b6cf77 --- /dev/null +++ b/installer/live-build/defaults/preseed/tasksel-gnome.cfg @@ -0,0 +1,6 @@ +# Pick GNOME as the default desktop. +# tasksel defaults to Xfce on every arch but i386/amd64 (see +# default_desktop_for_arch in tasksel), as not all of them have 3D hardware. +# These devices do, so tick GNOME instead. This only changes which +# desktop is ticked: the task selection is still asked. +tasksel tasksel/desktop multiselect gnome diff --git a/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary b/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary index 76367c47..6ec2eb8d 100755 --- a/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary +++ b/installer/live-build/dtb-loader/hooks/0100-dtb-loader.hook.binary @@ -12,7 +12,9 @@ # # Wraps the installer kernel (install/vmlinuz) in place in a DTB-loading EFI # stub bundling every DTB that has a Stubble HWID entry, selected automatically at -# boot via HWID matching. +# boot via HWID matching. Also wraps the live system's kernel, which +# build-installer.sh puts in live/ (lb doesn't, with --linux-packages none), +# in the same stub, which live-build's GRUB menu boots. # # The graphical and text installers only differ in their initrd and args: # replace-di-kernel.sh puts the same kernel in install/vmlinuz and @@ -112,6 +114,14 @@ dtb_loader_wrap() { dtb_loader_wrap "$BOOT_KERNEL" +# The live system's kernel. build-installer.sh puts it in live/. +LIVE_KERNELS=(live/vmlinuz-*) +if [ "${#LIVE_KERNELS[@]}" -ne 1 ] || [ ! -f "${LIVE_KERNELS[0]}" ]; then + die "expected exactly one live/vmlinuz-*, found: ${LIVE_KERNELS[*]}" +fi + +dtb_loader_wrap "${LIVE_KERNELS[0]}" + # The graphical installer's entries boot the same wrapped kernel. [ ! -f "$GTK_KERNEL" ] || cp -p "$BOOT_KERNEL" "$GTK_KERNEL" diff --git a/installer/live-build/firmware/archives/firmware.pref.chroot b/installer/live-build/firmware/archives/firmware.pref.chroot index b9295e0f..09ac0300 100644 --- a/installer/live-build/firmware/archives/firmware.pref.chroot +++ b/installer/live-build/firmware/archives/firmware.pref.chroot @@ -2,7 +2,8 @@ # # Take the firmware from trixie-backports, which apt otherwise only uses when # asked (NotAutomatic). firmware-qcom-dsp is only in trixie-backports. This -# resolves them for the ISO's pool (package-lists/firmware.list.binary). +# resolves them for the ISO's pool (package-lists/firmware.list.binary) and +# for the live system (the same list, as firmware.list.chroot). Package: src:firmware-nonfree src:hexagon-dsp-binaries Pin: release n=trixie-backports Pin-Priority: 900 diff --git a/installer/live-build/firmware/package-lists/firmware.list.binary b/installer/live-build/firmware/package-lists/firmware.list.binary index 76ec145f..8eb93763 100644 --- a/installer/live-build/firmware/package-lists/firmware.list.binary +++ b/installer/live-build/firmware/package-lists/firmware.list.binary @@ -1,6 +1,7 @@ # Firmware to download into the pool; hooks/0040-non-free-firmware.hook.binary # files them under the non-free-firmware component. build-installer.sh reads -# this list for pkgsel to install them on the target. +# this list for pkgsel to install them on the target, and installs them in +# the live system as firmware.list.chroot. firmware-atheros firmware-qcom-soc diff --git a/installer/live-build/kernel/archives/linux-base.pref.chroot b/installer/live-build/kernel/archives/linux-base.pref.chroot index 2b5d7398..2e68aaf7 100644 --- a/installer/live-build/kernel/archives/linux-base.pref.chroot +++ b/installer/live-build/kernel/archives/linux-base.pref.chroot @@ -3,7 +3,8 @@ # The custom kernel depends on a newer linux-base than trixie's, so take # it from trixie-backports, which apt otherwise only uses when asked # (NotAutomatic). This resolves it for the ISO's pool -# (package-lists/linux-base.list.binary). +# (package-lists/linux-base.list.binary) and for the live system's kernel +# (lb chroot). Package: src:linux-base Pin: release n=trixie-backports Pin-Priority: 900 diff --git a/installer/live-build/kernel/kernel-cmdline b/installer/live-build/kernel/kernel-cmdline index 39dc7829..7403d5e5 100644 --- a/installer/live-build/kernel/kernel-cmdline +++ b/installer/live-build/kernel/kernel-cmdline @@ -1,8 +1,8 @@ # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. # SPDX-License-Identifier: BSD-3-Clause -# Extra kernel arguments for the installer's GRUB entries and, through -# d-i's add-kernel-opts, the target's. +# Extra kernel arguments for the installer's and the live system's GRUB +# entries and, through d-i's add-kernel-opts, the target's. # Read by build-installer.sh, which skips the # comment lines and joins the # rest; not shipped in the ISO itself. clk_ignore_unused pd_ignore_unused diff --git a/installer/live-build/live/calamares/qli-postinst.conf b/installer/live-build/live/calamares/qli-postinst.conf new file mode 100644 index 00000000..f95155b6 --- /dev/null +++ b/installer/live-build/live/calamares/qli-postinst.conf @@ -0,0 +1,13 @@ +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Calamares shellprocess job, which 0060-calamares.hook.chroot runs after +# the initramfs job. Runs the same post-install steps as d-i's +# preseed/late_command (see live-build/postinst/postinst.sh) on the +# target, from the stick's /qli/, which live-boot mounts at +# /run/live/medium. +--- +dontChroot: true +timeout: 600 +script: + - "sh /run/live/medium/qli/postinst.sh ${ROOT} /run/live/medium/qli" diff --git a/installer/live-build/live/hooks/0050-initramfs.hook.chroot b/installer/live-build/live/hooks/0050-initramfs.hook.chroot new file mode 100755 index 00000000..39792218 --- /dev/null +++ b/installer/live-build/live/hooks/0050-initramfs.hook.chroot @@ -0,0 +1,25 @@ +#!/bin/bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build chroot-stage hook (config/hooks/normal/*.chroot). +# +# Runs inside the live chroot after the package lists and includes.chroot +# are installed, and before build-installer.sh copies the kernel and initrd out of +# chroot/boot. +# +# Creates the initrd for each installed kernel that doesn't have one. The +# custom kernel comes from packages.chroot and doesn't depend on +# initramfs-tools, so apt may configure it before initramfs-tools is +# installed; its postinst then finds no /etc/kernel/postinst.d hook, and +# the later initramfs-tools trigger only updates initrds that exist. +set -euo pipefail + +shopt -s nullglob + +for kernel in /boot/vmlinuz-*; do + kver="${kernel#/boot/vmlinuz-}" + if [ ! -e "/boot/initrd.img-$kver" ]; then + update-initramfs -c -k "$kver" + fi +done diff --git a/installer/live-build/live/hooks/0060-calamares.hook.chroot b/installer/live-build/live/hooks/0060-calamares.hook.chroot new file mode 100755 index 00000000..00e21bf6 --- /dev/null +++ b/installer/live-build/live/hooks/0060-calamares.hook.chroot @@ -0,0 +1,57 @@ +#!/bin/bash +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# live-build chroot-stage hook (config/hooks/normal/*.chroot). +# +# Runs inside the live chroot after the package lists and includes.chroot +# are installed. Adapts calamares-settings-debian's configuration to the +# image: +# +# - Its sources-media and sources-final helpers hard-code +# RELEASE="trixie": set the live system's suite instead, and drop the +# backports sources on suites without backports. +# - Run the qli-postinst shellprocess job (see +# /etc/calamares/modules/qli-postinst.conf) after the initramfs job, so +# Calamares installs get the same post-install steps as d-i's. +# +# Fails if calamares-settings-debian's files no longer look as expected, +# rather than silently installing an unbootable system. +set -euo pipefail + +die() { + echo "0060-calamares: $*" >&2 + exit 1 +} + +# shellcheck source=/dev/null +SUITE="$(. /etc/os-release && echo "${VERSION_CODENAME:-}")" +[ -n "$SUITE" ] || die "no VERSION_CODENAME in /etc/os-release" + +HELPERS=/usr/share/calamares/helpers +SETTINGS=/etc/calamares/settings.conf + +for helper in "$HELPERS/calamares-sources-media" \ + "$HELPERS/calamares-sources-final"; do + grep -q '^RELEASE=' "$helper" || die "no RELEASE= in $helper" + sed -i "s/^RELEASE=.*/RELEASE=\"$SUITE\"/" "$helper" +done + +# Only stable suites have backports, as in build-installer.sh. +if [ "$SUITE" != "trixie" ]; then + sed -i '/-backports/d' "$HELPERS/calamares-sources-final" +fi + +grep -qx ' - initramfs' "$SETTINGS" || die "no initramfs job in $SETTINGS" +if grep -q '^instances:' "$SETTINGS"; then + die "$SETTINGS already has instances, extend them instead" +fi +sed -i 's/^ - initramfs$/&\n - shellprocess@qli-postinst/' "$SETTINGS" +cat >> "$SETTINGS" < Date: Fri, 27 Nov 2026 21:48:14 +0000 Subject: [PATCH 09/15] installer: add scripts to set up a build host and download the kernel The image depends heavily on live-build's behaviour, and the suite's live-build package differs between trixie and forky and changes whenever the archive does. Add setup-build-host.sh, which installs live-build from its git repository instead, pinned to a commit, so every build uses the same live-build and it only changes when the pin is bumped, along with its dependencies, stubble and the Qualcomm Linux APT repository. It expects a forky host for every target suite, so all builds share the same host tools, matching the live-build from git, rather than the target suite's older debootstrap, squashfs-tools and xorriso, and stubble from trixie-backports. live-build bootstraps the target suite's chroot itself, so the image still has the target suite's packages. Add download-kernel.sh to download the linux-image package a kernel metapackage (e.g. linux-image-qcom-next) depends on from that repository. Both are shared by CI and local container builds, so they build the same way. Signed-off-by: Christopher Obbard --- installer/download-kernel.sh | 43 ++++++++++++++ installer/setup-build-host.sh | 107 ++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100755 installer/download-kernel.sh create mode 100755 installer/setup-build-host.sh diff --git a/installer/download-kernel.sh b/installer/download-kernel.sh new file mode 100755 index 00000000..d063fbfa --- /dev/null +++ b/installer/download-kernel.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Download the kernel package for the installer image from the Qualcomm +# Linux APT repository, which setup-build-host.sh adds, e.g.: +# +# installer/download-kernel.sh qcom-next kernel/ +# +# linux-image-$KERNEL is a metapackage; download the real +# linux-image- package it depends on, which has the kernel, its +# modules and DTBs. +set -eu + +USAGE="Usage: $0 qcom-next|qcom-7.3 OUTDIR" + +if [ "$#" -ne 2 ]; then + echo "$USAGE" >&2 + exit 1 +fi +KERNEL="$1" +OUTDIR="$2" + +case "$KERNEL" in + qcom-*) ;; + *) + echo "Unknown kernel '$KERNEL'" >&2 + echo "$USAGE" >&2 + exit 1 + ;; +esac + +META="linux-image-$KERNEL" +PKG=$(apt-cache depends --no-recommends --no-suggests "$META" | + awk '$1 ~ /Depends:$/ && $2 ~ /^linux-image-/ { print $2; exit }') +if [ -z "$PKG" ]; then + echo "$META depends on no linux-image package" >&2 + exit 1 +fi + +mkdir -p "$OUTDIR" +(cd "$OUTDIR" && apt-get download "$PKG") +ls -l "$OUTDIR" diff --git a/installer/setup-build-host.sh b/installer/setup-build-host.sh new file mode 100755 index 00000000..eb4dc36b --- /dev/null +++ b/installer/setup-build-host.sh @@ -0,0 +1,107 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Prepare a Debian forky host or container, as root, to build the +# installer image: install live-build from git with its dependencies, +# stubble, and the Qualcomm Linux APT repository for the suite the image +# installs, which download-kernel.sh downloads the kernel from, e.g.: +# +# installer/setup-build-host.sh --suite trixie +# +# Build on forky whatever the target suite, for its newer live-build +# dependencies and stubble; live-build bootstraps the target suite itself. +set -eu + +SUITE="trixie" +# live-build from git rather than the suite's package, pinned to a known +# commit so that the build only changes when the pin is bumped. +LIVE_BUILD_REPO="https://salsa.debian.org/live-team/live-build.git" +LIVE_BUILD_REF="531cdb9854e04d08c3c3770463454d8a5e91b129" +USAGE="Usage: $0 [--suite SUITE]" + +while [ "$#" -gt 0 ]; do + case "$1" in + --suite) + SUITE="${2:?Missing value for --suite}" + shift 2 + ;; + -h|--help) + echo "$USAGE" + exit 0 + ;; + *) + echo "$USAGE" >&2 + exit 1 + ;; + esac +done + +if [ "$(id -u)" -ne 0 ]; then + echo "Run this script as root" >&2 + exit 1 +fi + +# Get the latest fixes first, and avoid an automated update while +# building. +apt-get update +apt-get -y full-upgrade + +# live-build's own dependencies (debootstrap, cpio) and recommends, as it's +# installed from git below, plus what installing it from git needs: po4a and +# gettext for its manpages, and dpkg-dev. +# dctrl-tools: grep-aptavail lists tasksel's standard task for the pool. +# stubble: stubblify, the Stubble EFI stub and its HWID database. +apt-get -y install \ + git \ + make \ + gettext \ + dpkg-dev \ + po4a \ + debootstrap \ + cpio \ + bzip2 \ + file \ + rsync \ + wget \ + apt-utils \ + fakeroot \ + xorriso \ + device-tree-compiler \ + ca-certificates \ + sudo \ + kmod \ + squashfs-tools \ + zstd \ + xz-utils \ + debian-archive-keyring \ + dctrl-tools \ + stubble + +LIVE_BUILD_SRC=$(mktemp -d) +git init "$LIVE_BUILD_SRC" +git -C "$LIVE_BUILD_SRC" fetch --depth 1 "$LIVE_BUILD_REPO" "$LIVE_BUILD_REF" +git -C "$LIVE_BUILD_SRC" checkout --detach FETCH_HEAD +make -C "$LIVE_BUILD_SRC" install +rm -rf "$LIVE_BUILD_SRC" +lb --version + +cat > /etc/apt/sources.list.d/qli.sources < Date: Fri, 27 Nov 2026 21:48:15 +0000 Subject: [PATCH 10/15] ci: build the installers nightly Build the installer images for the CI kernels every night, so that changes to the installer or the kernels which break them are caught, and so that there are recent images to test with. Build in a forky container for every suite, with installer/setup-build-host.sh. Anything lb runs on the host (e.g. debootstrap, mksquashfs, the host stubble's HWID database) is then forky's, which could make a trixie image differ from one built on trixie; revert to a per-suite container if trixie builds misbehave. Signed-off-by: Christopher Obbard --- .github/workflows/build-installer.yml | 37 +++++++++ .github/workflows/installer.yml | 105 ++++++++++++++++++++++++++ docs/workflows.md | 6 +- 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-installer.yml create mode 100644 .github/workflows/installer.yml diff --git a/.github/workflows/build-installer.yml b/.github/workflows/build-installer.yml new file mode 100644 index 00000000..bb5f5aae --- /dev/null +++ b/.github/workflows/build-installer.yml @@ -0,0 +1,37 @@ +# Builds the installer images: +# - on trixie and forky for the qcom-next kernel +# - on trixie for the qcom-7.3 kernel + +name: Build installer images + +on: + schedule: + - cron: '00 13 * * *' + # allow manual runs + workflow_dispatch: + +# grant nothing by default; the job below declares the scopes it needs +permissions: {} + +jobs: + build: + # don't run from forks of the main repository or from other branches; + # manual runs are allowed from any branch of the main repository so + # that changes to the workflows can be tested before they are merged + if: >- + github.repository == 'qualcomm-linux/qcom-deb-images' && + (github.event_name == 'workflow_dispatch' || + github.ref == 'refs/heads/main') + strategy: + fail-fast: false + matrix: + include: + - {kernel: qcom-next, suite: trixie} + - {kernel: qcom-next, suite: forky} + - {kernel: qcom-7.3, suite: trixie} + uses: $/.github/workflows/installer.yml + permissions: + contents: read + with: + kernel: ${{ matrix.kernel }} + suite: ${{ matrix.suite }} diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml new file mode 100644 index 00000000..0bd98e15 --- /dev/null +++ b/.github/workflows/installer.yml @@ -0,0 +1,105 @@ +name: Build installer image + +on: + workflow_call: + inputs: + kernel: + description: > + Kernel the installer boots and installs: qcom-7.3 or qcom-next + (from the Qualcomm Linux APT repository) + required: true + type: string + suite: + description: Distribution suite (e.g. trixie, forky) + type: string + default: trixie + + outputs: + artifacts_url: + description: "URL to retrieve build artifacts" + value: ${{ jobs.build-installer.outputs.url }} + +# grant nothing by default; every job below declares the scopes it needs. these +# are also capped by the calling job's permissions: block, so callers have to +# grant at least as much. +permissions: {} + +jobs: + build-installer: + name: Build and upload installer image (${{ inputs.kernel }}, ${{ inputs.suite }}) + permissions: + contents: read # actions/checkout + outputs: + url: ${{ steps.upload_artifacts_s3.outputs.url }} + runs-on: [self-hosted, qcom-u2404, arm64] + # fail a hung build instead of letting it run to the 6-hour default + timeout-minutes: 120 + # build in forky whatever the target suite; see + # installer/setup-build-host.sh + container: + image: public.ecr.aws/debian/debian:forky + options: --privileged + env: + KERNEL: ${{ inputs.kernel }} + SUITE: ${{ inputs.suite }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # live-build from git, its dependencies, stubble and the Qualcomm + # Linux APT repository + - name: Set up build host + run: | + set -ux + installer/setup-build-host.sh --suite "${SUITE}" + + # bmaptool and pigz: stage the image for publishing below + - name: Install publishing tools + run: | + set -ux + apt-get -y install bmaptool pigz + + - name: Download kernel package + run: | + set -ux + installer/download-kernel.sh "${KERNEL}" kernel + + - name: Build installer image + run: | + set -ux + installer/build-installer.sh --suite "${SUITE}" \ + --kernel-name "${KERNEL}" \ + kernel/*.deb + + - name: Stage installer artifacts for publishing + run: | + set -ux + dir="installer-artifacts" + # every job of a run uploads to the same destination, so name + # everything after the kernel and suite + name="installer-${KERNEL}-${SUITE}" + mkdir -v "${dir}" + img=$(ls installer/build/"${SUITE}-${KERNEL}"/*.iso) + bmaptool create "${img}" >"${dir}/${name}.iso.bmap" + pigz -c "${img}" >"${dir}/${name}.iso.gz" + # generate sha256sums for all artifacts + (cd "${dir}" && sha256sum * | tee "${name}-sha256sums.txt") + + # upload to a cloud storage space accessible by Axiom + - name: Upload private artifacts (S3) + uses: qualcomm-linux/upload-private-artifact-action@4940e9327cd7386acdb908b61c714c079b7d754b # aws-v4 + id: upload_artifacts_s3 + with: + path: installer-artifacts + # these should be the defaults + s3_bucket: qcom-prd-gh-artifacts + destination: ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ github.run_id }}-${{ github.run_attempt }}/ + + - name: "Print output" + env: + build_url: ${{ steps.upload_artifacts_s3.outputs.url }} + run: | + echo "Downloads URL: ${build_url}" + echo "## Download URL" >> $GITHUB_STEP_SUMMARY + echo "[${build_url}](${build_url})" >> $GITHUB_STEP_SUMMARY diff --git a/docs/workflows.md b/docs/workflows.md index e4748b13..88b276d3 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -18,6 +18,7 @@ as any change to them. | 07:00 | daily | Build Debian | `build-debian.yml` | | 09:00 | daily | mainline linux build | `linux-mainline.yml` | | 11:00 | Monday | Build U-Boot for RB1 | `u-boot.yml` | +| 13:00 | daily | Build installer images | `build-installer.yml` | `stale-issues.yaml` also runs daily at 01:30, but only on a GitHub-hosted runner and without LAVA jobs, so it is not part of the sequence above. @@ -35,10 +36,13 @@ runner and without LAVA jobs, so it is not part of the sequence above. * The rest follow in no particular order. The project-specific kernels (arduino, qcom-laptops) come next, then linux-next and Vanilla Debian, which tracks upstream Debian rather than what QLI ships. Mainline is the last daily - build. + image build. * The weekly U-Boot build runs on Monday after the daily ones. It only starts once the daily builds are done with the runners and LAVA, so it doesn't add its jobs on top. +* The installer images build last, after the weekly builds. They run no LAVA + jobs, so only compete for the runners, and 13:00 keeps the two hour gap + after the 11:00 U-Boot build. * EFS maintenance runs before the first build, to prune old artifacts, which is best avoided while a build is publishing to EFS. From a8326c01f6803b235adb2499bdf0c0282c091964 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:15 +0000 Subject: [PATCH 11/15] installer: add a script to build in a container Building the installer locally needs live-build and its dependencies on the host, and the host's live-build and tools may differ from the ones CI builds with. Add build-installer-container.sh, which sets up a privileged forky container with setup-build-host.sh and builds in it, as CI does, so a local build matches CI's and the host only needs podman or docker. Like CI, it downloads the kernel given by --kernel (e.g. qcom-next or qcom-7.3) from the Qualcomm Linux APT repository for the suite, or takes a locally built kernel package instead, so a kernel under development can be tried without publishing it. Rootless podman can't set up the loop devices live-build uses, even with --privileged, so run podman as root through sudo when it is rootless. Even as root, a privileged container gets a static copy of the host's /dev, so loop devices that losetup creates during the build do not show up in it; bind-mount the host's /dev so they do. The build tree is then owned by root, so create installer/build as the calling user first, and hand the tree back to them once the build succeeds. Signed-off-by: Christopher Obbard --- installer/build-installer-container.sh | 141 +++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 installer/build-installer-container.sh diff --git a/installer/build-installer-container.sh b/installer/build-installer-container.sh new file mode 100755 index 00000000..af32a47c --- /dev/null +++ b/installer/build-installer-container.sh @@ -0,0 +1,141 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Build the installer image in a privileged forky container, as +# .github/workflows/installer.yml does, so the host needs nothing but +# podman or docker. The kernel comes from the Qualcomm Linux APT +# repository, e.g.: +# +# installer/build-installer-container.sh --suite forky --kernel qcom-next +# +# A locally built kernel package can be given instead; --kernel then only +# names the build directory: +# +# installer/build-installer-container.sh --suite forky --kernel my-kernel ../linux-image-custom.deb +# +# The image is written to installer/build/$SUITE-$KERNEL/, as without a +# container. +set -eu + +ENGINE="" +IMAGE="public.ecr.aws/debian/debian:forky" +SUITE="trixie" +KERNEL="" +DEB="" +USAGE="Usage: $0 --kernel qcom-next|qcom-7.3 [--suite SUITE] [--engine podman|docker] + $0 [--kernel NAME] [--suite SUITE] [--engine podman|docker] KERNEL.deb" + +while [ "$#" -gt 0 ]; do + case "$1" in + --kernel) + KERNEL="${2:?Missing value for --kernel}" + shift 2 + ;; + --suite) + SUITE="${2:?Missing value for --suite}" + shift 2 + ;; + --engine) + ENGINE="${2:?Missing value for --engine}" + shift 2 + ;; + -h|--help) + echo "$USAGE" + exit 0 + ;; + -*) + echo "$USAGE" >&2 + exit 1 + ;; + *) + if [ -n "$DEB" ]; then + echo "$USAGE" >&2 + exit 1 + fi + if [ ! -f "$1" ]; then + echo "$1: no such file" >&2 + exit 1 + fi + DEB=$(realpath "$1") + shift + ;; + esac +done + +# Without a local package, the kernel is linux-image-$KERNEL from the +# Qualcomm Linux repository. +if [ -z "$DEB" ]; then + case "$KERNEL" in + qcom-*) ;; + *) + echo "$USAGE" >&2 + exit 1 + ;; + esac +fi + +if [ -z "$ENGINE" ]; then + if command -v podman >/dev/null 2>&1; then + ENGINE=podman + elif command -v docker >/dev/null 2>&1; then + ENGINE=docker + else + echo "Neither podman nor docker found" >&2 + exit 1 + fi +fi + +SRC_DIR=$(cd "$(dirname "$0")/.." && pwd) + +# live-build and d-i's initrd handling need loop devices and mknod, which +# rootless podman cannot do even with --privileged, so run podman as root. +SUDO="" +if [ "$ENGINE" = podman ] && [ "$(id -u)" -ne 0 ] && + [ "$(podman info --format '{{.Host.Security.Rootless}}')" = true ]; then + SUDO=sudo +fi + +# Create the build directory as the host user: the build runs as root, which +# would otherwise create it, and leave later scripts (e.g. the QEMU one) +# unable to write next to the image. +mkdir -p "$SRC_DIR/installer/build" + +# A local kernel package is mounted read-only, as it may live outside the +# source tree. +set -- +LOCAL_KERNEL="" +if [ -n "$DEB" ]; then + set -- -v "$DEB:/kernel-local/$(basename "$DEB"):ro" + LOCAL_KERNEL=1 +fi + +# The script below runs in the container, reading its parameters from the +# environment. The host's /dev is bind-mounted so that loop devices +# losetup creates during the build show up in the container. +$SUDO "$ENGINE" run --rm -i --privileged \ + -v /dev:/dev "$@" \ + -v "$SRC_DIR:/src" -w /src \ + -e SUITE="$SUITE" \ + -e KERNEL="$KERNEL" \ + -e LOCAL_KERNEL="$LOCAL_KERNEL" \ + -e HOST_UID="$(id -u)" \ + -e HOST_GID="$(id -g)" \ + "$IMAGE" sh -eux -s <<'EOF' +installer/setup-build-host.sh --suite "$SUITE" + +if [ -n "$LOCAL_KERNEL" ]; then + kernel_debs=/kernel-local +else + kernel_debs=/tmp/kernel + installer/download-kernel.sh "$KERNEL" "$kernel_debs" +fi + +set -- --suite "$SUITE" +if [ -n "$KERNEL" ]; then + set -- "$@" --kernel-name "$KERNEL" +fi +installer/build-installer.sh "$@" "$kernel_debs"/*.deb +# The build runs as root, so give the build tree back to the host user. +chown -R "$HOST_UID:$HOST_GID" installer/build +EOF From 9b5702172aece61a034c1f7559949736167b9be1 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:15 +0000 Subject: [PATCH 12/15] installer: add a script to run the image in QEMU Add run-installer-qemu.sh, which boots the image in QEMU on an arm64 host with KVM, attached as a USB stick with a virtio disk to install to, so the installer can be tried without hardware. Boot QEMU with a DT rather than ACPI: QEMU's SPCR table makes the serial port the preferred console over the image's console=tty0, so d-i would run on serial instead of the screen. Keep virtio-gpu and simpledrm in the installer initrds, so d-i has a display in QEMU. Signed-off-by: Christopher Obbard --- .../live-build/kernel/initrd-modules.rules | 5 +- installer/run-installer-qemu.sh | 130 ++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100755 installer/run-installer-qemu.sh diff --git a/installer/live-build/kernel/initrd-modules.rules b/installer/live-build/kernel/initrd-modules.rules index 5f5527b1..b5362d55 100644 --- a/installer/live-build/kernel/initrd-modules.rules +++ b/installer/live-build/kernel/initrd-modules.rules @@ -9,11 +9,14 @@ sound/* drivers/media/* # Display: only the Qualcomm GPU/display driver and the panels and bridges -# its boards use. +# its boards use, plus virtio-gpu and simpledrm so d-i shows on the screen +# in QEMU. drivers/gpu/* !drivers/gpu/drm/msm/* !drivers/gpu/drm/panel/* !drivers/gpu/drm/bridge/* +!drivers/gpu/drm/virtio/* +!drivers/gpu/drm/tiny/simpledrm.ko* # Wifi: the installer installs from its own pool, and its initrds have no # wifi firmware. diff --git a/installer/run-installer-qemu.sh b/installer/run-installer-qemu.sh new file mode 100755 index 00000000..7316382f --- /dev/null +++ b/installer/run-installer-qemu.sh @@ -0,0 +1,130 @@ +#!/bin/sh +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +# SPDX-License-Identifier: BSD-3-Clause + +# Boot an installer image in QEMU on an arm64 host with KVM, e.g.: +# +# installer/run-installer-qemu.sh installer/build/trixie-qcom-next/*.iso +# +# The image is attached as a USB stick, in snapshot mode so it isn't +# changed, and a virtio disk to install to, which is created if missing +# and kept between runs, along with the UEFI variables next to it. Boot +# the installed system by running again without the image (--no-image). +# +# Needs qemu-system-arm, qemu-utils and qemu-efi-aarch64. The host needs +# KVM: an arm64 machine with /dev/kvm. +set -eu + +IMAGE="" +DISK="installer/build/qemu-disk.qcow2" +DISK_SIZE="32G" +MEMORY="4G" +CPUS="4" +NO_IMAGE=0 +USAGE="Usage: $0 [--disk FILE] [--disk-size SIZE] [--memory SIZE] [--cpus N] IMAGE.iso | --no-image" + +while [ "$#" -gt 0 ]; do + case "$1" in + --disk) + DISK="${2:?Missing value for --disk}" + shift 2 + ;; + --disk-size) + DISK_SIZE="${2:?Missing value for --disk-size}" + shift 2 + ;; + --memory) + MEMORY="${2:?Missing value for --memory}" + shift 2 + ;; + --cpus) + CPUS="${2:?Missing value for --cpus}" + shift 2 + ;; + --no-image) + NO_IMAGE=1 + shift + ;; + -h|--help) + echo "$USAGE" + exit 0 + ;; + -*) + echo "$USAGE" >&2 + exit 1 + ;; + *) + [ -z "$IMAGE" ] || { echo "$USAGE" >&2; exit 1; } + IMAGE="$1" + shift + ;; + esac +done + +# Exactly one of IMAGE and --no-image. +if [ "$NO_IMAGE" = 1 ]; then + [ -z "$IMAGE" ] || { echo "$USAGE" >&2; exit 1; } +else + [ -n "$IMAGE" ] || { echo "$USAGE" >&2; exit 1; } +fi + +if [ -n "$IMAGE" ] && [ ! -f "$IMAGE" ]; then + echo "Missing image: $IMAGE" >&2 + exit 1 +fi + +if [ "$(uname -m)" != aarch64 ]; then + echo "This needs an arm64 host, for KVM" >&2 + exit 1 +fi + +if [ ! -w /dev/kvm ]; then + echo "/dev/kvm is missing or not writable (are you in the kvm group?)" >&2 + exit 1 +fi + +# The image isn't signed for Secure Boot, so use firmware without it. +FIRMWARE_DIR=/usr/share/AAVMF +FIRMWARE="$FIRMWARE_DIR/AAVMF_CODE.no-secboot.fd" +[ -f "$FIRMWARE" ] || FIRMWARE="$FIRMWARE_DIR/AAVMF_CODE.fd" +if [ ! -f "$FIRMWARE" ]; then + echo "Missing UEFI firmware in $FIRMWARE_DIR (install qemu-efi-aarch64)" >&2 + exit 1 +fi + +mkdir -p "$(dirname "$DISK")" +if [ ! -e "$DISK" ]; then + qemu-img create -f qcow2 "$DISK" "$DISK_SIZE" +fi + +# The UEFI variables, kept with the disk so its boot entries survive. +VARS="${DISK%.qcow2}-vars.fd" +if [ ! -e "$VARS" ]; then + cp "$FIRMWARE_DIR/AAVMF_VARS.fd" "$VARS" +fi + +# Boot with a DT, not ACPI: QEMU's SPCR table makes the serial port the +# preferred console over the image's console=tty0, so d-i would run on +# serial instead of the screen. +set -- \ + -machine virt,acpi=off -cpu host -accel kvm \ + -smp "$CPUS" -m "$MEMORY" \ + -drive if=pflash,format=raw,readonly=on,file="$FIRMWARE" \ + -drive if=pflash,format=raw,file="$VARS" \ + -device virtio-gpu-pci \ + -device qemu-xhci \ + -device usb-kbd \ + -device usb-tablet \ + -drive if=none,id=disk,format=qcow2,file="$DISK" \ + -device virtio-blk-pci,drive=disk,bootindex=1 \ + -netdev user,id=net \ + -device virtio-net-pci,netdev=net \ + -serial mon:stdio + +if [ -n "$IMAGE" ]; then + set -- "$@" \ + -drive if=none,id=stick,format=raw,snapshot=on,file="$IMAGE" \ + -device usb-storage,drive=stick,bootindex=0 +fi + +exec qemu-system-aarch64 "$@" From f8062811f99648e4593a936ca61a3e4d7b4567fa Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 27 Nov 2026 21:48:15 +0000 Subject: [PATCH 13/15] docs: document the installer Explain how to build the installer image, run it in QEMU and how the image and the target are customised, and point to it from the README. Signed-off-by: Christopher Obbard --- .github/workflows/build-installer.yml | 2 + README.md | 14 ++ docs/installer.md | 267 ++++++++++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 docs/installer.md diff --git a/.github/workflows/build-installer.yml b/.github/workflows/build-installer.yml index bb5f5aae..f07a2344 100644 --- a/.github/workflows/build-installer.yml +++ b/.github/workflows/build-installer.yml @@ -1,6 +1,8 @@ # Builds the installer images: # - on trixie and forky for the qcom-next kernel # - on trixie for the qcom-7.3 kernel +# +# See docs/installer.md. name: Build installer images diff --git a/README.md b/README.md index d4907ef3..3e6ddd54 100644 --- a/README.md +++ b/README.md @@ -477,6 +477,20 @@ never pull a Qualcomm Linux package on upgrade. Expect reduced hardware support compared to the default image, as the Debian kernel does not carry the Qualcomm platform patches which `linux-image-qcom-next` does. +## Build an installer image + +A customised, standalone installer image can be built with `live-build`, for +now for the Glymur CRD only. It boots a kernel from the Qualcomm Linux APT +repository, or from a kernel `.deb` you provide. The simplest way is to build +it in a forky container, which only needs podman or docker: + +```bash +installer/build-installer-container.sh --suite forky --kernel qcom-next +``` + +See [docs/installer.md](docs/installer.md) for more information about the +installer. + ## Development Want to join in the development? Changes welcome! See [CONTRIBUTING.md file](CONTRIBUTING.md) for step by step instructions. diff --git a/docs/installer.md b/docs/installer.md new file mode 100644 index 00000000..33714833 --- /dev/null +++ b/docs/installer.md @@ -0,0 +1,267 @@ +# Installer + +`installer/` contains a [live-build](https://salsa.debian.org/live-team/live-build) +configuration for a Debian installer image for Qualcomm devices. For now, the +only supported device is the Glymur CRD. + +The image installs Debian from the packages in its pool, optionally adding a +network mirror. The installer boots the kernel from a `linux-image` `.deb` +you provide, e.g. `linux-image-qcom-next`'s from the Qualcomm Linux APT +repository, in place of the stock d-i kernel, so it supports the same +hardware as that kernel. + +The pool has GNOME's task, so the desktop can be installed offline, and +tasksel ticks it by default. The image also has a live GNOME system, to try +the hardware without installing anything (see [Live system](#live-system)). + +This is still a prototype. + +## Requirements + +The simplest way to build is in a forky container, as CI does (see +[Build the image](#build-the-image)), which only needs podman or docker on +the host. + +To build natively, on a Debian forky host, run +`installer/setup-build-host.sh` as root once. It installs the build +dependencies, `stubble` and live-build from a pinned git commit, and adds the +Qualcomm Linux APT repository for the suite the image installs (`--suite`, +default `trixie`). live-build itself has to run as root. + +`stubble` provides `stubblify` and the HWID database. The build takes the +AArch64 stub from the `systemd-boot-efi:arm64` package in the image's pool. + +## Kernel requirements + +The kernel `.deb` is a single `linux-image-$KVER` package with the kernel +in `/boot`, its modules and its DTBs in `/usr/lib/linux-image-$KVER/`, as +the Qualcomm Linux kernel packages are. + +The installer initrds are repacked with xz, so the kernel needs +`CONFIG_RD_XZ=y`. They keep their `initrd.gz` names, as the kernel finds the +format from the data. + +The build writes an iso-hybrid image (`.iso`), which can be written to a USB +stick as well as burnt to a disc. The installer mounts it as ISO 9660, so the +kernel needs `CONFIG_ISO9660_FS`, see `kernel-configs/installer.config`. + +The wrapped kernels are embedded as they are, as in the debos images, so +the kernel should be a `CONFIG_EFI_ZBOOT=y` PE image. + +## Build the image + +To build in a forky container as CI does, so the host needs only podman or +docker, run `installer/build-installer-container.sh`. It runs +`setup-build-host.sh` and `download-kernel.sh` in the container, and +downloads the kernel given by `--kernel`, `linux-image-$KERNEL` (e.g. +`qcom-next` or `qcom-7.3`), from the Qualcomm Linux APT repository for the +suite: + +```bash +installer/build-installer-container.sh --suite forky --kernel qcom-next +``` + +A locally built kernel package can be given instead, with `--kernel` only +naming the build directory: + +```bash +installer/build-installer-container.sh --suite forky --kernel my-kernel ../linux-image-custom.deb +``` + +It picks podman, or docker if podman is missing; `--engine` overrides that. + +To build natively, on a host set up as in [Requirements](#requirements): + +```bash +installer/download-kernel.sh qcom-next kernel/ +make installer KERNEL_DEB=kernel/linux-image-*.deb \ + INSTALLER_OPTS="--kernel-name qcom-next" +``` + +This runs `installer/build-installer.sh` through `sudo`, unless make is already +running as root. `SUITE` picks the Debian suite (default `trixie`), and +`INSTALLER_OPTS` passes further options to the script: + +| Option | Default | Description | +| ------ | ------- | ----------- | +| `--suite` | `trixie` | Debian suite, e.g. `forky`; `make installer` sets it from `SUITE` | +| `--kernel-name` | the kernel's version | kernel name for the build directory, e.g. `qcom-next` | + +The image is written as `installer/build/$SUITE-$KERNEL/*.iso`. +Write it to a USB stick, e.g. with `bmaptool copy --nobmap` or `dd`. Each +kernel and suite has its own live-build tree there. The build +refuses to run if the tree already exists, so remove it before rebuilding: + +```bash +make clean-installer +``` + +On an arm64 host with KVM, `installer/run-installer-qemu.sh` boots an image +in QEMU, attached as a USB stick, with a virtio disk to install to +(`installer/build/qemu-disk.qcow2` by default, kept between runs). +`--no-image` boots the installed system from that disk. It needs +`qemu-system-arm`, `qemu-utils` and `qemu-efi-aarch64`: + +```bash +installer/run-installer-qemu.sh installer/build/trixie-qcom-next/*.iso +``` + +The installer initrds keep `virtio-gpu` and `simpledrm`, besides the +Qualcomm display driver, so the installer has a display in QEMU. + +## How it is built + +`build-installer.sh` runs `lb config` in the build tree and then copies the files in +`installer/live-build/` to their places in the generated `config/`. +`installer/live-build/` is grouped by topic (`kernel/`, `defaults/`, +`dtb-loader/` etc.), and `build-installer.sh` lists every file with its +destination. A topic's `lib/` holds scripts that `build-installer.sh` runs; +they are never copied into the image. + +During `lb binary`, once the package lists have filled the pool, +`live-build/kernel/hooks/0050-replace-di-kernel.hook.binary` runs +`live-build/kernel/lib/replace-di-kernel.sh`, which replaces the kernel in +the installer's initrds with the one from the kernel `.deb`, along with +its modules and the preseeds, and repacks them with xz: + +- `live-build/kernel/lib/trim-modules.sh` drops the modules the installer + doesn't need, following `live-build/kernel/initrd-modules.rules`. The + initrds have no firmware, nor wifi drivers, as the installer installs + from its own pool. +- The files in the topics' `preseed/` dirs go into the initrds as + `/preseed.cfg`. + +The binary hooks in `live-build/defaults/hooks/` drop the stock kernel's +module udebs and udebs for unused hardware from the pool. The pool also has +tasksel's standard task and the packages in +`live-build/defaults/package-lists/`, so the installer can install a +standard system offline, and GNOME too (`gnome.list.binary`). +`defaults/preseed/tasksel-gnome.cfg` makes tasksel tick GNOME by default. + +`build-installer.sh` also adds the kernel `.deb` to the pool, from +`config/packages.binary/`, in place of the stock kernel, which +`0060-prune-pool.hook.binary` drops. + +`live-build/kernel/package-lists/linux-base.list.binary` adds the +kernel's newer `linux-base`, since base-installer installs the kernel +before backports is set up on the target, and +`live-build/dtb-loader/package-lists/dtb-loader.list.binary` adds +`stubble` and `systemd-boot-efi`, with their dependencies. On trixie, +`build-installer.sh` enables `trixie-backports` in live-build, which `stubble` comes +from, and `live-build/kernel/archives/linux-base.pref.chroot` pins +`linux-base` to it. + +`live-build/firmware/package-lists/firmware.list.binary` adds the wifi and +SoC firmware packages from non-free-firmware. live-build files them under +the pool's non-free component, which the ISO's `Release` doesn't list, so +`live-build/firmware/hooks/0040-non-free-firmware.hook.binary` moves them +back to non-free-firmware. On trixie, +`live-build/firmware/archives/firmware.pref.chroot` pins them to +`trixie-backports`: trixie's WCN7850 firmware is too old for newer kernels, +and `firmware-qcom-dsp` is only in backports. + +It also generates preseed lines in `config/installer-preseed.cfg` so that +base-installer installs the custom kernel and pkgsel the firmware, +`stubble` and `systemd-boot-efi`. + +## Boot menu + +The GRUB menu is live-build's own: the live system (the default) and the +graphical and text installers, with their advanced options. The kernel +arguments the Qualcomm machines need are in `live-build/kernel/kernel-cmdline`, +which `build-installer.sh` gives to live-build's boot entries +(`--bootappend-install` and `--bootappend-live`) and, through the preseed's +`debian-installer/add-kernel-opts`, to the installed system. + +The installer entries boot the installer kernel, `/install/vmlinuz`, which +`0100-dtb-loader.hook.binary` wraps in place with a DTB-loading EFI stub. It +bundles every DTB of the kernel with an entry in Stubble's HWID database +and picks the right one at boot. The live system's kernel is wrapped the same +way. + +## Live system + +The image boots a Debian live system with GNOME (`task-gnome-desktop`) from +`live/filesystem.squashfs`, built by `lb chroot` and `lb binary` from the +same suite. It runs the kernel from the kernel `.deb`, with its +dependencies and the firmware packages, like the installed system. The +Stubble hook wraps its kernel, `/live/vmlinuz-$VERSION`, like the installer's. + +The live system can be installed to disk with Calamares, from the "Install +Debian" icon on its desktop. Calamares copies the live system to the disk, +with Debian's settings (`calamares-settings-debian`), adapted by +`live-build/live/hooks/0060-calamares.hook.chroot`: + +- its APT sources use the image's suite, instead of the hard-coded trixie, + with backports on trixie only +- it then runs `postinst.sh` (see [Installed system](#installed-system)) on + the target, as d-i does, from `live-build/live/calamares/qli-postinst.conf` + +`build-installer.sh` also gives the live system, and so the target, a GRUB +snippet with the `kernel/kernel-cmdline` args, as d-i passes them on from +the boot entry. GRUB is installed from the stick's pool +(`live/package-lists/calamares.list.binary`). Unlike a d-i install, the +target doesn't get the trixie-backports pins for the kernel's `linux-base` +and the firmware. + +The image's installer entries don't use the live system. live-build's own +`--debian-installer live` installer copies the live squashfs to the disk, but +these images use live-build's `cdrom` installer, so the installer +entries install from the pool. + +The live system is untested on hardware and needs testing. + +## Installed system + +The installed system gets the custom kernel, which boots it. + +apt-setup enables `non-free-firmware` on it (`live-build/defaults/preseed/`), +and `trixie-backports` on trixie, which `build-installer.sh` adds by suite. There are no +APT pins, and no Qualcomm Linux repository, unlike the debos rootfs +(`debos-recipes/qualcomm-linux-debian-rootfs.yaml`). + +An install with no network gets no Debian entries in `/etc/apt/sources.list` +at all: the installer turns the mirror off, so apt-setup writes no mirror, +security, updates or backports lines (nor the `non-free-firmware` +component, which goes on the mirror line). Add the sources by hand, or install with a network, before using +`apt` on the installed system. + +On arm64, `live-build/postinst/preseed/postinst.cfg` runs +`/qli/postinst.sh` from the image at the end of the install, which sources +the parts in `/qli/postinst.d/` to install the files no package ships. Some +of them come from the rootfs overlays in `debos-recipes/overlays/`, which +`build-installer.sh` copies to `/qli/overlays/` on the image: + +- the kernel hook from the `dtb-loader` overlay, `50-stubble`, which wraps + each `/boot/vmlinuz-$VERSION` in place in Stubble, along with the DTBs + Stubble has HWIDs for (`dpkg --verify` flags the changed kernel; + reinstalling the kernel package wraps it again) +- the `kernel-install` variant of that hook, `95-dtb-loader.install`, in + `/etc/kernel/install.d/`. GRUB doesn't use `kernel-install`, so it + stays unused unless the installed system switches to systemd-boot; the + stock GRUB entries boot the wrapped kernels + +It then wraps the kernel. +Packaging these files would make it unnecessary. + +The wrapped kernels are unsigned, so booting them likely needs Secure Boot +disabled. + +The installed system boots via shim, as on a stock Debian install: +grub-installer installs `shim-signed` from the pool along with GRUB. + +## CI + +`.github/workflows/build-installer.yml` builds the images every night and on +demand, for these kernels: + +- `qcom-next`: `linux-image-qcom-next` from the Qualcomm Linux APT repository, + on trixie and forky +- `qcom-7.3`: `linux-image-qcom-7.3` from the Qualcomm Linux APT repository, + on trixie + +`.github/workflows/installer.yml` runs the same steps as +`build-installer-container.sh` in a forky container: `setup-build-host.sh`, +`download-kernel.sh` and `build-installer.sh`. It builds the image and uploads it gzipped as +`installer-$KERNEL-$SUITE.iso.gz`, with a `.iso.bmap` block map +for `bmaptool copy` and its `sha256sums`. From 3db4cba3a32b4807d58b77cc08ffb4def8ceb228 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 30 Oct 2026 14:41:07 +0000 Subject: [PATCH 14/15] HACK: ci: skip PR builds and tests for this branch The PR for the installer branch doesn't change the debos images, so building and testing them for every push only wastes the runners and LAVA. Drop before merging. Signed-off-by: Christopher Obbard --- .github/workflows/build-on-pr.yml | 4 ++++ .github/workflows/test-pr.yml | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-on-pr.yml b/.github/workflows/build-on-pr.yml index cb18b8a1..3f0dc619 100644 --- a/.github/workflows/build-on-pr.yml +++ b/.github/workflows/build-on-pr.yml @@ -9,6 +9,8 @@ permissions: {} jobs: event-file: name: "Upload event file" + # HACK: temporary, drop before merging: skip PRs from the installer branch + if: github.head_ref != 'wip/obbardc/iso-installer' runs-on: ubuntu-26.04 permissions: contents: read # actions/upload-artifact @@ -20,6 +22,8 @@ jobs: path: ${{ github.event_path }} build: + # HACK: temporary, drop before merging: skip PRs from the installer branch + if: github.head_ref != 'wip/obbardc/iso-installer' strategy: fail-fast: false matrix: diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 5dca85ff..c10c07d6 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -26,7 +26,11 @@ jobs: runs-on: ubuntu-26.04 permissions: contents: read # actions/github-script - if: ${{ github.event.workflow_run.conclusion == 'success' }} + # HACK: temporary, drop before merging: Build on PR skips PRs from the + # installer branch, but its run still succeeds, so skip them here too + if: >- + ${{ github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.head_branch != 'wip/obbardc/iso-installer' }} outputs: url: ${{ steps.set-build-url.outputs.url }} pr_number: ${{ steps.pr-details.outputs.pr_number }} From 5a1eefc445f3e640cbd43173d2c404bff8dfa7a4 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 30 Oct 2026 14:41:07 +0000 Subject: [PATCH 15/15] HACK: ci: installer: build on pushes to this branch The nightly installer builds only run from main, so the installer branch can't be tested before it is merged. Also build on pushes to it. Drop before merging. Signed-off-by: Christopher Obbard --- .github/workflows/build-installer.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-installer.yml b/.github/workflows/build-installer.yml index f07a2344..bf594ca7 100644 --- a/.github/workflows/build-installer.yml +++ b/.github/workflows/build-installer.yml @@ -11,6 +11,10 @@ on: - cron: '00 13 * * *' # allow manual runs workflow_dispatch: + # HACK: temporary, drop before merging: build the installers on pushes + # to the installer branch + push: + branches: [wip/obbardc/iso-installer] # grant nothing by default; the job below declares the scopes it needs permissions: {} @@ -20,10 +24,13 @@ jobs: # don't run from forks of the main repository or from other branches; # manual runs are allowed from any branch of the main repository so # that changes to the workflows can be tested before they are merged + # HACK: temporary, drop before merging: also run on pushes to the + # installer branch if: >- github.repository == 'qualcomm-linux/qcom-deb-images' && (github.event_name == 'workflow_dispatch' || - github.ref == 'refs/heads/main') + github.ref == 'refs/heads/main' || + github.ref == 'refs/heads/wip/obbardc/iso-installer') strategy: fail-fast: false matrix: