Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 122 additions & 17 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,46 @@ show-me-the-future:
just export-installer
just test-installer-artifact

# INSTALLER_BOOT_MODE selects how the installer itself is started:
# usb (default) — firmware (OVMF) boots the raw image off an emulated xHCI USB
# drive, the bare-metal USB install path.
# pxe — QEMU boots the exported PXE vmlinuz/initrd pair directly with
# -kernel/-initrd/-append, the network install path.
# Everything after the install (target partition check, booting the installed
# system, kiosk readiness probe) is identical for both modes.
# Install and reboot already-exported server artifacts in QEMU.
[group('test')]
test-installer-artifact:
#!/usr/bin/env bash
set -euo pipefail

BOOT_MODE="${INSTALLER_BOOT_MODE:-usb}"
case "${BOOT_MODE}" in
usb|pxe) ;;
*) echo "ERROR: INSTALLER_BOOT_MODE must be 'usb' or 'pxe', got '${BOOT_MODE}'." >&2; exit 1 ;;
esac

CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
mkdir -p "$CACHE_DIR"
WORKDIR="$(mktemp -d "${CACHE_DIR}/bluefin-show-future.XXXXXX")"
trap 'rm -rf "$WORKDIR"' EXIT

# The raw installer image is always needed; usb mode boots it through firmware
# so it consumes nothing else. The PXE vmlinuz/initrd pair is only copied in pxe
# mode, because copying it unconditionally would fail the usb test on hosts that
# have the installer image but no PXE artifacts.
cp dist/bluefin-server-installer-*.raw.zst "$WORKDIR/installer.raw.zst"
cp dist/bluefin-server-pxe-vmlinuz-* "$WORKDIR/installer.vmlinuz"
cp dist/bluefin-server-pxe-initrd-*.cpio.gz "$WORKDIR/installer.initrd"
if [ "${BOOT_MODE}" = "pxe" ]; then
PXE_KERNEL=$(find dist/ -maxdepth 1 -type f -name 'bluefin-server-pxe-vmlinuz-*' | head -n1)
PXE_INITRD=$(find dist/ -maxdepth 1 -type f -name 'bluefin-server-pxe-initrd-*.cpio.gz' | head -n1)
if [ -z "${PXE_KERNEL}" ] || [ -z "${PXE_INITRD}" ]; then
echo "ERROR: INSTALLER_BOOT_MODE=pxe needs an exported PXE kernel and initrd in dist/." >&2
echo "Please run: just build-installer && just export-pxe" >&2
exit 1
fi
cp "${PXE_KERNEL}" "$WORKDIR/installer.vmlinuz"
cp "${PXE_INITRD}" "$WORKDIR/installer.initrd"
fi
zstd -d "$WORKDIR/installer.raw.zst" -o "$WORKDIR/installer.raw"
TARGET_SIZE="${SHOW_ME_THE_FUTURE_DISK_SIZE:-16G}"
truncate -s "${TARGET_SIZE}" "$WORKDIR/target.raw"
Expand Down Expand Up @@ -393,42 +419,102 @@ test-installer-artifact:

OVMF_VARS=$(first_existing \
/home/linuxbrew/.linuxbrew/Cellar/qemu/*/share/qemu/edk2-x86_64-vars.fd \
/home/linuxbrew/.linuxbrew/Cellar/qemu/*/share/qemu/edk2-i386-vars.fd \
/usr/share/edk2/ovmf/OVMF_VARS.fd \
/usr/share/OVMF/OVMF_VARS.fd \
/usr/share/OVMF/OVMF_VARS_4M.fd \
/usr/share/edk2/x64/OVMF_VARS.4m.fd \
/usr/share/qemu/edk2-x86_64-vars.fd \
/usr/share/qemu/edk2-i386-vars.fd \
/usr/share/qemu/OVMF_VARS.fd) \
|| true
if [ -n "$OVMF_VARS" ]; then
if [ -n "${OVMF_VARS}" ]; then
cp "$OVMF_VARS" "$WORKDIR/ovmf-vars.fd"
else
# Hosts that ship only OVMF_CODE still boot: firmware initialises a blank
# variable store on first use, it just has no preseeded boot entries.
echo "WARNING: no OVMF_VARS template found; using a blank variable store sized to $OVMF_CODE" >&2
truncate -s "$(stat -c '%s' "$OVMF_CODE")" "$WORKDIR/ovmf-vars.fd"
fi

SMP_CPUS="${SHOW_ME_THE_FUTURE_SMP:-$(nproc)}"
MEM_SIZE="${SHOW_ME_THE_FUTURE_MEM:-8192}"

echo "==> Booting installer media in QEMU..."
echo "==> Booting installer media in QEMU (mode: ${BOOT_MODE})..."
# ponytail: we want QEMU to exit cleanly after install. Since QEMU's -no-reboot
# suspends/halts on reboot signals, we override systemd-sysinstall.service SuccessAction/FailureAction
# to poweroff. When the installer triggers poweroff, QEMU terminates, and we boot into the newly installed OS.
qemu-system-x86_64 \
-enable-kvm \
-m "${MEM_SIZE}" \
-cpu host \
-smp "${SMP_CPUS}" \
-drive file="$WORKDIR/installer.raw",format=raw,if=virtio,readonly=on \
-drive file="$WORKDIR/target.raw",format=raw,if=virtio \
-drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \
-drive if=pflash,format=raw,file="$WORKDIR/ovmf-vars.fd" \
-kernel "$WORKDIR/installer.vmlinuz" \
-initrd "$WORKDIR/installer.initrd" \
-append "systemd.unit=system-install.target console=tty0 console=ttyS0,115200 rw unattended" \
INSTALLER_TIMEOUT="${SHOW_ME_THE_FUTURE_INSTALL_TIMEOUT:-600}"
INSTALL_ARGS=(
-enable-kvm
-m "${MEM_SIZE}"
-cpu host
-smp "${SMP_CPUS}"
-drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE"
-drive if=pflash,format=raw,file="$WORKDIR/ovmf-vars.fd"
)
if [ "${BOOT_MODE}" = "usb" ]; then
# Firmware boots the image's own bootloader, so the unattended flag has to
# reach the UKI through systemd-stub rather than QEMU's -append.
#
# NOTE: systemd-stub deliberately ignores io.systemd.stub.kernel-cmdline-extra
# when Secure Boot is enabled, because the SMBIOS string is not covered by the
# signature. Point $OVMF_CODE at a secure-boot firmware build and this run
# boots interactive instead of unattended, then sits there until
# SHOW_ME_THE_FUTURE_INSTALL_TIMEOUT expires with a misleading "install did
# not finish" failure. Use INSTALLER_BOOT_MODE=pxe (-append is always honoured)
# to exercise unattended installs under Secure Boot firmware.
INSTALL_ARGS+=(
-device qemu-xhci,id=xhci
-drive file="$WORKDIR/installer.raw",format=raw,if=none,id=installer-disk,readonly=on
-device usb-storage,bus=xhci.0,drive=installer-disk,bootindex=1
-drive file="$WORKDIR/target.raw",format=raw,if=none,id=target-disk
-device virtio-blk-pci,drive=target-disk,bootindex=2
-smbios "type=11,value=io.systemd.stub.kernel-cmdline-extra=console=tty0 console=ttyS0,,115200 rw unattended"
)
else
INSTALL_ARGS+=(
-drive file="$WORKDIR/installer.raw",format=raw,if=virtio,readonly=on
-drive file="$WORKDIR/target.raw",format=raw,if=virtio
-kernel "$WORKDIR/installer.vmlinuz"
-initrd "$WORKDIR/installer.initrd"
-append "systemd.unit=system-install.target console=tty0 console=ttyS0,115200 rw unattended"
)
fi
timeout "${INSTALLER_TIMEOUT}" qemu-system-x86_64 \
"${INSTALL_ARGS[@]}" \
-nographic \
-serial mon:stdio \
-no-reboot < /dev/null

echo "==> Validating target disk partitions after installer execution..."
for tool in sfdisk jq; do
command -v "$tool" >/dev/null 2>&1 \
|| { echo "ERROR: '$tool' is required to validate the target disk layout but is not installed." >&2; exit 1; }
done

# Keep sfdisk and jq failures distinguishable from "the installer did not
# partition the disk", otherwise a broken host tool is misreported as a
# failed install.
if ! TARGET_TABLE=$(sfdisk --json "$WORKDIR/target.raw"); then
echo "ERROR: sfdisk could not read a partition table from $WORKDIR/target.raw!" >&2
sfdisk -l "$WORKDIR/target.raw" >&2 || true
exit 1
fi
if ! TARGET_PARTS=$(jq -r '.partitiontable.partitions[]?.name // empty' <<<"$TARGET_TABLE"); then
echo "ERROR: jq failed to parse the sfdisk JSON output!" >&2
echo "$TARGET_TABLE" >&2
exit 1
fi
if ! echo "$TARGET_PARTS" | grep -Fxq 'bluefin-server-root-a' || \
! echo "$TARGET_PARTS" | grep -Fxq 'var'; then
echo "ERROR: Target disk did not receive expected partition layout from installer!" >&2
echo "Observed partitions:" >&2
echo "$TARGET_PARTS" >&2
sfdisk -l "$WORKDIR/target.raw" >&2 || true
exit 1
fi
echo "==> Target disk successfully partitioned and populated!"
SERIAL_LOG="$WORKDIR/serial.log"
TARGET_QEMU_PID=""
cleanup() {
Expand Down Expand Up @@ -521,6 +607,20 @@ test-installer-artifact:
sleep 2
done

# This is the default mode of test-installer-artifact; the recipe exists so the USB
# boot path is discoverable by name.
# Boot the exported installer media via firmware (OVMF) as an xHCI USB drive.
[group('test')]
test-installer-boot-usb:
INSTALLER_BOOT_MODE=usb just test-installer-artifact

# `just export-pxe` only checks that the two files exist, so this recipe is the only
# thing that proves they still boot and install.
# Boot the exported PXE kernel/initrd pair directly (QEMU -kernel/-initrd/-append).
[group('test')]
test-installer-boot-pxe:
INSTALLER_BOOT_MODE=pxe just test-installer-artifact

# Interactively install and boot a persistent local KubeStellar kiosk VM.
[group('test')]
install-vm:
Expand Down Expand Up @@ -559,16 +659,21 @@ install-vm:
if [ ! -f "$OVMF_VARS" ]; then
OVMF_TEMPLATE=$(first_existing \
/home/linuxbrew/.linuxbrew/Cellar/qemu/*/share/qemu/edk2-x86_64-vars.fd \
/home/linuxbrew/.linuxbrew/Cellar/qemu/*/share/qemu/edk2-i386-vars.fd \
/usr/share/edk2/ovmf/OVMF_VARS.fd \
/usr/share/OVMF/OVMF_VARS.fd \
/usr/share/OVMF/OVMF_VARS_4M.fd \
/usr/share/edk2/x64/OVMF_VARS.4m.fd \
/usr/share/qemu/edk2-x86_64-vars.fd \
/usr/share/qemu/edk2-i386-vars.fd \
/usr/share/qemu/OVMF_VARS.fd) \
|| true
if [ -n "$OVMF_TEMPLATE" ]; then
if [ -n "${OVMF_TEMPLATE}" ]; then
cp "$OVMF_TEMPLATE" "$OVMF_VARS"
else
# Hosts that ship only OVMF_CODE still boot: firmware initialises a blank
# variable store on first use, it just has no preseeded boot entries.
echo "WARNING: no OVMF_VARS template found; using a blank variable store sized to $OVMF_CODE" >&2
truncate -s "$(stat -c '%s' "$OVMF_CODE")" "$OVMF_VARS"
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion docs/skills/ci-tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ uploaded to a GitHub Release tagged `installer-v<FSDK-RELEASE>`.
result as its own pull request against `main`.
3. **Full Compilation:** Builds the standalone DDI OS image, live installer, and
k0s systemd-sysext on every pull request and push to `main`.
4. **Installer boot test:** Uploads the already-built installer and PXE artifacts and calls `projectbluefin/actions/.github/workflows/server-installer-test.yml`. The shared workflow prepares QEMU/KVM and runs this repository's `just test-installer-artifact`; Lima remains local-only.
4. **Installer boot test:** Uploads the already-built installer and PXE artifacts and calls `projectbluefin/actions/.github/workflows/server-installer-test.yml`. The shared workflow prepares QEMU/KVM and runs this repository's `just test-installer-artifact`, which defaults to the USB/firmware boot path and consumes only the raw installer image; the uploaded PXE pair is exercised by `just test-installer-boot-pxe` (`INSTALLER_BOOT_MODE=pxe`). Lima remains local-only.
5. **Version Derivation:** The release tag is derived with `just version`, which
parses the pinned FSDK point release from `elements/freedesktop-sdk.bst`.
6. **Automated Publishing:** For pushes to `main` (including Renovate PR merges),
Expand Down
24 changes: 24 additions & 0 deletions docs/skills/ddi-installer-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,33 @@ just export-sysext # export sysext artifacts to dist/sysext/
just flash-installer # write the installer image to a USB device
just show-me-the-future # end-to-end QEMU installer smoke test
just test-installer-artifact # test already-exported artifacts in QEMU without rebuilding
just test-installer-boot-usb # test-installer-artifact in USB/firmware boot mode
just test-installer-boot-pxe # test-installer-artifact in PXE -kernel/-initrd boot mode
just tags # show FSDK-derived version tags
```

`just test-installer-artifact` boots the exported raw installer image through OVMF
firmware as an emulated xHCI USB drive (`-device qemu-xhci` plus `-device usb-storage`),
with the target disk on virtio-blk. This is the bare-metal USB install path: firmware
picks the bootloader off the image itself rather than QEMU injecting a kernel through
`-kernel`/`-initrd`. The boot method is selected by `INSTALLER_BOOT_MODE` (`usb`, the
default, or `pxe`); everything after the install is identical for both. `just
test-installer-boot-usb` and `just test-installer-boot-pxe` are the named entry points.

Use `pxe` mode to exercise the exported `bluefin-server-pxe-vmlinuz-*` /
`bluefin-server-pxe-initrd-*.cpio.gz` pair, which is booted with `-kernel`/`-initrd`
and an explicit `-append` command line. `just export-pxe` only asserts that those two
files exist, so the PXE recipe is what proves they still boot and install. PXE mode is
also the way to test an unattended install under Secure Boot firmware: in USB mode the
unattended flag travels via `-smbios type=11 io.systemd.stub.kernel-cmdline-extra`, and
systemd-stub ignores that credential when Secure Boot is enabled.

The recipe prefers a real `OVMF_VARS` template but falls back to a blank variable store
sized to `OVMF_CODE` on hosts that ship CODE only, so a missing template is a warning
rather than a hard failure. It needs `qemu-system-x86_64`, `zstd`, `sfdisk` and `jq` on
the host; the last two are used to assert that the installer actually partitioned the
target disk, and the recipe fails with a named error if either is missing.

### Payload base

`build-ddi` takes an optional `os-base` argument selecting which payload it
Expand Down
46 changes: 42 additions & 4 deletions elements/oci/bluefin-server-installer.bst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ config:
#!/bin/bash
set -euo pipefail

CMDLINE="$(< /proc/cmdline)"

# The service drop-in uses StandardOutput=journal+console so unattended runs
# land on the serial console that automated tests capture. /dev/console follows
# the last console= argument, which is ttyS0, so an interactive bare-metal
# install would otherwise print to serial rather than the attached display.
# Keep the interactive installer on the attached display by redirecting this
# script's own output to /dev/tty0 — but only when the kernel actually drives
# tty0 as a console. On serial-only machines the VT device still exists and is
# writable, so a -w test alone would send the whole install to a display nobody
# is watching; /sys/class/tty/console/active lists the consoles the kernel
# really registered, and omits tty0 when the boot was serial-only. If that file
# is unreadable the redirect is skipped and output stays on journal+console.
if [[ " ${CMDLINE} " != *" unattended "* ]] \
&& [ -w /dev/tty0 ] \
&& grep -qw tty0 /sys/class/tty/console/active 2>/dev/null; then
exec > /dev/tty0 2>&1
fi

# Ensure storage controller modules and filesystems are loaded before probing devices
modprobe -q nvme || true
modprobe -q nvme_core || true
Expand Down Expand Up @@ -265,18 +284,31 @@ config:
# bluefin-installer-data partition. Under PXE (inst.ddi_url=) there is no
# installer media, so the check is skipped when inst.ddi_url is set.
if [ -z "${DDI_URL}" ]; then
# Hard preflight: wait up to 30s for storage settle and installer data partition to become available
INSTALLER_PART_PATH="/dev/disk/by-partlabel/bluefin-installer-data"
DEADLINE=$((SECONDS + 30))
udevadm trigger --subsystem-match=block || true
udevadm settle --timeout=5 || true
while [ ! -b "${INSTALLER_PART_PATH}" ] && [ "${SECONDS}" -lt "${DEADLINE}" ]; do
sleep 1
udevadm trigger --subsystem-match=block || true
REMAINING=$((DEADLINE - SECONDS))
[ "${REMAINING}" -gt 0 ] || break
SETTLE_TIMEOUT=$(( REMAINING < 5 ? REMAINING : 5 ))
udevadm settle --timeout="${SETTLE_TIMEOUT}" || true
done

if [ ! -b "${INSTALLER_PART_PATH}" ]; then
echo "ERROR: Installer data partition '${INSTALLER_PART_PATH}' is missing or not a block device!" >&2
echo "ERROR: Installer data partition '${INSTALLER_PART_PATH}' is missing or not a block device after 30s deadline!" >&2
echo "==> Block devices visible at failure:" >&2
lsblk -p -o NAME,TYPE,PARTLABEL,PKNAME,SIZE,FSTYPE >&2 || true
echo "==> Partition label symlinks visible under /dev/disk/by-partlabel/:" >&2
ls -la /dev/disk/by-partlabel/ >&2 || true
exit 1
fi
INSTALLER_PART="$(readlink -f "${INSTALLER_PART_PATH}")"
echo "==> Found installer partition at ${INSTALLER_PART_PATH} -> ${INSTALLER_PART}"
fi

# Auto-detect target disk for unattended install (any raw disk of type "disk" that is not the installer, is not read-only, and has size > 0)
TARGET_DISK=""
while read -r name type ro size; do
Expand Down Expand Up @@ -343,6 +375,7 @@ config:
fi
}

# Check for unattended in kernel command line
if [[ " ${CMDLINE} " == *" unattended "* ]]; then
echo "==> Running in UNATTENDED mode..."
if [ -n "${TARGET_DISK}" ]; then
Expand Down Expand Up @@ -387,8 +420,13 @@ config:
FailureAction=poweroff

[Service]
# Keep the interactive installer on the attached display. The kernel
# still uses the final serial console for boot diagnostics.
# Mirror installer service output to journal+console so progress and diagnostics
# are captured on the serial console in headless/automated test runs. TTYPath is
# only honoured for Standard*=tty, so it does not steer this output; the wrapper
# keeps the interactive installer on the attached display by redirecting itself
# to /dev/tty0 when 'unattended' is absent from the kernel command line.
StandardOutput=journal+console
StandardError=journal+console
TTYPath=/dev/tty0
ExecStart=
ExecStart=/usr/bin/bluefin-sysinstall
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test-installer-artifact_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ setup() {
make_zstd_stub
make_qemu_stub
make_curl_stub
make_sfdisk_stub
}

# The OVMF_CODE lookup (`Justfile:254`, duplicated verbatim at the same
Expand Down Expand Up @@ -135,6 +136,35 @@ exit 0
EOF
chmod +x "${STUB_DIR}/zstd"
}
make_sfdisk_stub() {
cat > "${STUB_DIR}/sfdisk" <<EOF
#!/usr/bin/env bash
echo "sfdisk \$*" >> "${LOG}"
for ((i = 1; i <= \$#; i++)); do
arg="\${!i}"
if [ "\$arg" = "--json" ]; then
cat <<'JSON'
{
"partitiontable": {
"label": "gpt",
"id": "12345678-1234-1234-1234-123456789abc",
"device": "target.raw",
"unit": "sectors",
"partitions": [
{"node": "target.raw1", "start": 2048, "size": 204800, "type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "name": "ESP"},
{"node": "target.raw2", "start": 206848, "size": 8388608, "type": "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709", "name": "bluefin-server-root-a"},
{"node": "target.raw3", "start": 8595456, "size": 8388608, "type": "4D21B016-B534-45C2-A9FB-5C16E091FD2D", "name": "var"}
]
}
}
JSON
exit 0
fi
done
exit 0
EOF
chmod +x "${STUB_DIR}/sfdisk"
}

# make_qemu_stub
#
Expand Down
Loading
Loading