diff --git a/.github/workflows/build-iso-bootc-experimental.yml b/.github/workflows/build-iso-bootc-experimental.yml new file mode 100644 index 0000000..9af3957 --- /dev/null +++ b/.github/workflows/build-iso-bootc-experimental.yml @@ -0,0 +1,80 @@ +name: Build Experimental bootc ISOs + +# Experimental fisherman/bootcDirect ISO variant (resurrected from PR #61, +# reverted in #66; lives under bootc-iso/). Published as clearly-labeled +# workflow artifacts ONLY — deliberately NOT wired into the scheduled or +# production publish workflows or releases, so both installer paths can be +# compared side by side for a while. +on: + workflow_dispatch: + # Temporary: branch-scoped push trigger so the workflow can run before the + # file exists on main (workflow_dispatch only resolves default-branch + # workflows). Remove before merging. + push: + branches: [claude/resurrect-bootc-iso] + paths: ['bootc-iso/**', '.github/workflows/*bootc*.yml'] + +permissions: + contents: read + packages: read + +jobs: + build: + name: Build ${{ matrix.target }} (experimental bootc) + runs-on: ubuntu-24.04 + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + target: [bluefin, bluefin-lts] + defaults: + run: + working-directory: bootc-iso + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Free disk space + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be + with: + tool-cache: true + + - name: Install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y just podman buildah mtools xorriso -qq + + - name: Log in to GHCR + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | \ + sudo podman login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Configure podman storage (intelligent driver selection) + run: bash scripts/configure_podman_storage.sh + + - name: Build ISO + run: | + sudo mkdir -p /var/iso-build + sudo $(command -v just) installer_channel=stable compression=release \ + output_dir=/var/iso-build iso-sd-boot ${{ matrix.target }} + + - name: Rename ISO with experimental-bootc suffix + run: | + mkdir -p output + sudo mv "/var/iso-build/${{ matrix.target }}-live.iso" \ + "output/${{ matrix.target }}-experimental-bootc-x86_64.iso" + sudo chown -R "$USER:$(id -gn)" output/ + sha256sum "output/${{ matrix.target }}-experimental-bootc-x86_64.iso" \ + > "output/${{ matrix.target }}-experimental-bootc-x86_64.iso-CHECKSUM" + + - name: Upload ISO artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }}-experimental-bootc-x86_64 + path: | + bootc-iso/output/${{ matrix.target }}-experimental-bootc-x86_64.iso + bootc-iso/output/${{ matrix.target }}-experimental-bootc-x86_64.iso-CHECKSUM + if-no-files-found: error + retention-days: 14 + compression-level: 0 diff --git a/.github/workflows/test-luks-install-bootc.yml b/.github/workflows/test-luks-install-bootc.yml new file mode 100644 index 0000000..d52d55a --- /dev/null +++ b/.github/workflows/test-luks-install-bootc.yml @@ -0,0 +1,210 @@ +name: LUKS Install End-to-End Test (bootc-iso, experimental) + +# Experimental resurrection of the bootc-installer ISO builder from PR #61 +# (reverted in #66). Lives entirely under bootc-iso/ and is dispatch-only — +# it must never run on pull_request or a schedule. +on: + workflow_dispatch: + # Weekly regression run (matches the cadence from the original #61) so + # LUKS install+unlock coverage does not rot between manual dispatches. + schedule: + - cron: '0 4 * * 1' + # Temporary: branch-scoped push trigger so the workflow can run before the + # file exists on main (workflow_dispatch only resolves default-branch + # workflows). Remove before merging. + push: + branches: [claude/resurrect-bootc-iso] + paths: ['bootc-iso/**', '.github/workflows/*bootc*.yml'] + +permissions: + issues: write + pull-requests: write + contents: write + actions: read + +jobs: + luks-e2e: + name: LUKS E2E (${{ matrix.target }}, ${{ matrix.installer_channel }}) + runs-on: ubuntu-24.04 + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + installer_channel: [stable] + target: [bluefin, bluefin-lts] + defaults: + run: + working-directory: bootc-iso + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Ensure screenshots branch exists + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + run: | + if gh api "/repos/${REPO}/git/refs/heads/ci-screenshots" &>/dev/null; then + echo "ci-screenshots branch already exists" + else + echo "Creating ci-screenshots branch..." + DEFAULT=$(gh api "/repos/${REPO}" --jq '.default_branch') + SHA=$(gh api "/repos/${REPO}/git/refs/heads/${DEFAULT}" --jq '.object.sha') + gh api --method POST "/repos/${REPO}/git/refs" \ + -f "ref=refs/heads/ci-screenshots" \ + -f "sha=${SHA}" + echo "ci-screenshots branch created from ${DEFAULT}" + fi + + - name: Free disk space + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be + with: + tool-cache: true + + - name: Install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y \ + just podman buildah mtools xorriso \ + qemu-system-x86 ovmf socat sshpass \ + imagemagick -qq + + - name: Log in to GHCR + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | \ + sudo podman login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Configure podman storage (intelligent driver selection) + run: bash scripts/configure_podman_storage.sh + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + # Upstream fisherman main now natively supports direct-mode + # `bootc install --source-imgref containers-storage:` (the fix that + # previously lived only in the fix/overlay-driver-for-ostree-bootc-install + # fork branch), so build from main instead of the fork. + - name: Clone fisherman + run: | + git clone https://github.com/projectbluefin/fisherman.git \ + --branch main \ + --depth 1 \ + /tmp/fisherman + + - name: Build debug ISO + id: build + run: | + START=$(date +%s) + sudo mkdir -p /var/iso-build + sudo $(command -v just) debug=1 installer_channel=${{ matrix.installer_channel }} output_dir=/var/iso-build iso-sd-boot ${{ matrix.target }} + mkdir -p output + sudo cp /var/iso-build/*.iso output/ 2>/dev/null || true + sudo chown -R "$USER:$(id -gn)" output/ + echo "duration=$(( $(date +%s) - START ))" >> "$GITHUB_OUTPUT" + ISO=$(ls output/*.iso 2>/dev/null | head -1) + echo "iso_size=$(stat -c%s "$ISO" 2>/dev/null || echo 0)" >> "$GITHUB_OUTPUT" + + - name: Fix output directory ownership + run: sudo chown -R "$USER:$(id -gn)" output/ 2>/dev/null || true + + - name: Run LUKS end-to-end test + id: luks_test + env: + FISHER_REPO: /tmp/fisherman/fisherman + run: | + START=$(date +%s) + just luks-test-qemu ${{ matrix.target }} + echo "duration=$(( $(date +%s) - START ))" >> "$GITHUB_OUTPUT" + continue-on-error: true + + - name: Convert and publish screenshots + if: always() + continue-on-error: true + id: screenshots + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + run: | + sudo chmod a+r /tmp/luks-screenshot-*.ppm /tmp/luks-unlock-snap.ppm 2>/dev/null || true + + commit_png() { + local src_ppm="$1" label="$2" out_var="$3" + local png="/tmp/${label}.png" + + convert "$src_ppm" "$png" 2>/dev/null || return 0 + [[ -f "$png" ]] || return 0 + + local path_in_repo="luks-e2e/${RUN_ID}/${{ matrix.target }}/${{ matrix.installer_channel }}/${label}.png" + local existing_sha + existing_sha=$(gh api "/repos/${REPO}/contents/${path_in_repo}?ref=ci-screenshots" \ + --jq '.sha' 2>/dev/null || echo "") + + local b64_file + b64_file=$(mktemp) + base64 -w0 "$png" > "$b64_file" + + jq -n \ + --arg msg "LUKS E2E screenshot: ${label} (run ${RUN_ID})" \ + --rawfile content "$b64_file" \ + --arg branch "ci-screenshots" \ + --arg sha "$existing_sha" \ + 'if $sha != "" then + {message: $msg, content: ($content | rtrimstr("\n")), branch: $branch, sha: $sha} + else + {message: $msg, content: ($content | rtrimstr("\n")), branch: $branch} + end' | \ + gh api --method PUT "/repos/${REPO}/contents/${path_in_repo}" --input - > /dev/null + + rm "$b64_file" + local url="https://raw.githubusercontent.com/${REPO}/ci-screenshots/${path_in_repo}" + echo "${out_var}=${url}" >> "$GITHUB_OUTPUT" + echo "Published ${label} → ${url}" + } + + commit_png /tmp/luks-screenshot-live.ppm "live-boot" "live_url" + commit_png /tmp/luks-screenshot-plymouth.ppm "plymouth" "plymouth_url" + commit_png /tmp/luks-screenshot-final.ppm "final-boot" "final_url" + + - name: Write job summary + if: always() + run: | + RESULT="${{ steps.luks_test.outcome }}" + CHANNEL="${{ matrix.installer_channel }}" + TARGET="${{ matrix.target }}" + ICON=$( [ "$RESULT" = "success" ] && echo "PASS" || echo "FAIL" ) + { + echo "## ${ICON} LUKS End-to-End Test (${TARGET}, ${CHANNEL}) — ${RESULT}" + echo "" + echo "| Step | Value |" + echo "|------|-------|" + echo "| ISO size | $(numfmt --to=iec ${{ steps.build.outputs.iso_size }} 2>/dev/null || echo N/A) |" + echo "| Build time | ${{ steps.build.outputs.duration }}s |" + echo "| LUKS test time | ${{ steps.luks_test.outputs.duration }}s |" + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload serial logs + if: always() + run: | + sudo chmod a+r /tmp/bluefin-qemu-*.log 2>/dev/null || true + + - name: Upload serial logs artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: luks-e2e-serial-logs-${{ matrix.target }}-${{ matrix.installer_channel }} + path: | + /tmp/bluefin-qemu-live-serial.log + /tmp/bluefin-qemu-installed-serial.log + if-no-files-found: warn + retention-days: 14 + + - name: Fail if LUKS test failed + if: steps.luks_test.outcome == 'failure' + run: | + echo "::error::LUKS end-to-end test failed — see serial logs and screenshots above" + exit 1 diff --git a/bootc-iso/Containerfile b/bootc-iso/Containerfile new file mode 100644 index 0000000..9c16be8 --- /dev/null +++ b/bootc-iso/Containerfile @@ -0,0 +1,104 @@ +# Bluefin live ISO installer image +# +# Build with: +# just container bluefin +# +# Three-stage build: +# 1. bluefin-ref — original Bluefin image (provides kernel modules) +# 2. initramfs-builder — Debian: builds a dmsquash-live initramfs against +# Bluefin's kernel modules in its native glibc environment +# 3. final — Bluefin: receives the rebuilt initramfs + live-env setup +# +# Bluefin is Fedora/ostree-based using GRUB2 for the installed system. +# The live ISO uses systemd-boot for ESP boot (installed in the final stage). +# The installed system's bootloader is controlled by fisherman/bootc-installer +# via images.json (grub2). +# +# The initramfs is built in a separate Debian stage so no cross-distro binary +# grafting is needed; only the initramfs.img output crosses the stage boundary. + +# Base image — override to build bluefin-lts or other variants. +# Example: podman build --build-arg BASE_IMAGE=ghcr.io/ublue-os/bluefin-lts:latest ... +ARG BASE_IMAGE=ghcr.io/ublue-os/bluefin:stable + +# ── Stage 1: Bluefin reference (kernel modules source) ─────────────────────── +FROM ${BASE_IMAGE} AS bluefin-ref + +# ── Stage 2: Debian — builds the dmsquash-live initramfs ───────────────────── +# Dracut runs natively in Debian against Bluefin's kernel modules. +# Only /tmp/initramfs.img crosses into the final stage. +FROM debian:sid AS initramfs-builder + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + dracut \ + dmsetup \ + && rm -rf /var/lib/apt/lists/* + +# Import Bluefin's kernel module tree so dracut targets the correct kernel +COPY --from=bluefin-ref /usr/lib/modules /usr/lib/modules + +# Add Bluefin-specific initramfs support for Ventoy/file-backed ISO boot. +COPY src/dracut/95bluefin-isofile /usr/lib/dracut/modules.d/95bluefin-isofile + +RUN set -ex; \ + kernel=$(ls /usr/lib/modules | sort -V | tail -1); \ + echo "Building dmsquash-live initramfs for kernel ${kernel}"; \ + # Check which optional drivers are available (el10 kernel may lack ntfs3). + NTFS3=""; test -f "/usr/lib/modules/${kernel}/kernel/fs/ntfs3/ntfs3.ko" && NTFS3="ntfs3"; \ + DRACUT_NO_XATTR=1 dracut -v --force --zstd --reproducible --no-hostonly \ + --add "dmsquash-live bluefin-isofile" \ + --add-drivers "squashfs overlay loop iso9660 sr_mod cdrom sd_mod usb-storage xhci-pci exfat vfat fat ${NTFS3} ext4" \ + /tmp/initramfs.img "${kernel}"; \ + ls -lh /tmp/initramfs.img + +# ── Stage 3: Final Bluefin live image ──────────────────────────────────────── +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +# Set to "dev" to pull the tuna-installer dev build (continuous-dev release) +# instead of the stable continuous build. +ARG INSTALLER_CHANNEL=stable +ENV INSTALLER_CHANNEL=${INSTALLER_CHANNEL} + +# DEBUG=1 builds a debug ISO (installer only, SSH enabled). +ARG DEBUG=0 +ENV DEBUG=${DEBUG} + +# Filesystem for the installed system: btrfs (Bluefin stable) or xfs (Bluefin LTS). +# Override via: --build-arg FILESYSTEM=xfs +ARG FILESYSTEM=btrfs + +# Install systemd-boot for the live ISO ESP (Bluefin ships GRUB2 for the +# installed system, but the live ISO needs a UEFI bootloader on the ESP image). +# systemd-boot-unsigned is the Fedora package; use rpm-ostree to layer it. +# fuse-overlayfs provides overlay-on-overlay for kernels without native support +# (e.g. CentOS Stream 10 in bluefin-lts — containers/storage needs it on +# overlayfs-based rootfs). +RUN rpm-ostree install --apply-live --allow-inactive systemd-boot-unsigned fuse-overlayfs \ + && rm -rf /var/cache/rpm-ostree + +# Replace the OCI-mode initramfs with the dmsquash-live initramfs from stage 2 +COPY --from=initramfs-builder /tmp/initramfs.img /tmp/initramfs.img +RUN kernel=$(ls /usr/lib/modules | sort -V | tail -1) && \ + mv /tmp/initramfs.img "/usr/lib/modules/${kernel}/initramfs.img" && \ + echo "Replaced initramfs for kernel ${kernel}" + +# ── Flatpak install layer ───────────────────────────────────────────────────── +COPY src/flatpaks /tmp/flatpaks-list +RUN --mount=type=bind,source=src,target=/src \ + --mount=type=cache,target=/var/cache/flatpak-dl,id=bluefin-flatpak \ + /src/install-flatpaks.sh + +# ── Live-environment configure layer ───────────────────────────────────────── +COPY src/ /tmp/src/ +RUN chmod +x /tmp/src/configure-live.sh && /tmp/src/configure-live.sh + +ARG BASE_IMAGE +ARG FILESYSTEM +# Patch installer configs to reference the actual base image + filesystem for this variant. +RUN sed -i "s|ghcr.io/ublue-os/bluefin:stable|${BASE_IMAGE}|g" \ + /etc/bootc-installer/images.json \ + /etc/bootc-installer/recipe.json && \ + sed -i 's|"filesystem": "btrfs"|"filesystem": "${FILESYSTEM}"|g' \ + /etc/bootc-installer/images.json diff --git a/bootc-iso/Containerfile.builder b/bootc-iso/Containerfile.builder new file mode 100644 index 0000000..161d701 --- /dev/null +++ b/bootc-iso/Containerfile.builder @@ -0,0 +1,28 @@ +# ISO assembly builder image (Debian-based) +# +# Used by: just iso-sd-boot +# +# This container has all the tools needed to assemble a UEFI live ISO: +# xorriso — ISO-9660 creation with El Torito EFI boot entry +# mksquashfs — compress the live rootfs into a squashfs image +# mkfs.fat — create the FAT ESP image for systemd-boot +# mtools — populate the FAT image without requiring a loop mount +# implantisomd5 — embed MD5 checksum for ISO integrity verification +# +# All tools run in their native Debian environment; no cross-distro binary +# grafting required. +FROM debian:sid + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + xorriso \ + isomd5sum \ + squashfs-tools \ + dosfstools \ + mtools \ + && rm -rf /var/lib/apt/lists/* + +COPY src/build-iso.sh /build-iso.sh +RUN chmod +x /build-iso.sh + +ENTRYPOINT ["/build-iso.sh"] diff --git a/bootc-iso/HANDOFF.md b/bootc-iso/HANDOFF.md new file mode 100644 index 0000000..283449a --- /dev/null +++ b/bootc-iso/HANDOFF.md @@ -0,0 +1,172 @@ +# Bluefin bootc-ISO — Handoff + +This document captures the current state of the Bluefin bootc-ISO effort for +another agent or maintainer to pick up, including the architectural differences +from dakota-iso (which works) and the remaining blocker. + +## What this branch does + +PR #61 (`feat/bluefin-bootc-iso`) adds a full ISO builder for Bluefin and +Bluefin LTS using the bootc-installer Flatpak (fisherman) with an ostree +backend. The ISO is live-bootable, supports LUKS-encrypted installation via +fisherman, and is built in CI via GitHub Actions. + +Dakota-ISO exists as a working reference: same toolchain (fisherman, +bootc-installer), same VM-based LUKS E2E test, same QEMU/KVM harness. +The differences are the root cause of the remaining issues. + +## Architectural comparison: bluefin-iso vs dakota-iso + +### 1. Image backend (UNCHANGEABLE) + +| Aspect | Dakota-ISO | Bluefin-ISO | +|--------|------------|-------------| +| Base image | `ghcr.io/projectbluefin/dakota:latest` | `ghcr.io/ublue-os/bluefin:stable` / `...bluefin:lts` | +| Backend | composefs-native | ostree | +| Installed bootloader | systemd-boot | GRUB2 | +| `images.json` `composefs` | `true` | absent | +| `images.json` `needs_user_creation` | `false` | `true` | +| Filesystem | btrfs | btrfs (bluefin), xfs (bluefin-lts) | + +Bluefin IS ostree — this cannot change. All the memory and deployment +differences flow from this. + +### 2. Install flow (CURRENT / TRIED) + +Dakota uses `"image": "containers-storage:..."` in the fisherman recipe with +`composeFsBackend: true`. Fisherman's composefs path: +1. Exports the image to an OCI layout via skopeo +2. Runs `podman --root --storage-driver overlay --tmpfs /var/tmp ... oci: bootc install --composefs-backend ...` +3. Works reliably at 8 GB VM RAM + +Bluefin has tried several approaches: + +| Approach | Result | Why | +|----------|--------|-----| +| `containers-storage:` recipe + VFS (original) | OOM | VFS copies every layer | +| Registry pull + VFS (be4f757) | OOM | Same VFS issue | +| Registry + overlay redirect + OCI layout (1b70f55..266b4fb) | OOM at podman run | Podman container setup ate 14.9 GB virtual | +| Empty image → bootcDirect (58c8ed2) | `bootc install` fails | Needs `--source-imgref` | +| bootcDirect + `--source-imgref docker://` (625ab3b) | untested | Would require network pull (offline VM) | +| bootcDirect + `--source-imgref containers-storage:` (24d15db) | **PENDING CI** | Most promising — no podman, no network | + +### 3. Justfile recipe differences (luks-install-qemu) + +```json +// Dakota recipe (WORKS): +{"image": "containers-storage:ghcr.io/projectbluefin/dakota:latest", + "composeFsBackend": true, + "bootloader": "systemd"} + +// Bluefin recipe (CURRENT — awaiting CI): +{"image": "", + "targetImgref": "ghcr.io/ublue-os/bluefin:stable", + "composeFsBackend": false, + "bootloader": "grub2"} +``` + +### 4. QEMU VM RAM + +| | Dakota | Bluefin (currently) | +|---|---|---| +| Live ISO QEMU | 8 GB | 8 GB (was bumped to 12 GB, reverted) | +| Installed disk QEMU | 8 GB | 8 GB | +| Second disk (cs-disk) | No | Removed | + +Dakota passes at 8 GB. Bluefin's ostree deployment needs more headroom. +12 GB has been tested but not with the `containers-storage:` transport + +bootcDirect approach. + +### 5. Fisherman fork + +Bluefin needs a forked fisherman +(`projectbluefin/fisherman#fix/overlay-driver-for-ostree-bootc-install`) +because the upstream tuna-os/fisherman doesn't support the `--source-imgref` +flag for the direct (bootcDirect) mode. The fork adds: + +1. `BuildBootcArgs` emits `--source-imgref containers-storage:` for + direct-mode installs (when SourceImgref is empty, TargetImgref is set). +2. `bareImageRef()` is called on target-imgref to strip transport prefixes. +3. The `selectStorageDriver` composefs guard is removed (unused in direct + mode but needed for the container-mode fallback). + +If the `containers-storage:` transport + bootcDirect approach works, these +changes should be upstreamed to tuna-os/fisherman and the forked build step +removed from CI. + +## Current status + +**✅ NEW: offline-capable path working** — run `27702412035`: bluefin + bluefin-stable PASSED +with `--source-imgref containers-storage:ghcr.io/ublue-os/bluefin:stable` (containers-storage +transport) + bootcDirect at 8 GB VM RAM. No squash, no second disk, no podman container, +no network pull. The image is read from the embedded squashfs at `/usr/lib/containers/storage`. + +**Bluefin-lts:** pre-existing dracut build failure (kernel `6.12.0-228.el10` in Debian +initramfs-builder) — unrelated to LUKS test changes. + +**Key insight that made it work:** removing the `podman commit -s` squashing step. +The squashing was added for VFS memory pressure (commit `3b8322b`), but the +containers-storage import now uses overlay driver. Without squashing, ostree +annotations (`ostree.final-diffid`) survive into the embedded store, and bootc +resolves them correctly. + +**Fisherman fork needed:** upstream tuna-os/fisherman lacks the `--source-imgref` +emission for direct mode. The essential patch is ~10 lines in `BuildBootcArgs`. +See PR to upstream. + +**Previous failure chain (resolved):** + +| CI Run | ISO Commit | Fisherman Commit | Failure | +|--------|-----------|-----------------|---------| +| 27684346872 | e4a6039 | d5c3b3e | `Unknown transport 'ostree-unverified-registry'` | +| 27682666045 | 94e2473 | d5c3b3e | `Either --source-imgref must be defined...` | +| 27681019431 | ba3ec5f | d5c3b3e | Same as above | +| 27679316314 | 58c8ed2 | d5c3b3e | Same as above | +| 27677273567 | 50df7d8 | 266b4fb | OOM (12 GB, podman run) | +| 27674960446 | 136ae7d | 266b4fb | OOM (10 GB, podman run) | +| 27673343778 | a9e081b | 266b4fb | OOM (8 GB, podman run) | +| 27670315536 | 8dec7d5 | 266b4fb | OOM (8 GB, podman pull) | + +## Files changed + +### `projectbluefin/iso` (PR #61, branch `feat/bluefin-bootc-iso`) + +| File | Change | +|------|--------| +| `justfile` | Added `fisher_repo` var, rebuilt `luks-install-qemu` for bootcDirect, removed second disk and cs-setup.sh | +| `.github/workflows/test-luks-install-bootc.yml` | Added Go setup, fisherman clone, FISHER_REPO env var | +| `bluefin/` | payload_ref, images.json, recipe.json (new variant files) | +| `bluefin-lts/` | Same (bluefin-lts variant) | +| `Containerfile` | 3-stage ISO build (Bluefin + Debian initramfs + final) | +| `src/` | configure-live.sh, build-iso.sh, dracut module, branding assets | + +### `projectbluefin/fisherman` (branch `fix/overlay-driver-for-ostree-bootc-install`) + +| File | Change | +|------|--------| +| `internal/install/bootc.go` | `BuildBootcArgs`: emits `--source-imgref containers-storage:` for direct mode; `bareImageRef` on target-imgref | +| `internal/install/storage_driver.go` | Removed composefs-only guard from `selectStorageDriver`; removed btrfs from unsafeFS list | +| `internal/install/bootc_test.go` | New tests for direct-mode args, OCI export guards | +| `internal/install/storage_driver_test.go` | Updated for new `selectStorageDriver` sig | +| `internal/install/storage_driver_loopback_test.go` | Same | + +## Open questions + +1. ~~Does `--source-imgref containers-storage:ghcr.io/ublue-os/bluefin:stable` work~~ + **RESOLVED** — works with bootcDirect at 8 GB when squashing is removed. + +2. ~~Is 8 GB enough for ostree bootcDirect?~~ **RESOLVED** — 8 GB is sufficient. + bootcDirect avoids podman's container runtime overhead entirely. + +3. **Cleanup dead patches** — commits `1b70f55` through `ea7987b` in the fisherman + fork (overlay/OCI container-mode patches) should be removed from the branch. + Only the direct-mode `--source-imgref` change + `bareImageRef` fix + tests are + needed. + +4. **Upstream fisherman fix** — the ~10-line `--source-imgref` change in + `BuildBootcArgs` should be submitted as a PR to tuna-os/fisherman. + Once merged, the forked binary build step can be removed from CI. + +5. **bluefin-lts dracut failure** — kernel `6.12.0-228.el10` in the Debian + initramfs-builder causes dracut to fail. Unrelated to LUKS test changes. + Needs a separate Containerfile fix (different dracut version or kernel path). diff --git a/bootc-iso/README.md b/bootc-iso/README.md new file mode 100644 index 0000000..75731de --- /dev/null +++ b/bootc-iso/README.md @@ -0,0 +1,70 @@ +# bootc-iso: experimental bootc-installer ISO builder + +This directory resurrects the bootc-installer ISO builder originally merged in +[PR #61](https://github.com/projectbluefin/iso/pull/61) (by @hanthor) and +reverted in [PR #66](https://github.com/projectbluefin/iso/pull/66). It is +fully self-contained: nothing here touches the Anaconda/titanoboa build system +at the repository root, and its CI workflows run on `workflow_dispatch` only: + +- `.github/workflows/test-luks-install-bootc.yml` — LUKS install E2E in QEMU. +- `.github/workflows/build-iso-bootc-experimental.yml` — builds the + experimental ISOs and uploads them as workflow artifacts named with an + explicit `-experimental-bootc` suffix + (e.g. `bluefin-lts-experimental-bootc-x86_64.iso`). These are deliberately + NOT wired into the scheduled/production publish workflows or releases — + artifacts only, clearly labeled, so the fisherman/bootcDirect path can be + compared against the Anaconda ISOs for a while. + +## What this is + +A live-ISO builder where the installer is **fisherman** (the bootc-installer +Flatpak) performing `bootcDirect` installs from an embedded +containers-storage store: + +- `justfile` — `iso-sd-boot ` builds the ISO; `luks-test-qemu ` + runs the LUKS-encrypted install end-to-end in QEMU (also the CI entry point). +- `Containerfile` — 3-stage build of the live environment (base image + + live-session configuration + fisherman installer). +- `Containerfile.builder` — Debian-based ISO assembly container + (systemd-boot + dmsquash-live, via `src/build-iso.sh`). +- `bluefin/`, `bluefin-lts/` — per-variant config (`payload_ref` with the base + image reference). +- `src/` — live-session configuration (`configure-live.sh`), ISO assembly + (`build-iso.sh`), dracut module (`95bluefin-isofile`), branding, LUKS test + helpers. +- `scripts/configure_podman_storage.sh` — CI helper choosing a podman storage + driver for the runner (was `.github/scripts/` in #61). +- `HANDOFF.md` — detailed engineering handoff notes from the original effort. + +## Why it was reverted (maintainer-confirmed) + +1. **ISO size blowup — no dedupe between live rootfs and embedded container + image.** The ISO carries the OS twice: once as the live squashfs rootfs and + once as the payload image inside containers-storage. With the `vfs` storage + driver the store is flat copies (no layer sharing at all). Switching the + embedded store to the `overlay` driver fought with `ostree`-based + `bootc install`; that was originally patched in the fisherman fork branch + `projectbluefin/fisherman` @ `fix/overlay-driver-for-ostree-bootc-install`. + **Update:** upstream fisherman `main` now natively supports direct-mode + `bootc install --source-imgref containers-storage:...` (the same mechanism + bootc-image-builder uses), so the CI workflow builds fisherman from `main` + and no longer depends on the fork branch. The size/dedupe problem itself + remains unsolved. +2. **bluefin-lts never built** due to a dracut failure — see + [iso issue #63](https://github.com/projectbluefin/iso/issues/63). + +## Intended fix direction + +Move to a **single-copy design**: mount the live rootfs directly out of the +embedded container store (composefs/erofs), so the installer payload and the +live environment share one copy of the OS content instead of duplicating it in +a separate squashfs. That eliminates the dedupe problem structurally rather +than fighting the storage driver. + +## Usage + +```bash +cd bootc-iso +just iso-sd-boot bluefin # build output/bluefin-live.iso +just luks-test-qemu bluefin # LUKS install E2E in QEMU +``` diff --git a/bootc-iso/bluefin-lts/payload_ref b/bootc-iso/bluefin-lts/payload_ref new file mode 100644 index 0000000..2cda6ef --- /dev/null +++ b/bootc-iso/bluefin-lts/payload_ref @@ -0,0 +1 @@ +ghcr.io/ublue-os/bluefin:lts diff --git a/bootc-iso/bluefin/payload_ref b/bootc-iso/bluefin/payload_ref new file mode 100644 index 0000000..f59758c --- /dev/null +++ b/bootc-iso/bluefin/payload_ref @@ -0,0 +1 @@ +ghcr.io/ublue-os/bluefin:stable diff --git a/bootc-iso/justfile b/bootc-iso/justfile new file mode 100644 index 0000000..7fc8e46 --- /dev/null +++ b/bootc-iso/justfile @@ -0,0 +1,777 @@ +image-builder := "image-builder" +image-builder-dev := "image-builder-dev" + +# Output directory for built ISOs and intermediate artifacts. +# Override with: just output_dir=/your/path iso-sd-boot bluefin +output_dir := "output" + +# Working directory for ISO builds where container storage staging +# and the squashfs-root are stored. +# Override with: just workdir=/your/path iso-sd-boot bluefin +workdir := output_dir + +# Set to 1 to enable SSH in the live session for debugging. +# Never use debug=1 for production/release ISOs. +debug := "0" + +# Set to "dev" to pull the bootc-installer dev build (continuous-dev release). +installer_channel := "stable" + +# LUKS passphrase used by luks-install for testing. +luks-passphrase := "testpassphrase" + +# Squashfs compression preset: +# fast (default) — zstd level 3, 128K blocks — quick local builds/CI +# release — zstd level 15, 1M blocks — ~20% smaller, ~5× slower +compression := "fast" + +# Path to the projectbluefin/fisherman repo for building the patched fisherman binary. +fisher_repo := "../fisherman/fisherman" + +# Create an XFS loopback mount at /mnt for faster VFS import. +mount-xfs: + #!/usr/bin/bash + set -euo pipefail + if findmnt -n -o FSTYPE /mnt 2>/dev/null | grep -q '^xfs$'; then + echo "/mnt is already XFS — skipping" + exit 0 + fi + echo "Creating 45G XFS loopback at /mnt..." + IMG="/var/tmp/bluefin-xfs-loopback.img" + truncate -s 0 "${IMG}" + chattr +C "${IMG}" 2>/dev/null || true + fallocate -l 45G "${IMG}" + mkfs.xfs -f "${IMG}" + mount -o loop "${IMG}" /mnt + echo "XFS mounted at /mnt (45G)" + echo "" + echo "Now run your build with workdir on /mnt:" + echo " just workdir=/mnt iso-sd-boot bluefin" + df -h /mnt + +# Build the ISO in the background, detached from the terminal session. +build-bg target: + #!/usr/bin/bash + set -euo pipefail + mkdir -p {{ output_dir }} + LOG=$(realpath {{ output_dir }})/build.log + echo "Starting background build → ${LOG}" + setsid \ + debug={{ debug }} \ + installer_channel={{ installer_channel }} \ + output_dir={{ output_dir }} \ + compression={{ compression }} \ + just iso-sd-boot {{ target }} \ + > "${LOG}" 2>&1 & + disown $! + echo "Build PID $! — tailing log (Ctrl-C is safe, build continues)" + tail -f "${LOG}" + +# Helper: returns "--bootc-installer-payload-ref " or "" if no payload_ref file +_payload_ref_flag target: + @if [ -f "{{ target }}/payload_ref" ]; then echo "--bootc-installer-payload-ref $(cat '{{ target }}/payload_ref' | tr -d '[:space:]')"; fi + +# Map target to filesystem: bluefin=btrfs, bluefin-lts=xfs. Default=btrfs. +_filesystem_for target: + @if [ "{{ target }}" = "bluefin-lts" ]; then echo "xfs"; else echo "btrfs"; fi + +container target: + @test -f "{{ target }}/payload_ref" || { echo "ERROR: {{ target }}/payload_ref not found — create it with the base image reference, e.g.: echo 'ghcr.io/ublue-os/bluefin:stable' > {{ target }}/payload_ref"; exit 1; } + podman build --cap-add sys_admin --security-opt label=disable \ + --layers \ + --build-arg DEBUG={{ debug }} \ + --build-arg INSTALLER_CHANNEL={{ installer_channel }} \ + --build-arg BASE_IMAGE=$(cat {{ target }}/payload_ref | tr -d '[:space:]') \ + --build-arg FILESYSTEM=$(just _filesystem_for {{ target }}) \ + -t {{ target }}-installer -f ./Containerfile . + +# Build the Debian-based ISO assembly container for the given target. +iso-builder target: + podman build --security-opt label=disable -t {{ target }}-iso-builder \ + -f ./Containerfile.builder . + +# Build a UEFI live ISO for the given target using systemd-boot and dmsquash-live. +# +# Uses a two-container approach: +# 1. localhost/-installer — the live environment (3-stage Containerfile) +# 2. localhost/-iso-builder — Debian ISO assembly tools (Containerfile.builder) +# +# Output: output/-live.iso +iso-sd-boot target: + #!/usr/bin/bash + set -euo pipefail + PAYLOAD_IMAGE=$(cat "{{ target }}/payload_ref" | tr -d '[:space:]') + + mkdir -p {{ output_dir }} + OUTPUT_DIR=$(realpath "{{ output_dir }}") + WORKDIR=$(realpath "{{ workdir }}") + + echo "=== Disk space before container build ===" + df -h "${OUTPUT_DIR}" + + if ! findmnt -n -o FSTYPE -T "${WORKDIR}" 2>/dev/null | grep -qE '^(xfs|btrfs)$'; then + echo "Hint: $WORKDIR is not an XFS/BTRFS mount. For faster VFS import, run:" >&2 + echo " sudo just mount-xfs" >&2 + echo " sudo just workdir=/mnt iso-sd-boot {{ target }}" >&2 + fi + + AVAILABLE_KB=$(df --output=avail -B1024 "${OUTPUT_DIR}" | tail -1 | tr -d ' ') + REQUIRED_KB=$((20 * 1024 * 1024)) + if [ "$AVAILABLE_KB" -lt "$REQUIRED_KB" ]; then + echo "WARNING: Only $(( AVAILABLE_KB / 1024 / 1024 ))GB free on $(df --output=target "${OUTPUT_DIR}" | tail -1) — ISO output needs ~5GB, full build needs more" >&2 + fi + podman images --format "table {{{{.Repository}}}}\t{{{{.Tag}}}}\t{{{{.Size}}}}" 2>/dev/null || true + + just debug={{ debug }} installer_channel={{ installer_channel }} container {{ target }} + + echo "=== Disk space after container build ===" + df -h "${OUTPUT_DIR}" + podman images --format "table {{{{.Repository}}}}\t{{{{.Tag}}}}\t{{{{.Size}}}}" 2>/dev/null || true + + podman rmi debian:sid 2>/dev/null || true + podman image prune -f 2>/dev/null || true + echo "=== Disk space after intermediate cleanup ===" + df -h "${OUTPUT_DIR}" + + if [[ $(id -u) -eq 0 ]]; then + _ns() { bash -c "$1"; } + else + _ns() { podman unshare bash -c "$1"; } + fi + + SQUASHFS="${OUTPUT_DIR}/{{ target }}-rootfs.sfs" + BOOT_TAR="${OUTPUT_DIR}/{{ target }}-boot-files.tar" + CS_STAGING="${WORKDIR}/{{ target }}-cs-staging" + SQUASHFS_ROOT="${WORKDIR}/{{ target }}-sfs-root" + trap "rm -f '${SQUASHFS}' '${BOOT_TAR}' '${OUTPUT_DIR}/{{ target }}-payload.oci.tar' 2>/dev/null || true" EXIT + echo "=== Disk space before squashfs assembly ===" + df -h "${OUTPUT_DIR}" + if [[ "$WORKDIR" != "$OUTPUT_DIR" ]]; then + df -h "${WORKDIR}" + fi + echo "Building squashfs and boot tar from localhost/{{ target }}-installer..." + _ns " + set -euo pipefail + + SQUASHFS_ROOT='${SQUASHFS_ROOT}' + CS_STAGING='${CS_STAGING}' + OVERLAY_UPPER=\$(mktemp -d \"\${SQUASHFS_ROOT}_upper_XXXXXX\") + OVERLAY_WORK=\$(mktemp -d \"\${SQUASHFS_ROOT}_work_XXXXXX\") + + ns_cleanup() { + umount \"\${SQUASHFS_ROOT}/usr/lib/containers/storage\" 2>/dev/null || true + umount \"\${SQUASHFS_ROOT}\" 2>/dev/null || true + podman image unmount localhost/{{ target }}-installer 2>/dev/null || true + rm -rf \"\${OVERLAY_UPPER}\" \"\${OVERLAY_WORK}\" 2>/dev/null || true + rm -rf \"\${CS_STAGING}\" \"\${SQUASHFS_ROOT}\" 2>/dev/null || true + } + trap ns_cleanup EXIT + + MOUNT=\$(podman image mount localhost/{{ target }}-installer) + PATH=/usr/sbin:/usr/bin:/home/linuxbrew/.linuxbrew/bin:\$PATH + + PAYLOAD_OCI='${OUTPUT_DIR}/{{ target }}-payload.oci.tar' + SQUASHFS_STORAGE=\"\${CS_STAGING}/usr/lib/containers/storage\" + STORAGE_CONF=\"\$(mktemp '${OUTPUT_DIR}'/live-storage-XXXXXX.conf)\" + mkdir -p \"\${SQUASHFS_STORAGE}\" + printf '[storage]\ndriver = \"overlay\"\nrunroot = \"/tmp/cs-runroot\"\ngraphroot = \"/vfs-storage\"\n' \ + > \"\${STORAGE_CONF}\" + + podman save -o \"\${PAYLOAD_OCI}\" --format oci-archive '"${PAYLOAD_IMAGE}"' + + + echo 'Importing Bluefin OCI image into squashfs containers-storage...' + echo '=== Disk space before VFS import ===' + df -h '${OUTPUT_DIR}' + if [[ '$WORKDIR' != '$OUTPUT_DIR' ]]; then + df -h '${WORKDIR}' + fi + podman run --rm \ + --privileged \ + -v \"\${PAYLOAD_OCI}:/payload.oci.tar:ro\" \ + -v \"\${SQUASHFS_STORAGE}:/vfs-storage\" \ + -v \"\${STORAGE_CONF}:/tmp/st.conf:ro\" \ + localhost/{{ target }}-installer \ + sh -c 'mkdir -p /tmp/cs-runroot /var/tmp && CONTAINERS_STORAGE_CONF=/tmp/st.conf skopeo copy oci-archive:/payload.oci.tar:'"${PAYLOAD_IMAGE}"' containers-storage:'"${PAYLOAD_IMAGE}"'' + + rm -f \"\${PAYLOAD_OCI}\" \"\${STORAGE_CONF}\" + + echo '=== Disk space after VFS import ===' + df -h '${OUTPUT_DIR}' + if [[ '$WORKDIR' != '$OUTPUT_DIR' ]]; then + df -h '${WORKDIR}' + fi + du -sh \"\${CS_STAGING}\" 2>/dev/null || true + + echo 'Building unified squashfs source tree using bind mounts...' + mkdir -p \"\${SQUASHFS_ROOT}\" + + FS_TYPE=\$(findmnt -n -o FSTYPE -T \"\${SQUASHFS_ROOT}\" 2>/dev/null || echo \"unknown\") + if [[ \"\${FS_TYPE}\" == \"xfs\" || \"\${FS_TYPE}\" == \"ext4\" ]]; then + echo \"Filesystem is \${FS_TYPE}, trying overlay\" + if ! mount -t overlay overlay \ + -o lowerdir=\"\${MOUNT}\",upperdir=\"\${OVERLAY_UPPER}\",workdir=\"\${OVERLAY_WORK}\" \"\${SQUASHFS_ROOT}\"; then + echo \"Overlay mount failed on \${FS_TYPE}; falling back to cp -a\" + cp -a \"\${MOUNT}/.\" \"\${SQUASHFS_ROOT}/\" + fi + else + echo \"Filesystem is \${FS_TYPE}, doing it the boring way\" + cp -a \"\${MOUNT}/.\" \"\${SQUASHFS_ROOT}/\" + fi + + mkdir -p \"\${SQUASHFS_ROOT}/usr/lib/containers/storage\" + mount --bind \"\${CS_STAGING}/usr/lib/containers/storage\" \"\${SQUASHFS_ROOT}/usr/lib/containers/storage\" + echo '=== Disk space after creation of squashfs root ===' + df -h '${OUTPUT_DIR}' + if [[ '$WORKDIR' != '$OUTPUT_DIR' ]]; then + df -h '${WORKDIR}' + fi + du -sh \"\${SQUASHFS_ROOT}\" 2>/dev/null || true + + SFS_LEVEL=3; SFS_BLOCK=131072 + [[ '{{ compression }}' == 'release' ]] && { SFS_LEVEL=15; SFS_BLOCK=1048576; } + mksquashfs \"\${SQUASHFS_ROOT}\" '${SQUASHFS}' \ + -noappend -comp zstd -Xcompression-level \${SFS_LEVEL} -b \${SFS_BLOCK} \ + -processors 4 \ + -e proc -e sys -e dev -e run -e tmp + + tar -C \"\$MOUNT\" \ + -cf '${BOOT_TAR}' \ + ./usr/lib/modules \ + ./usr/lib/systemd/boot/efi + " + + echo "=== Disk space after squashfs, before ISO assembly ===" + df -h "${OUTPUT_DIR}" + du -sh "${SQUASHFS}" "${BOOT_TAR}" 2>/dev/null || true + + TMPDIR="${OUTPUT_DIR}" \ + PATH="/usr/sbin:/usr/bin:/home/linuxbrew/.linuxbrew/bin:${PATH}" \ + bash "src/build-iso.sh" "${BOOT_TAR}" "${SQUASHFS}" "${OUTPUT_DIR}/{{ target }}-live.iso" + + echo "ISO ready: ${OUTPUT_DIR}/{{ target }}-live.iso" + +# ── QEMU and libvirt boot / LUKS testing recipes ───────────────────────────── + +# Boot a built ISO in QEMU via UEFI (OVMF) with serial console output on stdout. +boot-iso-serial target: + #!/usr/bin/bash + set -euo pipefail + QEMU=$(command -v /usr/libexec/qemu-kvm /usr/bin/qemu-kvm \ + /usr/bin/qemu-system-x86_64 \ + /home/linuxbrew/.linuxbrew/bin/qemu-system-x86_64 2>/dev/null | head -1) + [[ -z "$QEMU" ]] && { echo "qemu-kvm / qemu-system-x86_64 not found" >&2; exit 1; } + ISO=$(ls \ + {{ output_dir }}/{{ target }}-live.iso \ + output/bootiso/install.iso \ + output/bootc-{{ target }}*.iso \ + 2>/dev/null | head -1 || true) + if [[ -z "$ISO" ]]; then + echo "No ISO found for '{{ target }}' — run: just iso-sd-boot {{ target }}" >&2 + exit 1 + fi + + OVMF_CODE="" + for f in \ + /usr/share/OVMF/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE.fd \ + /usr/share/edk2-ovmf/x64/OVMF_CODE.fd \ + /usr/share/ovmf/OVMF.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-x86_64-code.fd \ + /home/linuxbrew/.linuxbrew/Cellar/qemu/11.0.0/share/qemu/edk2-x86_64-code.fd; do + [[ -f "$f" ]] && { OVMF_CODE="$f"; break; } + done + OVMF_VARS_SRC="" + for f in \ + /usr/share/OVMF/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS.fd \ + /usr/share/edk2-ovmf/x64/OVMF_VARS.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-i386-vars.fd; do + [[ -f "$f" ]] && { OVMF_VARS_SRC="$f"; break; } + done + if [[ -z "$OVMF_CODE" ]]; then + echo "OVMF firmware not found — install edk2-ovmf or ovmf" >&2 + exit 1 + fi + + OVMF_VARS=$(mktemp /tmp/OVMF_VARS.XXXXXX.fd) + [[ -n "$OVMF_VARS_SRC" ]] && cp "${OVMF_VARS_SRC}" "${OVMF_VARS}" + trap "rm -f ${OVMF_VARS}" EXIT + + echo "Booting ${ISO} via UEFI — serial console below (Ctrl-A X to quit)" + echo "SSH available on localhost:2222 (user: liveuser, password: live) if built with debug=1" + "$QEMU" \ + -machine q35 \ + -m 4096 \ + -accel kvm \ + -cpu host \ + -smp 4 \ + -drive if=pflash,format=raw,readonly=on,file="${OVMF_CODE}" \ + -drive if=pflash,format=raw,file="${OVMF_VARS}" \ + -drive if=none,id=live-disk,file="${ISO}",media=cdrom,format=raw,readonly=on \ + -device virtio-scsi-pci,id=scsi \ + -device scsi-cd,drive=live-disk \ + -net nic,model=virtio -net user,hostfwd=tcp::2222-:22 \ + -serial mon:stdio \ + -display none \ + -no-reboot + +# Boot a built ISO in libvirt with UEFI, a target install disk, and SSH via +# the default libvirt network. +boot-libvirt-debug target: + #!/usr/bin/bash + set -euo pipefail + + VM_NAME="bluefin-debug" + VM_RAM=8192 + VM_CPUS=4 + DISK_SIZE=64 + + ISO=$(ls \ + {{ output_dir }}/{{ target }}-live.iso \ + output/bootiso/install.iso \ + output/bootc-{{ target }}*.iso \ + 2>/dev/null | head -1 || true) + if [[ -z "$ISO" ]]; then + echo "No ISO found for '{{ target }}' — run: just debug=1 iso-sd-boot {{ target }}" >&2 + exit 1 + fi + + OVMF_CODE="" + for f in \ + /usr/share/OVMF/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE.fd \ + /usr/share/edk2-ovmf/x64/OVMF_CODE.fd \ + /usr/share/ovmf/OVMF.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-x86_64-code.fd \ + /home/linuxbrew/.linuxbrew/Cellar/qemu/11.0.0/share/qemu/edk2-x86_64-code.fd; do + [[ -f "$f" ]] && { OVMF_CODE="$f"; break; } + done + OVMF_VARS="" + for f in \ + /usr/share/OVMF/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS.fd \ + /usr/share/edk2-ovmf/x64/OVMF_VARS.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-i386-vars.fd; do + [[ -f "$f" ]] && { OVMF_VARS="$f"; break; } + done + if [[ -z "$OVMF_CODE" ]]; then + echo "OVMF firmware not found — install edk2-ovmf or ovmf" >&2 + exit 1 + fi + + sudo cp "$ISO" /var/lib/libvirt/images/${VM_NAME}.iso + + if sudo virsh dominfo "$VM_NAME" &>/dev/null; then + echo "VM '${VM_NAME}' already exists — swapping ISO and rebooting..." + sudo virsh destroy "$VM_NAME" 2>/dev/null || true + CDROM_DEV=$(sudo virsh domblklist "$VM_NAME" \ + | awk 'NR>2 && $2 == "-" {print $1; exit}') + if [[ -z "$CDROM_DEV" ]]; then + CDROM_DEV=$(sudo virsh domblklist "$VM_NAME" \ + | awk 'NR>2 && ($2 ~ /\.iso$/) {print $1; exit}') + fi + sudo virsh change-media "$VM_NAME" "$CDROM_DEV" \ + /var/lib/libvirt/images/${VM_NAME}.iso --force + sudo virsh start "$VM_NAME" + else + echo "Creating libvirt VM: ${VM_NAME} (${VM_RAM}M RAM, ${VM_CPUS} vCPUs, ${DISK_SIZE}G disk)" + sudo virt-install \ + --name "$VM_NAME" \ + --memory "$VM_RAM" --vcpus "$VM_CPUS" \ + --boot loader="${OVMF_CODE}",loader.readonly=yes,loader.type=pflash,nvram.template="${OVMF_VARS}" \ + --cdrom /var/lib/libvirt/images/${VM_NAME}.iso \ + --disk size=${DISK_SIZE},format=qcow2 \ + --network network=default \ + --graphics vnc,listen=127.0.0.1 \ + --os-variant generic \ + --tpm none \ + --noautoconsole + fi + + MAC=$(sudo virsh domiflist "$VM_NAME" | awk '/network/{print $5}') + echo "VM started. MAC: ${MAC}" + echo "Waiting for DHCP lease (this takes 30-90s while the ISO boots)..." + + GUEST_IP="" + for i in $(seq 1 60); do + GUEST_IP=$(sudo virsh net-dhcp-leases default 2>/dev/null \ + | awk -v mac="$MAC" '$3 == mac {split($5, a, "/"); print a[1]}' \ + | head -1) + if [[ -n "$GUEST_IP" ]]; then + break + fi + sleep 3 + done + + if [[ -z "$GUEST_IP" ]]; then + echo "WARNING: No DHCP lease found after 3 minutes." >&2 + echo "Try: sudo virsh net-dhcp-leases default" >&2 + echo "Or: sudo virsh console ${VM_NAME}" >&2 + exit 1 + fi + + echo "" + echo "========================================" + echo " SSH ready:" + echo " ssh liveuser@${GUEST_IP}" + echo " password: live" + echo "========================================" + echo "" + echo "VNC: $(sudo virsh domdisplay ${VM_NAME} 2>/dev/null || echo 'unavailable')" + echo "Serial: sudo virsh console ${VM_NAME}" + echo "Cleanup: sudo virsh destroy ${VM_NAME} && sudo virsh undefine ${VM_NAME} --nvram" + +# Run LUKS encrypted install via fisherman into the running bluefin-debug libvirt VM. +luks-install target: + #!/usr/bin/bash + set -euo pipefail + + VM_NAME="bluefin-debug" + PASSPHRASE="{{ luks-passphrase }}" + DISK="/dev/sda" + PAYLOAD_IMAGE=$(cat "{{ target }}/payload_ref" | tr -d '[:space:]') + SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o ConnectTimeout=5 -o IdentitiesOnly=yes -o PreferredAuthentications=password" + SSH="sshpass -p live ssh $SSH_OPTS" + SCP="sshpass -p live scp $SSH_OPTS" + + MAC=$(sudo virsh domiflist "$VM_NAME" 2>/dev/null | awk '/network/{print $5; exit}') + if [[ -z "$MAC" ]]; then + echo "ERROR: VM '${VM_NAME}' is not running." + echo "Start it first: just debug=1 boot-libvirt-debug {{ target }}" + exit 1 + fi + + GUEST_IP="" + echo "Looking up DHCP lease for ${VM_NAME} (${MAC})..." + for i in $(seq 1 20); do + GUEST_IP=$(sudo virsh net-dhcp-leases default 2>/dev/null \ + | awk -v mac="$MAC" '$3 == mac {split($5, a, "/"); print a[1]}' \ + | head -1) + [[ -n "$GUEST_IP" ]] && break + sleep 3 + done + if [[ -z "$GUEST_IP" ]]; then + echo "ERROR: no DHCP lease found — is the VM fully booted?" + echo "Check: sudo virsh net-dhcp-leases default" + exit 1 + fi + echo "Guest IP: ${GUEST_IP}" + + echo "Waiting for SSH..." + for i in $(seq 1 30); do + $SSH liveuser@"$GUEST_IP" true 2>/dev/null && break + sleep 3 + done + $SSH liveuser@"$GUEST_IP" true || { echo "ERROR: SSH timed out"; exit 1; } + + FILESYSTEM=$(just _filesystem_for "{{ target }}") + RECIPE_TMP=$(mktemp /tmp/luks-recipe-XXXXXX.json) + trap "rm -f '${RECIPE_TMP}'" EXIT + printf '{\n "disk": "%s",\n "filesystem": "%s",\n "image": "%s",\n "composeFsBackend": false,\n "bootloader": "grub2",\n "hostname": "bluefin-luks-test",\n "encryption": {"type": "luks-passphrase", "passphrase": "%s"},\n "flatpaks": []\n}\n' \ + "${DISK}" "${FILESYSTEM}" "${PAYLOAD_IMAGE}" "${PASSPHRASE}" > "${RECIPE_TMP}" + $SCP "${RECIPE_TMP}" liveuser@"$GUEST_IP":/tmp/luks-recipe.json + echo "Uploaded recipe to /tmp/luks-recipe.json" + + echo "Running fisherman install (pulls from registry, takes several minutes)..." + $SSH liveuser@"$GUEST_IP" 'sudo /usr/local/bin/fisherman /tmp/luks-recipe.json' + echo "Install finished." + + CDROM_DEV=$(sudo virsh domblklist "$VM_NAME" \ + | awk 'NR>2 && ($2 ~ /\.iso$/ || $2 == "-") {print $1; exit}') + if [[ -n "$CDROM_DEV" ]]; then + sudo virsh change-media "$VM_NAME" "$CDROM_DEV" --eject --force 2>/dev/null || true + echo "ISO ejected from ${CDROM_DEV}." + else + echo "Warning: could not identify CD-ROM device; eject skipped." + fi + + echo "Rebooting VM into installed system..." + sudo virsh reboot "$VM_NAME" || $SSH liveuser@"$GUEST_IP" 'sudo reboot' || true + + echo "" + echo "========================================" + echo " VM is rebooting into the installed system." + echo " Unlock LUKS: just luks-unlock {{ target }}" + echo " Watch boot: just luks-boot {{ target }}" + echo "========================================" + +# Automate LUKS passphrase entry on the bluefin-debug VM serial console. +luks-unlock target: + #!/usr/bin/bash + VM_NAME="bluefin-debug" + PASSPHRASE="{{ luks-passphrase }}" + if ! sudo virsh domstate "$VM_NAME" 2>/dev/null | grep -q running; then + echo "ERROR: VM '${VM_NAME}' is not running." + echo "Run: just luks-install {{ target }}" + exit 1 + fi + MAC=$(sudo virsh domiflist "$VM_NAME" 2>/dev/null | awk '/network/{print $5; exit}') + if [[ -z "$MAC" ]]; then + echo "ERROR: VM '${VM_NAME}' is not running." + exit 1 + fi + echo "Waiting for Plymouth passphrase prompt (VM MAC: ${MAC})..." + echo "Passphrase: ${PASSPHRASE}" + sudo python3 "src/luks-unlock.py" libvirt "$VM_NAME" "$PASSPHRASE" "$MAC" + +# Connect to the serial console of the bluefin-debug VM. +luks-boot target: + #!/usr/bin/bash + VM_NAME="bluefin-debug" + if ! sudo virsh domstate "$VM_NAME" 2>/dev/null | grep -q running; then + echo "ERROR: VM '${VM_NAME}' is not running." + echo "Run: just luks-install {{ target }}" + exit 1 + fi + echo "Connecting to serial console (detach: Ctrl-])" + echo "At the LUKS passphrase prompt type: {{ luks-passphrase }}" + echo "" + sudo virsh console "$VM_NAME" + +# ── QEMU-native LUKS test (used by CI; mirrors the libvirt recipes) ─────────── + +luks-qemu-disk := "/var/tmp/bluefin-luks-install.qcow2" +luks-qemu-monitor-live := "/tmp/bluefin-qemu-live.sock" +luks-qemu-monitor-installed := "/tmp/bluefin-qemu-installed.sock" +luks-qemu-serial-live := "/tmp/bluefin-qemu-live-serial.log" +luks-qemu-serial-installed := "/tmp/bluefin-qemu-installed-serial.log" +luks-qemu-ssh-port := "2222" +# SSH port forwarded into the installed (post-LUKS-unlock) VM for boot detection. +luks-qemu-ssh-port-installed := "2223" +luks-qemu-ram := "8192" + +# Full end-to-end test: build the ISO then run the LUKS install + boot test. +e2e target: + #!/usr/bin/bash + set -euo pipefail + echo "=== Step 1/2: Building ISO (debug={{ debug }}, installer_channel={{ installer_channel }}) ===" + just debug={{ debug }} installer_channel={{ installer_channel }} output_dir={{ output_dir }} iso-sd-boot {{ target }} + echo "=== Step 2/2: LUKS end-to-end test ===" + sudo rm -f "{{ luks-qemu-disk }}" "{{ luks-qemu-monitor-live }}" "{{ luks-qemu-monitor-installed }}" \ + "{{ luks-qemu-serial-live }}" "{{ luks-qemu-serial-installed }}" + just luks-test-qemu {{ target }} + +# Run the full LUKS end-to-end test in QEMU (CI entry point). +luks-test-qemu target: + #!/usr/bin/bash + set -euo pipefail + just luks-qemu-disk={{ luks-qemu-disk }} luks-boot-qemu-live {{ target }} + just luks-qemu-ssh-port={{ luks-qemu-ssh-port }} luks-install-qemu {{ target }} + just luks-qemu-disk={{ luks-qemu-disk }} \ + luks-qemu-ssh-port-installed={{ luks-qemu-ssh-port-installed }} \ + luks-boot-qemu-installed {{ target }} + just luks-qemu-monitor-installed={{ luks-qemu-monitor-installed }} \ + luks-qemu-serial-installed={{ luks-qemu-serial-installed }} \ + luks-qemu-ssh-port-installed={{ luks-qemu-ssh-port-installed }} \ + luks-unlock-qemu {{ target }} + +# Boot the live ISO in QEMU (daemonized) with a blank install disk attached. +luks-boot-qemu-live target: + #!/usr/bin/bash + set -euo pipefail + QEMU=$(command -v /usr/libexec/qemu-kvm /usr/bin/qemu-kvm \ + /usr/bin/qemu-system-x86_64 \ + /home/linuxbrew/.linuxbrew/bin/qemu-system-x86_64 2>/dev/null | head -1) + [[ -z "$QEMU" ]] && { echo "qemu-kvm / qemu-system-x86_64 not found" >&2; exit 1; } + ISO=$(ls \ + {{ output_dir }}/{{ target }}-live.iso \ + output/bootiso/install.iso \ + output/bootc-{{ target }}*.iso \ + 2>/dev/null | head -1 || true) + if [[ -z "$ISO" ]]; then + echo "No ISO found — run: just debug=1 iso-sd-boot {{ target }}" >&2 + exit 1 + fi + + OVMF_CODE=""; OVMF_VARS="" + for f in /usr/share/OVMF/OVMF_CODE_4M.fd /usr/share/OVMF/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE.fd /usr/share/ovmf/OVMF.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-x86_64-code.fd \ + /home/linuxbrew/.linuxbrew/Cellar/qemu/11.0.0/share/qemu/edk2-x86_64-code.fd; do + [[ -f "$f" ]] && { OVMF_CODE="$f"; break; } + done + for f in /usr/share/OVMF/OVMF_VARS_4M.fd /usr/share/OVMF/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-i386-vars.fd; do + if [[ -f "$f" ]]; then cp "$f" /var/tmp/bluefin-qemu-live-vars.fd; OVMF_VARS=/var/tmp/bluefin-qemu-live-vars.fd; break; fi + done + [[ -z "$OVMF_CODE" ]] && { echo "OVMF firmware not found" >&2; exit 1; } + + [[ -f "{{ luks-qemu-disk }}" ]] || qemu-img create -f qcow2 "{{ luks-qemu-disk }}" 64G + sudo rm -f "{{ luks-qemu-monitor-live }}" "{{ luks-qemu-serial-live }}" + + echo "Booting live ISO: $ISO" + QEMU_ACCEL="-accel kvm" + QEMU_PREFIX="" + if ! test -r /dev/kvm 2>/dev/null; then + if sudo test -r /dev/kvm 2>/dev/null; then + echo "Using sudo for KVM access" + QEMU_PREFIX="sudo" + else + echo "KVM not available, falling back to TCG emulation (slower)" + QEMU_ACCEL="-accel tcg,thread=multi" + QEMU_PREFIX="" + fi + fi + $QEMU_PREFIX "$QEMU" \ + -machine q35 -cpu host -m {{ luks-qemu-ram }} -smp 4 $QEMU_ACCEL \ + -drive "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}" \ + -drive "if=pflash,format=raw,file=${OVMF_VARS}" \ + -drive "if=none,id=iso,file=${ISO},media=cdrom,readonly=on,format=raw" \ + -device virtio-scsi-pci,id=scsi \ + -device scsi-cd,drive=iso \ + -drive "if=none,id=disk,file={{ luks-qemu-disk }},format=qcow2" \ + -device virtio-blk-pci,drive=disk \ + -netdev "user,id=net0,hostfwd=tcp::{{ luks-qemu-ssh-port }}-:22" \ + -device virtio-net-pci,netdev=net0 \ + -monitor "unix:{{ luks-qemu-monitor-live }},server,nowait" \ + -serial "file:{{ luks-qemu-serial-live }}" \ + -display none \ + -daemonize + echo "Live QEMU started (monitor: {{ luks-qemu-monitor-live }})" + + SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o ConnectTimeout=5 -o PreferredAuthentications=password" + echo "Waiting for live environment on port {{ luks-qemu-ssh-port }}..." + for i in $(seq 1 60); do + if sudo grep -q "BLUEFIN_LIVE_READY" "{{ luks-qemu-serial-live }}" 2>/dev/null; then + echo "Live environment ready (serial marker seen)" + break + fi + if sshpass -p live ssh $SSH_OPTS liveuser@127.0.0.1 -p {{ luks-qemu-ssh-port }} true 2>/dev/null; then + echo "Live environment ready (SSH connected)" + break + fi + [[ "$i" -eq 60 ]] && { echo "ERROR: live env not ready after 5m"; sudo tail -30 "{{ luks-qemu-serial-live }}" || true; exit 1; } + sleep 5 + done + + echo "Live environment ready. Waiting 25s for GUI to fully render..." + sleep 25 + sudo socat - "UNIX-CONNECT:{{ luks-qemu-monitor-live }}" \ + <<< "screendump /tmp/luks-screenshot-live.ppm" 2>/dev/null || true + +# Run fisherman LUKS install via SSH into the live QEMU VM. +luks-install-qemu target: + #!/usr/bin/bash + set -euo pipefail + PASSPHRASE="{{ luks-passphrase }}" + DISK="/dev/vda" + PAYLOAD_IMAGE=$(cat "{{ target }}/payload_ref" | tr -d '[:space:]') + SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o ConnectTimeout=5 -o PreferredAuthentications=password -o ServerAliveInterval=30 -o ServerAliveCountMax=20" + SSH="sshpass -p live ssh $SSH_OPTS liveuser@127.0.0.1 -p {{ luks-qemu-ssh-port }}" + SCP="sshpass -p live scp $SSH_OPTS -P {{ luks-qemu-ssh-port }}" + + FILESYSTEM=$(just _filesystem_for "{{ target }}") + RECIPE_TMP=$(mktemp /tmp/luks-recipe-XXXXXX.json) + trap "rm -f '${RECIPE_TMP}'" EXIT + # Empty image triggers bootcDirect: fisherman runs `bootc install + # to-filesystem` natively on the live ISO (which IS the Bluefin image). + # No podman, no OCI export, no overlay, no RAM issues. + # target_imgref tells bootc what to track for day-2 updates. + printf '{\n "disk": "%s",\n "filesystem": "%s",\n "image": "",\n "targetImgref": "%s",\n "composeFsBackend": false,\n "bootloader": "grub2",\n "hostname": "bluefin-luks-test",\n "encryption": {"type": "luks-passphrase", "passphrase": "%s"},\n "flatpaks": []\n}\n' \ + "${DISK}" "${FILESYSTEM}" "${PAYLOAD_IMAGE}" "${PASSPHRASE}" > "${RECIPE_TMP}" + $SCP "${RECIPE_TMP}" liveuser@127.0.0.1:/tmp/luks-recipe.json + + # Use the fisherman already installed on the live ISO (Flatpak). + # bootcDirect doesn't need any of our patches — it runs bootc natively. + # Build patched fisherman for the direct-mode --source-imgref fix. + FISHER_REPO="${FISHER_REPO:-{{ fisher_repo }}}" + FISHERMAN_BIN=$(mktemp /tmp/fisherman-XXXXXX) + trap "rm -f '${RECIPE_TMP}' '${FISHERMAN_BIN}'" EXIT + (cd "${FISHER_REPO}" && CGO_ENABLED=0 go build -o "${FISHERMAN_BIN}" ./cmd/fisherman/) + $SCP "${FISHERMAN_BIN}" liveuser@127.0.0.1:/tmp/fisherman + $SSH 'chmod +x /tmp/fisherman' + echo "Running fisherman (direct bootc install, takes several minutes)..." + if ! $SSH 'sudo /tmp/fisherman /tmp/luks-recipe.json'; then + echo "=== INSTALL FAILURE DIAGNOSTICS ===" + echo "--- dmesg ---" + $SSH 'sudo dmesg | tail -n 100' || true + echo "--- journalctl ---" + $SSH 'sudo journalctl -n 100 --no-pager' || true + echo "--- systemd-oomd status ---" + $SSH 'sudo systemctl status systemd-oomd --no-pager' || true + echo "--- podman system info ---" + $SSH 'sudo podman info' || true + exit 1 + fi + echo "Install complete. Shutting down live QEMU..." + echo "system_powerdown" | sudo socat - "UNIX-CONNECT:{{ luks-qemu-monitor-live }}" 2>/dev/null || true + sleep 5 + echo "quit" | sudo socat - "UNIX-CONNECT:{{ luks-qemu-monitor-live }}" 2>/dev/null || true + +# Boot the installed disk in QEMU (no ISO). Called after luks-install-qemu. +luks-boot-qemu-installed target: + #!/usr/bin/bash + set -euo pipefail + QEMU=$(command -v /usr/libexec/qemu-kvm /usr/bin/qemu-kvm \ + /usr/bin/qemu-system-x86_64 \ + /home/linuxbrew/.linuxbrew/bin/qemu-system-x86_64 2>/dev/null | head -1) + [[ -z "$QEMU" ]] && { echo "qemu-kvm / qemu-system-x86_64 not found" >&2; exit 1; } + OVMF_CODE=""; OVMF_VARS="" + for f in /usr/share/OVMF/OVMF_CODE_4M.fd /usr/share/OVMF/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE.fd /usr/share/ovmf/OVMF.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-x86_64-code.fd \ + /home/linuxbrew/.linuxbrew/Cellar/qemu/11.0.0/share/qemu/edk2-x86_64-code.fd; do + [[ -f "$f" ]] && { OVMF_CODE="$f"; break; } + done + for f in /usr/share/OVMF/OVMF_VARS_4M.fd /usr/share/OVMF/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-i386-vars.fd; do + if [[ -f "$f" ]]; then cp "$f" /var/tmp/bluefin-qemu-installed-vars.fd; OVMF_VARS=/var/tmp/bluefin-qemu-installed-vars.fd; break; fi + done + [[ -z "$OVMF_CODE" ]] && { echo "OVMF firmware not found" >&2; exit 1; } + + sudo rm -f "{{ luks-qemu-monitor-installed }}" "{{ luks-qemu-serial-installed }}" + + echo "Booting installed disk: {{ luks-qemu-disk }}" + QEMU_ACCEL="-accel kvm" + QEMU_PREFIX="" + if ! test -r /dev/kvm 2>/dev/null; then + if sudo test -r /dev/kvm 2>/dev/null; then + echo "Using sudo for KVM access" + QEMU_PREFIX="sudo" + else + echo "KVM not available, falling back to TCG emulation (slower)" + QEMU_ACCEL="-accel tcg,thread=multi" + QEMU_PREFIX="" + fi + fi + $QEMU_PREFIX "$QEMU" \ + -machine q35 -cpu host -m {{ luks-qemu-ram }} -smp 4 $QEMU_ACCEL \ + -drive "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}" \ + -drive "if=pflash,format=raw,file=${OVMF_VARS}" \ + -drive "if=none,id=disk,file={{ luks-qemu-disk }},format=qcow2" \ + -device virtio-blk-pci,drive=disk \ + -netdev "user,id=net0,hostfwd=tcp::{{ luks-qemu-ssh-port-installed }}-:22" \ + -device virtio-net-pci,netdev=net0 \ + -monitor "unix:{{ luks-qemu-monitor-installed }},server,nowait" \ + -serial "file:{{ luks-qemu-serial-installed }}" \ + -display none \ + -daemonize + echo "Installed QEMU started (monitor: {{ luks-qemu-monitor-installed }})" + + for i in $(seq 1 15); do + [[ -S "{{ luks-qemu-monitor-installed }}" ]] && break + sleep 2 + done + +# Send LUKS passphrase to installed QEMU VM via monitor screendump + sendkey. +# luks-qemu-ssh-port-installed: forwarded SSH port for boot-completion detection +# (0 = disabled, use framebuffer fallback only) +luks-unlock-qemu target: + #!/usr/bin/bash + set -euo pipefail + PASSPHRASE="{{ luks-passphrase }}" + echo "Unlocking LUKS on installed QEMU VM..." + echo "Passphrase: ${PASSPHRASE}" + sudo python3 "src/luks-unlock.py" qemu \ + "{{ luks-qemu-monitor-installed }}" \ + "$PASSPHRASE" \ + "{{ luks-qemu-serial-installed }}" \ + "{{ luks-qemu-ssh-port-installed }}" + + for label in "Plymouth prompt" "Final boot"; do + key=$(echo "$label" | tr ' ' '-' | tr '[:upper:]' '[:lower:]') + bash "src/show-screenshot.sh" "/tmp/luks-screenshot-${key}.ppm" "$label" || true + done diff --git a/bootc-iso/scripts/configure_podman_storage.sh b/bootc-iso/scripts/configure_podman_storage.sh new file mode 100755 index 0000000..d565bd0 --- /dev/null +++ b/bootc-iso/scripts/configure_podman_storage.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 +# Configure podman storage driver intelligently based on available filesystem +# Clears existing podman storage to avoid database mismatch errors + +set -eo pipefail + +# Stop podman if running +sudo podman rm -fa 2>/dev/null || true +sudo podman rmi -a 2>/dev/null || true + +# Clear existing podman storage database to avoid driver mismatch +# This is safe in CI where we start fresh each run +echo "Clearing podman storage database..." +if command -v podman &> /dev/null; then + sudo podman system reset -f 2>/dev/null || { + # Fallback if podman system reset isn't available + sudo rm -rf /var/lib/containers/storage.lock 2>/dev/null || true + sudo rm -rf /run/containers/storage.lock 2>/dev/null || true + echo "Warning: podman system reset not available, tried lock file cleanup as fallback" + } +else + echo "Podman not installed, skipping reset" +fi + +# Detect filesystem type at /var/lib/containers (where BTRFS loopback is mounted) +# Use findmnt to reliably detect filesystem (stat --file-system returns "ext2/ext3" for ext4) +if [ -d /var/lib/containers ]; then + FS_TYPE=$(findmnt -n -o FSTYPE -T /var/lib/containers 2>/dev/null || echo "unknown") +else + FS_TYPE=$(findmnt -n -o FSTYPE -T /var/lib 2>/dev/null || echo "unknown") +fi + +echo "Detected filesystem for /var/lib/containers: $FS_TYPE" + +# Choose driver based on filesystem (native drivers preferred for COW efficiency) +case "$FS_TYPE" in + btrfs) + DRIVER="btrfs" + echo "Using btrfs driver (native COW support on BTRFS filesystem)" + ;; + zfs) + DRIVER="zfs" + echo "Using zfs driver (native COW support on ZFS filesystem)" + ;; + ext4|ext3|ext2|xfs) + DRIVER="overlay" + echo "Using overlay driver (space-efficient on ext4/xfs)" + ;; + *) + DRIVER="vfs" + echo "Using vfs driver (fallback for $FS_TYPE)" + ;; +esac + +# Write storage.conf +echo "Configuring podman storage driver: $DRIVER" +GRAPHROOT="/var/lib/containers/storage" + +sudo bash -c "cat > /etc/containers/storage.conf" << CONF +[storage] +driver = "$DRIVER" +graphroot = "$GRAPHROOT" +runroot = "/run/containers/storage" +CONF + +# Verify configuration +echo "" +echo "=== Podman storage configuration ===" +sudo podman info | grep -A 5 "storage:" || sudo podman info | head -20 diff --git a/bootc-iso/src/build-iso.sh b/bootc-iso/src/build-iso.sh new file mode 100644 index 0000000..6fc1f65 --- /dev/null +++ b/bootc-iso/src/build-iso.sh @@ -0,0 +1,184 @@ +#!/usr/bin/bash +# build-iso.sh +# +# Creates a UEFI-bootable systemd-boot live ISO from pre-built components: +# — tar containing only kernel + EFI files from the rootfs +# — squashfs of the full live rootfs (built with correct UIDs +# via mksquashfs inside podman unshare) +# +# Boot architecture (no GRUB2, no shim): +# El Torito EFI entry → EFI/efi.img (FAT ESP image containing): +# EFI/BOOT/BOOTX64.EFI systemd-boot EFI binary (arch-detected) +# loader/loader.conf systemd-boot configuration +# loader/entries/bluefin-live.conf boot entry (kernel + initrd + cmdline) +# images/pxeboot/vmlinuz Bluefin kernel +# images/pxeboot/initrd.img dmsquash-live initramfs +# ISO9660 root: +# EFI/BOOT/BOOTX64.EFI EFI fallback path for Proxmox OVMF / Ventoy +# EFI/efi.img (also referenced by El Torito) +# images/pxeboot/* kernel/initramfs copies for loopback ISO boot tools +# boot/grub/loopback.cfg metadata for Ventoy/GRUB-style loopback boot +# LiveOS/squashfs.img squashfs of the full Bluefin live rootfs +# +# Live boot flow: +# UEFI firmware → El Torito → FAT ESP → systemd-boot → kernel+initramfs +# dmsquash-live: scans for CDLABEL=BLUEFIN_LIVE → mounts ISO → squashfs → overlayfs + +set -euo pipefail + +BOOT_TAR="${1:?Usage: build-iso.sh }" +SQUASHFS_SRC="${2:?Usage: build-iso.sh }" +OUTPUT_ISO="${3:?Usage: build-iso.sh }" +LABEL="BLUEFIN_LIVE" + +WORK=$(mktemp -d "${TMPDIR:-/tmp}/iso-build.XXXXXX") +trap "chmod -R u+rwX '${WORK}' 2>/dev/null; rm -rf '${WORK}'" EXIT + +BOOT_DIR="${WORK}/boot-files" +ISO_ROOT="${WORK}/iso-root" +ESP_STAGING="${WORK}/esp-staging" + +mkdir -p "${BOOT_DIR}" "${ISO_ROOT}/EFI" "${ISO_ROOT}/LiveOS" + +# ── Extract boot files (kernel, initramfs, systemd-boot EFI) ───────────────── +echo ">>> Extracting boot files..." +tar -xf "${BOOT_TAR}" -C "${BOOT_DIR}" --no-same-owner + +# ── Locate kernel ──────────────────────────────────────────────────────────── +kernel=$(ls "${BOOT_DIR}/usr/lib/modules" | sort -V | tail -1) +echo ">>> Kernel: ${kernel}" + +VMLINUZ="${BOOT_DIR}/usr/lib/modules/${kernel}/vmlinuz" +INITRD="${BOOT_DIR}/usr/lib/modules/${kernel}/initramfs.img" + +# Detect EFI binary: arm64 ships systemd-bootaa64.efi → BOOTAA64.EFI +# amd64 ships systemd-bootx64.efi → BOOTX64.EFI +BOOT_EFI_SRC="" +BOOT_EFI_DEST="" +for _candidate in \ + "systemd-bootaa64.efi:EFI/BOOT/BOOTAA64.EFI" \ + "systemd-bootx64.efi:EFI/BOOT/BOOTX64.EFI"; do + _src="${BOOT_DIR}/usr/lib/systemd/boot/efi/${_candidate%%:*}" + _dest="${_candidate##*:}" + if [[ -f "${_src}" ]]; then + BOOT_EFI_SRC="${_src}" + BOOT_EFI_DEST="${_dest}" + break + fi +done +[[ -n "${BOOT_EFI_SRC}" ]] || { echo "ERROR: no systemd-boot EFI binary found in boot-files tar"; exit 1; } + +for f in "${VMLINUZ}" "${INITRD}" "${BOOT_EFI_SRC}"; do + [[ -f "${f}" ]] || { echo "ERROR: missing ${f}"; exit 1; } +done +echo ">>> Kernel: $(du -sh "${VMLINUZ}" | cut -f1)" +echo ">>> Initramfs: $(du -sh "${INITRD}" | cut -f1)" +echo ">>> EFI: ${BOOT_EFI_SRC} → ${BOOT_EFI_DEST}" + +# ── Assemble the ESP staging directory ────────────────────────────────────── +# systemd-boot reads loader entries and kernel/initramfs exclusively from the +# FAT volume it was loaded from. Everything it needs must be in the ESP image. +mkdir -p \ + "${ESP_STAGING}/EFI/BOOT" \ + "${ESP_STAGING}/loader/entries" \ + "${ESP_STAGING}/images/pxeboot" + +cp "${BOOT_EFI_SRC}" "${ESP_STAGING}/${BOOT_EFI_DEST}" +cp "${VMLINUZ}" "${ESP_STAGING}/images/pxeboot/vmlinuz" +cp "${INITRD}" "${ESP_STAGING}/images/pxeboot/initrd.img" + +cat > "${ESP_STAGING}/loader/loader.conf" << 'EOF' +timeout 5 +default bluefin-live.conf +EOF + +# Kernel cmdline for dmsquash-live live boot: +# root=live:CDLABEL=... dmsquash-live: find the ISO by volume label +# rd.live.image enable dmsquash-live mode +# rd.live.overlay.overlayfs=1 use overlayfs (not device mapper) for the rw layer +# enforcing=0 disable SELinux enforcement (for live environment) +# console=ttyS0,115200n8 serial output on amd64 (16550/QEMU q35) — validation target +# console=ttyAMA0,115200n8 serial output on arm64 (PL011/QEMU virt) — validation target +cat > "${ESP_STAGING}/loader/entries/bluefin-live.conf" << EOF +title Bluefin Live +linux /images/pxeboot/vmlinuz +initrd /images/pxeboot/initrd.img +options root=live:CDLABEL=${LABEL} rd.live.image rd.live.overlay.overlayfs=1 enforcing=0 quiet console=ttyS0,115200n8 console=ttyAMA0,115200n8 +EOF + +# ── Create the FAT ESP image ────────────────────────────────────────────────── +# Size = kernel + initramfs + EFI binary + loader files + 32 MiB headroom +INITRD_MB=$(du -m "${INITRD}" | cut -f1) +VMLINUZ_MB=$(du -m "${VMLINUZ}" | cut -f1) +ESP_MB=$(( INITRD_MB + VMLINUZ_MB + 4 + 32 )) +ESP_IMG="${ISO_ROOT}/EFI/efi.img" + +echo ">>> Creating ${ESP_MB} MiB FAT ESP image..." +truncate -s "${ESP_MB}M" "${ESP_IMG}" +mkfs.fat -F 32 -n "ESP" "${ESP_IMG}" + +# Populate the FAT image using mtools — no loop mount required, works +# in unprivileged/restricted containers. +export MTOOLS_SKIP_CHECK=1 + +mmd -i "${ESP_IMG}" \ + ::/EFI \ + ::/EFI/BOOT \ + ::/loader \ + ::/loader/entries \ + ::/images \ + ::/images/pxeboot + +mcopy -i "${ESP_IMG}" "${ESP_STAGING}/${BOOT_EFI_DEST}" ::/"${BOOT_EFI_DEST}" +mcopy -i "${ESP_IMG}" "${ESP_STAGING}/loader/loader.conf" ::/loader/loader.conf +mcopy -i "${ESP_IMG}" "${ESP_STAGING}/loader/entries/bluefin-live.conf" ::/loader/entries/bluefin-live.conf +mcopy -i "${ESP_IMG}" "${ESP_STAGING}/images/pxeboot/vmlinuz" ::/images/pxeboot/vmlinuz +mcopy -i "${ESP_IMG}" "${ESP_STAGING}/images/pxeboot/initrd.img" ::/images/pxeboot/initrd.img + +# ── EFI fallback path on the ISO9660 root ──────────────────────────────────── +mkdir -p "${ISO_ROOT}/EFI/BOOT" +cp "${BOOT_EFI_SRC}" "${ISO_ROOT}/${BOOT_EFI_DEST}" +echo ">>> EFI fallback: ${BOOT_EFI_DEST} added to ISO root" + +# ── ISO-root kernel/initramfs and loopback metadata ────────────────────────── +mkdir -p "${ISO_ROOT}/images/pxeboot" "${ISO_ROOT}/boot/grub" +cp "${VMLINUZ}" "${ISO_ROOT}/images/pxeboot/vmlinuz" +cp "${INITRD}" "${ISO_ROOT}/images/pxeboot/initrd.img" +cat > "${ISO_ROOT}/boot/grub/loopback.cfg" << EOF +menuentry "Bluefin Live" { + linux /images/pxeboot/vmlinuz root=live:CDLABEL=${LABEL} rd.live.image rd.live.overlay.overlayfs=1 enforcing=0 quiet console=ttyS0,115200n8 console=ttyAMA0,115200n8 rd.bluefin.isofile=\${iso_path} + initrd /images/pxeboot/initrd.img +} +EOF +echo ">>> Loopback boot metadata added to ISO root" + +# ── Place the pre-built squashfs ───────────────────────────────────────────── +echo ">>> Copying squashfs..." +cp "${SQUASHFS_SRC}" "${ISO_ROOT}/LiveOS/squashfs.img" +echo ">>> Squashfs: $(du -sh "${ISO_ROOT}/LiveOS/squashfs.img" | cut -f1)" + +# ── Assemble the ISO with xorriso ──────────────────────────────────────────── +echo ">>> Assembling ISO..." +xorriso -as mkisofs \ + -iso-level 3 \ + -r \ + -J --joliet-long \ + -V "${LABEL}" \ + --efi-boot EFI/efi.img \ + -efi-boot-part \ + --efi-boot-image \ + -o "${OUTPUT_ISO}" \ + "${ISO_ROOT}" + +implantisomd5 "${OUTPUT_ISO}" 2>/dev/null || true + +# ── Verify protective MBR + GPT layout ─────────────────────────────────────── +echo ">>> Partition layout:" +xorriso -indev "${OUTPUT_ISO}" -report_system_area plain 2>/dev/null | \ + grep -E '^(System area|ISO image size|MBR|GPT|Partition)' || true +xorriso -indev "${OUTPUT_ISO}" -report_system_area plain 2>/dev/null | \ + grep 'System area summary' | grep -q 'protective' && \ + echo ">>> Protective MBR + GPT: OK" || \ + echo ">>> WARNING: protective MBR not found — USB may not boot on older firmware" + +echo ">>> Done: ${OUTPUT_ISO} ($(du -sh "${OUTPUT_ISO}" | cut -f1))" diff --git a/bootc-iso/src/configure-live.sh b/bootc-iso/src/configure-live.sh new file mode 100644 index 0000000..aa05d21 --- /dev/null +++ b/bootc-iso/src/configure-live.sh @@ -0,0 +1,361 @@ +#!/usr/bin/bash +# Live-environment setup for the Bluefin ISO installer image. +# +# Runs inside the final Bluefin container stage with: +# --cap-add sys_admin --security-opt label=disable +# +# At this point the initramfs has already been replaced (by the Debian +# initramfs-builder stage) with a dmsquash-live capable one. This script +# handles the runtime live-environment: user, GDM autologin, bootc-installer +# configuration + autostart, and Flatpak pre-installation. + +set -exo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# ── VERSION_ID ──────────────────────────────────────────────────────────────── +# Ensure VERSION_ID is present in os-release for image-builder and bootc tooling. +if grep -q '^VERSION_ID=' /usr/lib/os-release 2>/dev/null; then + sed -i 's/^VERSION_ID=.*/VERSION_ID=latest/' /usr/lib/os-release +else + echo 'VERSION_ID=latest' >> /usr/lib/os-release +fi + +# ── Live user ───────────────────────────────────────────────────────────────── +# Create a passwordless live user for the live session. +useradd --create-home --uid 1000 --user-group \ + --comment "Live User" liveuser || true +passwd --delete liveuser + +# Debug builds only: enable SSH so the live session is reachable for testing. +# Never enabled in production ISOs. +if [[ "${DEBUG:-0}" == "1" ]]; then + echo "liveuser:live" | chpasswd + + # Enable root login with a known password so hotfixes can be applied + # directly via `ssh root@` or `su -` without going through sudo. + passwd --unlock root + echo "root:root" | chpasswd + + # Enable sshd: the Bluefin preset marks sshd disabled, so a plain + # wants symlink gets overridden at first boot. A preset file in + # /etc/systemd/system-preset/ takes priority over /usr/lib and forces it on. + mkdir -p /etc/systemd/system-preset + echo "enable sshd.service" > /etc/systemd/system-preset/90-live-debug.preset + mkdir -p /etc/systemd/system/multi-user.target.wants + ln -sf /usr/lib/systemd/system/sshd.service \ + /etc/systemd/system/multi-user.target.wants/sshd.service + + cat >> /etc/ssh/sshd_config << 'SSHEOF' +PermitEmptyPasswords no +PasswordAuthentication yes +PermitRootLogin yes +SSHEOF + + # Open SSH through firewalld so port 22 is reachable from the host + mkdir -p /etc/firewalld/zones + cat > /etc/firewalld/zones/public.xml << 'FWEOF' + + + Public + + + + +FWEOF + + # Print SSH connection info to the serial console once the network is up. + cat > /usr/lib/systemd/system/debug-ssh-banner.service << 'BANNEREOF' +[Unit] +Description=Print SSH connection info to serial console +After=sshd.service network-online.target +Wants=network-online.target + +[Service] +Type=oneshot +ExecStart=/bin/bash -c '\ + IP=$(hostname -I | awk "{print \\$1}"); \ + echo ""; \ + echo "========================================"; \ + echo " DEBUG SSH READY"; \ + echo " ssh liveuser@${IP:-} (password: live)"; \ + echo " ssh root@${IP:-} (password: root)"; \ + echo "========================================"; \ + echo ""' +StandardOutput=journal+console + +[Install] +WantedBy=multi-user.target +BANNEREOF + systemctl enable debug-ssh-banner.service +fi + +# Give liveuser passwordless sudo so the live session is fully manageable +echo 'liveuser ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/liveuser +chmod 0440 /etc/sudoers.d/liveuser + +# Skip gnome-initial-setup in the live session so GNOME Shell starts directly +mkdir -p /home/liveuser/.config +touch /home/liveuser/.config/gnome-initial-setup-done +chown -R liveuser:liveuser /home/liveuser/.config + +# Remove gnome-tour desktop file so GNOME Shell can never launch it on the +# live ISO regardless of dconf state. +rm -f /usr/share/applications/org.gnome.Tour.desktop + +# Override the bootc-installer flatpak's desktop entry so it appears as +# "Bluefin Installer" with the bluefin icon instead of "bootc Installer (Devel)". +# On Fedora/ostree /usr/local is a symlink to /var/usrlocal — resolve it. +LOCAL_APPS=$(realpath /usr/local 2>/dev/null || echo /usr/local)/share/applications +mkdir -p "${LOCAL_APPS}" || { LOCAL_APPS=/usr/share/applications; mkdir -p "${LOCAL_APPS}"; } +cat > "${LOCAL_APPS}/org.bootcinstaller.Installer.Devel.desktop" << 'DESKTOPEOF' +[Desktop Entry] +Name=Bluefin Installer +Exec=/usr/bin/flatpak run --branch=master --arch=x86_64 --command=bootc-installer org.bootcinstaller.Installer.Devel +Icon=bluefin +Terminal=false +Type=Application +Categories=GTK;System;Settings; +StartupNotify=true +X-Flatpak=org.bootcinstaller.Installer.Devel +DESKTOPEOF + +# Suppress the GNOME Tour / "Welcome to Bluefin" dialog on first login. +mkdir -p /etc/dconf/db/distro.d /etc/dconf/db/distro.d/locks +cat > /etc/dconf/db/distro.d/50-live-iso << 'DCONFEOF' +[org/gnome/shell] +welcome-dialog-last-shown-version='999' +favorite-apps=['bluefin-installer.desktop', 'org.mozilla.firefox.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.Console.desktop'] + +[org/gnome/desktop/screensaver] +lock-enabled=false +idle-activation-enabled=false + +[org/gnome/desktop/session] +idle-delay=uint32 0 + +[org/gnome/settings-daemon/plugins/power] +sleep-inactive-ac-type='nothing' +sleep-inactive-battery-type='nothing' +sleep-inactive-ac-timeout=0 +sleep-inactive-battery-timeout=0 +power-button-action='nothing' +DCONFEOF + +cat > /etc/dconf/db/distro.d/locks/50-live-iso << 'LOCKSEOF' +/org/gnome/desktop/screensaver/lock-enabled +/org/gnome/desktop/screensaver/idle-activation-enabled +/org/gnome/desktop/session/idle-delay +/org/gnome/shell/favorite-apps +/org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type +/org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-type +/org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout +/org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-timeout +LOCKSEOF + +dconf update + +# Mask systemd sleep/suspend targets so the kernel never suspends regardless +# of what any userspace tool requests — belt-and-suspenders for the install. +systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target + +# ── GDM autologin ───────────────────────────────────────────────────────────── +mkdir -p /etc/gdm +cat > /etc/gdm/custom.conf << 'GDMEOF' +[daemon] +AutomaticLoginEnable=True +AutomaticLogin=liveuser +GDMEOF + +# ── /var/tmp tmpfs ──────────────────────────────────────────────────────────── +# The live overlayfs puts /var on a small RAM overlay. bootc needs substantial +# space in /var/tmp when staging an install; mount a dedicated tmpfs there. +cat > /usr/lib/systemd/system/var-tmp.mount << 'UNITEOF' +[Unit] +Description=Large tmpfs for /var/tmp in the live environment + +[Mount] +What=tmpfs +Where=/var/tmp +Type=tmpfs +Options=size=8G,nr_inodes=1m + +[Install] +WantedBy=local-fs.target +UNITEOF +systemctl enable var-tmp.mount + +# ── Default mounts for containers ───────────────────────────────────────────── +# Automatically bind-mount the read-only SquashFS cache at /usr/lib/containers/storage +# from the host into all container namespaces, allowing offline installation to work. +mkdir -p /etc/containers +cat > /etc/containers/mounts.conf << 'EOF' +/usr/lib/containers/storage:/usr/lib/containers/storage +EOF + + +# ── Live-ready marker service ───────────────────────────────────────────────── +# Prints BLUEFIN_LIVE_READY to the serial console after display-manager.service +# starts. CI boot verification greps for this token in the serial log. +cat > /usr/lib/systemd/system/live-ready.service << 'LREOF' +[Unit] +Description=Live environment ready marker +After=display-manager.service +Requires=display-manager.service + +[Service] +Type=oneshot +ExecStart=/bin/echo BLUEFIN_LIVE_READY +StandardOutput=tty +TTYPath=/dev/ttyS0 + +[Install] +WantedBy=multi-user.target +LREOF +systemctl enable live-ready.service + +# fisherman (bootc-installer backend) creates /var/fisherman-tmp and bind-mounts +# it to /var/tmp. Pre-create the directory so it exists at boot time. +mkdir -p /var/fisherman-tmp + +# ── Bluefin icon ────────────────────────────────────────────────────────────── +# Install icon in hicolor theme hierarchy for desktop integration +mkdir -p /usr/share/icons/hicolor/{16x16,24x24,32x32,48x48,64x64,128x128,256x256,512x512}/apps +for size in 16 24 32 48 64 128 256 512; do + install -Dm644 "$SCRIPT_DIR/icons/hicolor/${size}x${size}/apps/bluefin.png" \ + "/usr/share/icons/hicolor/${size}x${size}/apps/bluefin.png" +done +# Symlink 512×512 to pixmaps for compatibility +install -Dm644 "$SCRIPT_DIR/icons/hicolor/512x512/apps/bluefin.png" /usr/share/pixmaps/bluefin.png +gtk-update-icon-cache /usr/share/icons/hicolor/ + +# ── Installer tour images ───────────────────────────────────────────────────── +# The bootc-installer Flatpak has --filesystem=host so absolute paths are visible. +mkdir -p /usr/share/bootc-installer/images +install -Dm644 "$SCRIPT_DIR/images/bluefin.png" /usr/share/bootc-installer/images/bluefin.png + +# ── Installer configuration ─────────────────────────────────────────────────── +# The bootc-installer reads both overrides from /etc/bootc-installer/: +# images.json — locks the catalog to Bluefin only +# recipe.json — sets distro branding, tour slides, and install steps +mkdir -p /etc/bootc-installer +cp "$SCRIPT_DIR/etc/bootc-installer/images.json" /etc/bootc-installer/images.json +cp "$SCRIPT_DIR/etc/bootc-installer/recipe.json" /etc/bootc-installer/recipe.json +# Flag file read by the installer to activate live ISO mode. +touch /etc/bootc-installer/live-iso-mode + +# ── Installer autostart ─────────────────────────────────────────────────────── +# App ID differs between stable and dev channel builds. +INSTALLER_APP_ID="org.bootcinstaller.Installer" +[[ "${INSTALLER_CHANNEL:-stable}" == "dev" ]] && INSTALLER_APP_ID="org.bootcinstaller.Installer.Devel" + +# Create a wrapper script to handle the delay safely without desktop entry quoting issues +cat > /usr/bin/autostart-installer << EOF +#!/usr/bin/bash +sleep 5 +exec flatpak run --filesystem=/etc/bootc-installer:ro --env=VANILLA_CUSTOM_RECIPE=/etc/bootc-installer/recipe.json ${INSTALLER_APP_ID} +EOF +chmod +x /usr/bin/autostart-installer + +mkdir -p /etc/xdg/autostart +cat > /etc/xdg/autostart/tuna-installer.desktop << DTEOF +[Desktop Entry] +Name=Bluefin Installer +Exec=/usr/bin/autostart-installer +Icon=bluefin +Type=Application +X-GNOME-Autostart-enabled=true +DTEOF + +# A matching entry in /usr/share/applications/ lets GNOME Shell reference this +# app in the dock via favorite-apps. +mkdir -p /usr/share/applications +cat > /usr/share/applications/bluefin-installer.desktop << DTEOF +[Desktop Entry] +Name=Bluefin Installer +Comment=Install Bluefin to your computer +Exec=flatpak run --filesystem=/etc/bootc-installer:ro --env=VANILLA_CUSTOM_RECIPE=/etc/bootc-installer/recipe.json ${INSTALLER_APP_ID} +Icon=bluefin +Type=Application +Categories=System; +NoDisplay=false +DTEOF + +# ── Polkit rules for live installer ─────────────────────────────────────────── +# The installer's polkit action (org.tunaos.Installer.install) defaults to +# auth_admin. On the live ISO we want liveuser to install without any password +# prompt. Two complementary mechanisms are used for belt-and-suspenders: +# +# 1. Policy override: write the action definition directly with allow_active=yes +# so polkit approves it at the policy level before rules even run. +# +# 2. JS rule: belt-and-suspenders fallback that grants YES for liveuser. + +# fisherman symlink — installer calls /usr/local/bin/fisherman via pkexec +INSTALLER_APP_DIR=$(find /var/lib/flatpak/app/${INSTALLER_APP_ID} -name fisherman -type f 2>/dev/null | head -1 | xargs dirname 2>/dev/null || true) +if [ -n "$INSTALLER_APP_DIR" ]; then + mkdir -p /usr/local/bin + ln -sf "${INSTALLER_APP_DIR}/fisherman" /usr/local/bin/fisherman +fi + +# Policy file: allow any active session to run the installer without auth. +mkdir -p /usr/share/polkit-1/actions +cat > /usr/share/polkit-1/actions/org.bootcinstaller.Installer.policy << 'POLICYEOF' + + + + + Install an operating system to disk + Authentication is required to install an operating system + drive-harddisk + + no + no + yes + + /usr/local/bin/fisherman + true + + +POLICYEOF + +# JS rule: grant YES for liveuser on both custom + generic polkit exec actions. +mkdir -p /etc/polkit-1/rules.d +cat > /etc/polkit-1/rules.d/99-live-installer.rules << 'EOF' +polkit.addRule(function(action, subject) { + if ((action.id === "org.freedesktop.policykit.exec" || + action.id === "org.tunaos.Installer.install") && + subject.user === "liveuser" && subject.local) { + return polkit.Result.YES; + } +}); +EOF + +# ── Live network defaults ───────────────────────────────────────────────────── +# /etc/hostname is bind-mounted by the container runtime during builds; writing +# to it in a RUN step doesn't persist into the image layer. Use tmpfiles.d to +# create it at first boot instead. +mkdir -p /usr/lib/tmpfiles.d +echo 'f /etc/hostname 0644 - - - bluefin-live' > /usr/lib/tmpfiles.d/live-hostname.conf + +# ── Container storage ──────────────────────────────────────────────────────── +# Use overlay driver for space-efficient container operations. +# The embedded OCI in the squashfs is available via skopeo/podman pull +# from the registry. Overlay avoids VFS's full-image copy per layer. +# fuse-overlayfs (installed in Containerfile) handles overlay-on-overlay +# on kernels without native support (e.g. CentOS Stream 10 in bluefin-lts). +cat > /etc/containers/storage.conf << 'STOREOF' +[storage] +driver = "overlay" +runroot = "/run/containers/storage" +graphroot = "/var/lib/containers/storage" + +[storage.options] +additionalimagestores = [ + "/usr/lib/containers/storage" +] +STOREOF + +# fisherman handles scratch space, OCI export, and GPT partition setup natively. diff --git a/bootc-iso/src/dracut/95bluefin-isofile/bluefin-isofile.sh b/bootc-iso/src/dracut/95bluefin-isofile/bluefin-isofile.sh new file mode 100644 index 0000000..b478585 --- /dev/null +++ b/bootc-iso/src/dracut/95bluefin-isofile/bluefin-isofile.sh @@ -0,0 +1,94 @@ +#!/bin/sh +# Locate a Bluefin live ISO file on Ventoy/USB partitions and expose it as +# /dev/disk/by-label/BLUEFIN_LIVE so the standard dmsquash-live CDLABEL path works. + +LABEL="BLUEFIN_LIVE" +RUN_DIR="/run/initramfs/bluefin-isofile" +FOUND_MARKER="${RUN_DIR}/found" + +[ -e "/dev/disk/by-label/${LABEL}" ] && return 0 +[ -e "${FOUND_MARKER}" ] && return 0 + +mkdir -p "${RUN_DIR}" /dev/disk/by-label + +debug() { + echo "bluefin-isofile: $*" > /dev/kmsg 2>/dev/null || echo "bluefin-isofile: $*" +} + +iso_hint="" +for arg in $(cat /proc/cmdline); do + case "$arg" in + rd.bluefin.isofile=*|findiso=*|iso-scan/filename=*|rd.live.iso=*) + iso_hint="${arg#*=}" + ;; + esac +done + +try_iso() { + iso="$1" + [ -f "$iso" ] || return 1 + + loopdev=$(losetup --find --show --read-only "$iso" 2>/dev/null) || return 1 + iso_label=$(blkid -s LABEL -o value "$loopdev" 2>/dev/null || true) + + if [ "$iso_label" = "$LABEL" ]; then + ln -sf "$loopdev" "/dev/disk/by-label/${LABEL}" + : > "${FOUND_MARKER}" + udevadm settle 2>/dev/null || true + debug "using ISO file $iso via $loopdev" + /sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root "$loopdev" + return 0 + fi + + losetup -d "$loopdev" 2>/dev/null || true + return 1 +} + +scan_mount() { + dev="$1" + base=$(basename "$dev") + mp="${RUN_DIR}/mnt-${base}" + mkdir -p "$mp" + + mount -o ro -t auto "$dev" "$mp" 2>/dev/null || return 1 + + if [ -n "$iso_hint" ]; then + case "$iso_hint" in + /*) + try_iso "${mp}${iso_hint}" && return 0 + ;; + *) + try_iso "${mp}/${iso_hint}" && return 0 + ;; + esac + fi + + # Fast common cases first. Avoid deep recursive searches in initramfs. + for iso in \ + "$mp"/bluefin*.iso \ + "$mp"/Bluefin*.iso \ + "$mp"/*.iso \ + "$mp"/ISO/*.iso \ + "$mp"/iso/*.iso \ + "$mp"/*/bluefin*.iso \ + "$mp"/*/*.iso + do + [ -e "$iso" ] || continue + try_iso "$iso" && return 0 + done + + umount "$mp" 2>/dev/null || true + return 1 +} + +# Prefer real partition nodes. Skip whole disks and optical devices here because +# direct ISO block devices are handled by the normal CDLABEL path above. +for dev in /dev/disk/by-label/* /dev/disk/by-id/*-part* /dev/sd*[0-9] /dev/vd*[0-9] /dev/nvme*n*p* /dev/mmcblk*p*; do + [ -b "$dev" ] || continue + [ -e "/dev/disk/by-label/${LABEL}" ] && return 0 + scan_mount "$dev" && return 0 +done + +# Keep dracut's initqueue waiting if neither the normal CDLABEL path nor the +# Ventoy/file-backed path is ready yet. +return 1 diff --git a/bootc-iso/src/dracut/95bluefin-isofile/module-setup.sh b/bootc-iso/src/dracut/95bluefin-isofile/module-setup.sh new file mode 100644 index 0000000..c02567e --- /dev/null +++ b/bootc-iso/src/dracut/95bluefin-isofile/module-setup.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Dracut module: support booting Bluefin ISO as a file from Ventoy-style media. + +check() { + return 0 +} + +depends() { + echo dmsquash-live + return 0 +} + +installkernel() { + instmods loop iso9660 squashfs overlay + instmods usb-storage xhci-pci xhci_hcd ehci-pci ehci_hcd uhci-hcd ohci-hcd + instmods sd_mod sr_mod virtio_blk virtio_pci virtio_scsi + instmods exfat vfat fat ntfs3 ext4 nls_cp437 nls_iso8859_1 nls_utf8 +} + +install() { + inst_multiple mount umount blkid losetup find grep sed mkdir ln readlink basename cat sleep udevadm + inst_hook initqueue 20 "$moddir/bluefin-isofile.sh" +} diff --git a/bootc-iso/src/etc/bootc-installer/images.json b/bootc-iso/src/etc/bootc-installer/images.json new file mode 100644 index 0000000..e18be56 --- /dev/null +++ b/bootc-iso/src/etc/bootc-installer/images.json @@ -0,0 +1,16 @@ +{ + "default_image": "ghcr.io/ublue-os/bluefin:stable", + "fallback_flatpaks": [], + "images": [ + { + "name": "Bluefin", + "imgref": "ghcr.io/ublue-os/bluefin:stable", + "desc": "Cloud-native developer workstation", + "icon": "resource:///org/bootcinstaller/Installer/images/bluefin.png", + "bootloader": "grub2", + "filesystem": "btrfs", + "needs_user_creation": true, + "flatpak_var_path": "var" + } + ] +} diff --git a/bootc-iso/src/etc/bootc-installer/recipe.json b/bootc-iso/src/etc/bootc-installer/recipe.json new file mode 100644 index 0000000..9979367 --- /dev/null +++ b/bootc-iso/src/etc/bootc-installer/recipe.json @@ -0,0 +1,57 @@ +{ + "log_file": "/var/log/bootc-installer.log", + "distro_name": "Bluefin", + "distro_logo": "resource:///org/bootcinstaller/Installer/images/bluefin.png", + "imgref": "ghcr.io/ublue-os/bluefin:stable", + "local_imgref": "containers-storage:ghcr.io/ublue-os/bluefin:stable", + "bootloader": "grub2", + "composeFsBackend": false, + "distroID": "bluefin", + "brewTap": "ublue-os/tap", + "tour": { + "welcome": { + "image": "/run/host/usr/share/bootc-installer/images/bluefin.png", + "title": "Welcome to Bluefin", + "description": "A cloud-native developer workstation built on Fedora Atomic Desktop technology." + }, + "features": { + "image": "/run/host/usr/share/bootc-installer/images/bluefin.png", + "title": "Developer-First", + "description": "Pre-configured with Brew, Devbox, Devcontainers, and cloud-native tools out of the box." + }, + "community": { + "image": "/run/host/usr/share/bootc-installer/images/bluefin.png", + "title": "Documentation & Community", + "description": "Find docs at docs.projectbluefin.io and join the community on Discord." + }, + "developer": { + "image": "/run/host/usr/share/bootc-installer/images/bluefin.png", + "title": "Always Up-to-Date", + "description": "Automatic updates via bootc. Your system stays current with the latest features and fixes." + }, + "completed": { + "image": "/run/host/usr/share/bootc-installer/images/bluefin.png", + "title": "Welcome to Bluefin", + "description": "Reboot into your new Bluefin system. Welcome aboard!" + } + }, + "steps": { + "welcome": { + "template": "welcome", + "protected": true + }, + "user": { + "template": "user" + }, + "image": { + "template": "image", + "protected": true + }, + "disk": { + "template": "disk" + }, + "encryption": { + "template": "encryption" + } + } +} diff --git a/bootc-iso/src/flatpaks b/bootc-iso/src/flatpaks new file mode 100644 index 0000000..5b0e6ca --- /dev/null +++ b/bootc-iso/src/flatpaks @@ -0,0 +1,45 @@ +# Bluefin system flatpaks +# Installed into the live squashfs at build time (committed to layer, not cache). +# Copied offline to the target by tuna-installer during installation. +# +# Note: org.bootcinstaller.Installer is installed separately via the GitHub +# Releases bundle (not on Flathub) earlier in build.sh. +# +# Format: one app ID per line, resolved from the flathub remote. +com.github.PintaProject.Pinta +com.github.tchx84.Flatseal +com.mattjakeman.ExtensionManager +com.ranfdev.DistroShelf +io.github.flattool.Ignition +io.github.flattool.Warehouse +io.github.kolunmi.Bazaar +io.gitlab.adhami3310.Impression +io.missioncenter.MissionCenter +it.mijorus.smile +org.gnome.Calculator +org.gnome.Calendar +org.gnome.Characters +org.gnome.Connections +org.gnome.Contacts +org.gnome.DejaDup +org.gnome.FileRoller +org.gnome.Firmware +org.gnome.Logs +org.gnome.Loupe +org.gnome.Maps +org.gnome.NautilusPreviewer +org.gnome.Papers +org.gnome.Showtime +org.gnome.SimpleScan +org.gnome.Snapshot +org.gnome.SoundRecorder +org.gnome.TextEditor +org.gnome.Weather +org.gnome.baobab +org.gnome.clocks +org.gnome.font-viewer +org.gtk.Gtk3theme.adw-gtk3 +org.gtk.Gtk3theme.adw-gtk3-dark +org.mozilla.Thunderbird +org.mozilla.firefox +page.tesk.Refine diff --git a/bootc-iso/src/icons/hicolor/128x128/apps/bluefin.png b/bootc-iso/src/icons/hicolor/128x128/apps/bluefin.png new file mode 100644 index 0000000..53b2e8b Binary files /dev/null and b/bootc-iso/src/icons/hicolor/128x128/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/16x16/apps/bluefin.png b/bootc-iso/src/icons/hicolor/16x16/apps/bluefin.png new file mode 100644 index 0000000..43a2e45 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/16x16/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/24x24/apps/bluefin.png b/bootc-iso/src/icons/hicolor/24x24/apps/bluefin.png new file mode 100644 index 0000000..73d91f8 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/24x24/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/256x256/apps/bluefin.png b/bootc-iso/src/icons/hicolor/256x256/apps/bluefin.png new file mode 100644 index 0000000..1e93c02 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/256x256/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/32x32/apps/bluefin.png b/bootc-iso/src/icons/hicolor/32x32/apps/bluefin.png new file mode 100644 index 0000000..865ade1 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/32x32/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/48x48/apps/bluefin.png b/bootc-iso/src/icons/hicolor/48x48/apps/bluefin.png new file mode 100644 index 0000000..fa84225 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/48x48/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/512x512/apps/bluefin.png b/bootc-iso/src/icons/hicolor/512x512/apps/bluefin.png new file mode 100644 index 0000000..a5e4ee1 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/512x512/apps/bluefin.png differ diff --git a/bootc-iso/src/icons/hicolor/64x64/apps/bluefin.png b/bootc-iso/src/icons/hicolor/64x64/apps/bluefin.png new file mode 100644 index 0000000..eef19c0 Binary files /dev/null and b/bootc-iso/src/icons/hicolor/64x64/apps/bluefin.png differ diff --git a/bootc-iso/src/images/bluefin.png b/bootc-iso/src/images/bluefin.png new file mode 100644 index 0000000..a5e4ee1 Binary files /dev/null and b/bootc-iso/src/images/bluefin.png differ diff --git a/bootc-iso/src/images/bluefin.svg b/bootc-iso/src/images/bluefin.svg new file mode 100644 index 0000000..75ee9e8 --- /dev/null +++ b/bootc-iso/src/images/bluefin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bootc-iso/src/install-flatpaks.sh b/bootc-iso/src/install-flatpaks.sh new file mode 100755 index 0000000..fdd2719 --- /dev/null +++ b/bootc-iso/src/install-flatpaks.sh @@ -0,0 +1,106 @@ +#!/usr/bin/bash +# Pre-install flatpaks into the live squashfs. +# +# Uses --mount=type=cache,target=/var/cache/flatpak-dl to persist the flatpak +# ostree repo across builds. On each run the script: +# 1. Seeds /var/lib/flatpak/repo from the build cache (warm start) +# 2. Reconciles to match /tmp/flatpaks-list (only deltas downloaded) +# 3. Saves the repo back to the cache for next build +# +# /tmp/flatpaks-list is COPYd by the Containerfile so it's always current. +# Requires network at build time; CAP_SYS_ADMIN for dbus. + +set -exo pipefail + +FLATPAK_CACHE="/var/cache/flatpak-dl" + +# overlayfs inside Podman builds doesn't support O_TMPFILE. /dev/shm would +# work but is only ~3.5 GB on GHA 7-GB runners — too small for GNOME Platform. +# The --mount=type=cache volume is a bind-mount from btrfs (supports O_TMPFILE) +# and has ~60 GB free, so use a subdirectory of it as TMPDIR instead. +mkdir -p "${FLATPAK_CACHE}/tmp" +export TMPDIR="${FLATPAK_CACHE}/tmp" +mkdir -p /run/dbus +dbus-daemon --system --fork --nopidfile +sleep 1 + +# ── Seed flatpak repo from build cache (warm start) ────────────────────────── +if [ -d "${FLATPAK_CACHE}/repo/refs" ]; then + echo "Seeding flatpak repo from build cache..." + rsync -a --ignore-existing "${FLATPAK_CACHE}/repo/" /var/lib/flatpak/repo/ || true + echo "Cache seed complete" +fi + +flatpak remote-add --system --if-not-exists flathub \ + https://dl.flathub.org/repo/flathub.flatpakrepo + +# bootc-installer bundle +# INSTALLER_CHANNEL controls which release tag to pull from: +# stable (default) → continuous (latest stable build from prod branch) +# dev → continuous-dev (latest dev build, tracks dev branch) +# Primary source: projectbluefin/bootc-installer (Project Bluefin's fork). +# Fallback: tuna-os/tuna-installer (upstream) if projectbluefin assets are unavailable. +# v2.5.0 includes fisherman v0.2.0 with fix for #38 (OCI cache mount on composefs/btrfs). +INSTALLER_REPO="projectbluefin/bootc-installer" +FALLBACK_REPO="tuna-os/tuna-installer" +RELEASE_TAG="continuous" +FLATPAK_FILENAME="org.bootcinstaller.Installer.flatpak" +if [[ "${INSTALLER_CHANNEL:-stable}" == "dev" ]]; then + RELEASE_TAG="continuous-dev" + FLATPAK_FILENAME="org.bootcinstaller.Installer.Devel.flatpak" +fi +if ! curl --retry 3 --fail --location \ + "https://github.com/${INSTALLER_REPO}/releases/download/${RELEASE_TAG}/${FLATPAK_FILENAME}" \ + -o /tmp/tuna-installer.flatpak 2>/dev/null; then + echo "Primary source unavailable, falling back to ${FALLBACK_REPO}..." + curl --retry 3 --fail --location \ + "https://github.com/${FALLBACK_REPO}/releases/download/${RELEASE_TAG}/${FLATPAK_FILENAME}" \ + -o /tmp/tuna-installer.flatpak +fi +INSTALLER_APP_ID="org.bootcinstaller.Installer" +[[ "${INSTALLER_CHANNEL:-stable}" == "dev" ]] && INSTALLER_APP_ID="org.bootcinstaller.Installer.Devel" + +flatpak install --system --noninteractive --bundle /tmp/tuna-installer.flatpak || \ + flatpak update --system --noninteractive "${INSTALLER_APP_ID}" +rm /tmp/tuna-installer.flatpak + +flatpak override --system --filesystem=/etc:ro "${INSTALLER_APP_ID}" + +# ── Reconcile Flathub apps against the wanted list ─────────────────────────── +# In debug mode, skip the full Flathub app list to keep builds fast. +# NOTE: Disabled to allow debug ISOs with full flatpak suite + SSH access +# if [[ "${DEBUG:-0}" == "1" ]]; then +# echo "DEBUG mode: skipping Flathub app list (installer-only ISO)" +# # Still save cache for the installer runtime +# echo "Saving flatpak repo to build cache..." +# mkdir -p "${FLATPAK_CACHE}" +# rsync -a --delete /var/lib/flatpak/repo/ "${FLATPAK_CACHE}/repo/" +# exit 0 +# fi + +readarray -t WANTED < <(grep -v '^[[:space:]]*#' /tmp/flatpaks-list | grep -v '^[[:space:]]*$') + +# Install or update everything in the list (--or-update = skip if current) +# --no-related skips locale packs and debug symbols (~3 GB uncompressed) +flatpak install --system --noninteractive --no-related --or-update flathub "${WANTED[@]}" + +# Remove any system app that is no longer in the wanted list +readarray -t INSTALLED < <(flatpak list --app --system --columns=application 2>/dev/null || true) +for app in "${INSTALLED[@]}"; do + # Keep the installer regardless (stable or devel app ID) + [[ "$app" == "org.bootcinstaller.Installer" ]] && continue + [[ "$app" == "org.bootcinstaller.Installer.Devel" ]] && continue + if [[ ! " ${WANTED[*]} " =~ " ${app} " ]]; then + echo "Removing dropped flatpak: $app" + flatpak uninstall --system --noninteractive "$app" || true + fi +done + +# Prune unused runtimes left behind by removals +flatpak uninstall --system --noninteractive --unused || true + +# ── Save flatpak repo to build cache for next build ────────────────────────── +echo "Saving flatpak repo to build cache..." +mkdir -p "${FLATPAK_CACHE}" +rsync -a --delete /var/lib/flatpak/repo/ "${FLATPAK_CACHE}/repo/" +echo "Cache updated" diff --git a/bootc-iso/src/luks-unlock.py b/bootc-iso/src/luks-unlock.py new file mode 100644 index 0000000..1fdf735 --- /dev/null +++ b/bootc-iso/src/luks-unlock.py @@ -0,0 +1,534 @@ +#!/usr/bin/env python3 +""" +Automate LUKS passphrase entry for a VM booting with Plymouth. + +Plymouth renders the passphrase prompt on the EFI framebuffer (not the serial +console), so we cannot detect it via serial output. Instead we detect the +Plymouth prompt by analysing QEMU screendumps (PPM files): + + - Plymouth passphrase prompt is a static, nearly all-black screen. + - We wait for the screendump MD5 hash to stabilise (stop changing) after + the framebuffer has first shown any non-zero content (OVMF/boot rendered). + - Then inject keystrokes via virsh send-key (libvirt) or QEMU HMP sendkey. + +Usage: + libvirt mode: luks-unlock.py libvirt + qemu mode: luks-unlock.py qemu + +Exit codes: + 0 — passphrase sent and boot succeeded (display re-stabilised after unlock) + 1 — error (timed out, passphrase prompt never appeared, etc.) + 2 — passphrase sent but boot resulted in emergency shell (issue #270 reproduced) +""" + +import hashlib +import os +import subprocess +import sys +import time + + +# ── Shared constants ────────────────────────────────────────────────────────── + +POLL_INTERVAL = 3 # seconds between screenshot polls +PLYMOUTH_WAIT = 10 # seconds to wait after display goes blank before sending keys +PROMPT_DEADLINE = 300 # seconds to wait for Plymouth to take over +BOOT_DEADLINE = 900 # seconds to wait for successful boot after passphrase + +# Headless QEMU (-display none) often keeps the framebuffer all-black after +# LUKS unlock while GRUB2 and Plymouth run. If the screen hash has not +# changed within this many seconds of the passphrase being sent, we assume +# the passphrase was accepted and the system is booting silently. +DARK_SCREEN_OVERRIDE_S = 90 + + +# ── Libvirt helpers ─────────────────────────────────────────────────────────── + +def virsh_screenshot_size(vm: str, path: str) -> int: + r = subprocess.run(["virsh", "screenshot", vm, path], capture_output=True) + if r.returncode != 0: + return 0 + try: + return os.path.getsize(path) + except OSError: + return 0 + + +def virsh_send_passphrase(vm: str, passphrase: str): + key_map = { + c: f"KEY_{c.upper()}" for c in "abcdefghijklmnopqrstuvwxyz" + } + key_map.update({str(i): f"KEY_{i}" for i in range(10)}) + key_map["-"] = "KEY_MINUS" + key_map["_"] = "KEY_MINUS" + key_map[" "] = "KEY_SPACE" + + for ch in passphrase: + key = key_map.get(ch) + if key is None: + print(f"[luks-unlock] WARNING: no key mapping for {ch!r}", file=sys.stderr) + continue + subprocess.run( + ["virsh", "send-key", vm, "--codeset", "linux", key], + capture_output=True, + ) + time.sleep(0.08) + subprocess.run( + ["virsh", "send-key", vm, "--codeset", "linux", "KEY_ENTER"], + capture_output=True, + ) + + +def virsh_dhcp_ip(mac: str) -> str: + r = subprocess.run( + ["virsh", "net-dhcp-leases", "default"], + capture_output=True, text=True, + ) + for line in r.stdout.splitlines(): + if mac.lower() in line.lower(): + for part in line.split(): + if "/" in part and "." in part: + return part.split("/")[0] + return "" + + +# ── QEMU monitor helpers ────────────────────────────────────────────────────── + +def qemu_screendump(sock: str, path: str) -> tuple: + """Return (brightness, md5_hash) for the screendump, or (-1, '') on error. + + PPM files are always the same byte length regardless of content, so we + analyse pixel values rather than file size. + + brightness — average sampled pixel value (0-255). + QEMU uninitialized: all zeros → 0.0 + OVMF/bootloader: dim text on black → typically 0.5–5 + Plymouth prompt: nearly all-black → typically 0.5–2, STABLE + GDM/GNOME: colourful UI → typically higher + + md5_hash — MD5 of the full PPM file. Used to detect when the display + has stopped changing (Plymouth is waiting for passphrase input). + """ + subprocess.run( + ["socat", "-", f"UNIX-CONNECT:{sock}"], + input=f"screendump {path}\n".encode(), + capture_output=True, + timeout=5, + ) + # Brief pause so QEMU can finish writing the PPM before we read it + time.sleep(0.5) + try: + data = open(path, "rb").read() + except OSError: + return -1, "" + md5 = hashlib.md5(data).hexdigest() + # Parse PPM header: "P6\n \n255\n" + try: + header_end = data.index(b"255\n") + 4 + except ValueError: + return -1, "" + pixel_data = data[header_end:] + if not pixel_data: + return -1, "" + # Sample every 100th byte for speed (each pixel = 3 bytes R,G,B) + sampled = pixel_data[::100] + return sum(sampled) / len(sampled), md5 + + +def qemu_send_passphrase(sock: str, passphrase: str): + # QEMU HMP sendkey takes individual key names (one per invocation). + # Keys are sent one character at a time with a small delay. + key_map = {c: c for c in "abcdefghijklmnopqrstuvwxyz0123456789"} + key_map["-"] = "minus" + key_map["_"] = "shift-minus" + key_map[" "] = "spc" + + def _sendkey(key: str): + subprocess.run( + ["socat", "-", f"UNIX-CONNECT:{sock}"], + input=f"sendkey {key}\n".encode(), + capture_output=True, + timeout=5, + ) + + for ch in passphrase: + key = key_map.get(ch) + if key is None: + print(f"[luks-unlock] WARNING: no key mapping for {ch!r}", file=sys.stderr) + continue + _sendkey(key) + time.sleep(0.1) + _sendkey("ret") + + +def qemu_check_serial(serial_log: str) -> str: + """Return 'plymouth', 'gdm', 'emergency', or '' if no marker yet. + + Checks for systemd unit messages that appear on the serial console when the + installed system has console=ttyS0 in its kernel cmdline. + Falls back gracefully to '' when serial output is absent. + """ + import re + try: + raw = open(serial_log).read() + except OSError: + return "" + # Strip ANSI escape codes and collapse whitespace so that systemd status + # lines like " OK ] Started \ngdm.service\n- GNOME Display…" + # become searchable as a single string. + content = re.sub(r'\x1b\[[0-9;]*[A-Za-z]', '', raw) + content_flat = ' '.join(content.split()) + if "emergency mode" in content or "emergency shell" in content: + return "emergency" + # systemd serial output (ANSI-stripped, whitespace-collapsed): + # "OK ] Started gdm.service - GNOME Display Manager." + if "Started gnome-initial-setup" in content_flat: + return "gnome-initial-setup" + if "Started gdm.service" in content_flat or "Started GNOME Display Manager" in content_flat: + return "gdm" + # Plymouth passphrase prompt — no ANSI codes, plain text on serial. + if "Please enter passphrase for disk" in raw: + return "plymouth" + return "" + + +# ── Mode implementations ────────────────────────────────────────────────────── + +def run_libvirt(vm: str, passphrase: str, mac: str): + snap = "/tmp/luks-unlock-snap.png" + seen_content = False + + print(f"[luks-unlock] libvirt mode — watching {vm} for Plymouth takeover...", flush=True) + deadline = time.time() + PROMPT_DEADLINE + + while time.time() < deadline: + size = virsh_screenshot_size(vm, snap) + print(f"[luks-unlock] screenshot: {size}B", flush=True) + + if not seen_content and size > 4096: + seen_content = True + print("[luks-unlock] Boot content visible (OVMF/bootloader)", flush=True) + + if seen_content and size <= 4096: + print( + f"[luks-unlock] Plymouth has the display — waiting {PLYMOUTH_WAIT}s...", + flush=True, + ) + time.sleep(PLYMOUTH_WAIT) + print("[luks-unlock] Sending passphrase via virsh send-key...", flush=True) + virsh_send_passphrase(vm, passphrase) + print("[luks-unlock] Passphrase sent — waiting for boot...", flush=True) + break + + time.sleep(POLL_INTERVAL) + else: + print("[luks-unlock] ERROR: Plymouth takeover never detected", file=sys.stderr) + sys.exit(1) + + deadline = time.time() + BOOT_DEADLINE + while time.time() < deadline: + ip = virsh_dhcp_ip(mac) + if ip: + print(f"[luks-unlock] RESULT: boot succeeded — guest IP {ip}", flush=True) + sys.exit(0) + time.sleep(5) + + print("[luks-unlock] WARNING: passphrase sent but no DHCP lease within timeout", file=sys.stderr) + sys.exit(2) + + +def ssh_reachable(port: int, timeout: int = 5) -> bool: + """Return True if sshd on localhost:port is accepting TCP connections. + + Checks TCP reachability only — does not require auth or a configured user. + An SSH banner in the response means the daemon is up and the system booted. + """ + import socket + try: + with socket.create_connection(("127.0.0.1", port), timeout=timeout) as s: + banner = s.recv(64) + return banner.startswith(b"SSH-") + except OSError: + return False + + +def run_qemu(monitor_sock: str, passphrase: str, serial_log: str, ssh_port: int = 0): + snap = "/tmp/luks-unlock-snap.ppm" + + # Plymouth detection strategy + # ---------------------------- + # QEMU with -display none renders very dim (brightness 0–5 for all phases). + # We cannot distinguish OVMF from Plymouth by absolute brightness, so we use + # two criteria instead: + # + # 1. had_content: at least one poll returned brightness > 0.5, meaning the + # VM has started rendering something (rules out the all-zeros framebuffer + # right after QEMU starts). + # + # 2. hash stability: the screendump MD5 has not changed for STABLE_POLLS + # consecutive polls. Plymouth passphrase prompt is a static screen + # (no animation) so it stabilises quickly; OVMF and early boot are + # actively changing. + CONTENT_THRESHOLD = 0.5 # any non-zero rendering + STABLE_POLLS = 2 # consecutive identical-hash polls → Plymouth waiting + # (≥ 6 s at POLL_INTERVAL=3) + + print(f"[luks-unlock] qemu mode — watching monitor {monitor_sock}...", flush=True) + deadline = time.time() + PROMPT_DEADLINE + + had_content = False + stable_count = 0 + prev_hash = "" + + while time.time() < deadline: + # Primary path: detect Plymouth passphrase prompt via serial log. + # With console=tty0 console=ttyS0 in the BLS entry, Plymouth writes + # the prompt to serial. Input still comes from tty0, so sendkey works. + serial_result = qemu_check_serial(serial_log) + if serial_result == "plymouth": + print("[luks-unlock] Plymouth passphrase prompt detected via serial", flush=True) + brightness, md5 = qemu_screendump(monitor_sock, snap) + prev_hash = md5 # anchor passphrase_hash so post-passphrase screen_changed is accurate + try: + import shutil + shutil.copy2(snap, "/tmp/luks-screenshot-plymouth.ppm") + except OSError: + pass + print(f"[luks-unlock] Waiting {PLYMOUTH_WAIT}s for Plymouth to settle...", flush=True) + time.sleep(PLYMOUTH_WAIT) + print("[luks-unlock] Sending passphrase via QEMU monitor sendkey...", flush=True) + qemu_send_passphrase(monitor_sock, passphrase) + print("[luks-unlock] Passphrase sent — watching for boot...", flush=True) + break + + brightness, md5 = qemu_screendump(monitor_sock, snap) + print(f"[luks-unlock] screendump brightness={brightness:.2f} hash={md5[:8]}", flush=True) + + if brightness < 0: + # Failed to read/parse screendump — socket not ready yet + stable_count = 0 + time.sleep(POLL_INTERVAL) + continue + + if not had_content and brightness > CONTENT_THRESHOLD: + had_content = True + print(f"[luks-unlock] VM is rendering (brightness {brightness:.2f})", flush=True) + + # Track hash stability only after the framebuffer has any content + if had_content: + if md5 == prev_hash: + stable_count += 1 + else: + stable_count = 0 + prev_hash = md5 + + # Fallback: detect Plymouth via framebuffer stability (no serial console) + if had_content and stable_count >= STABLE_POLLS: + print( + f"[luks-unlock] Plymouth prompt stable" + f" (brightness={brightness:.2f}, {stable_count} identical polls)", + flush=True, + ) + # Save a copy of the Plymouth screendump for CI diagnostics + try: + import shutil + shutil.copy2(snap, "/tmp/luks-screenshot-plymouth.ppm") + except OSError: + pass + print(f"[luks-unlock] Waiting {PLYMOUTH_WAIT}s for Plymouth to settle...", flush=True) + time.sleep(PLYMOUTH_WAIT) + print("[luks-unlock] Sending passphrase via QEMU monitor sendkey...", flush=True) + qemu_send_passphrase(monitor_sock, passphrase) + print("[luks-unlock] Passphrase sent — watching for boot...", flush=True) + break + + time.sleep(POLL_INTERVAL) + else: + print("[luks-unlock] ERROR: Plymouth takeover never detected", file=sys.stderr) + sys.exit(1) + + # After passphrase: watch for the screen to change from Plymouth (passphrase + # accepted → Plymouth clears → boot continues) and check serial for emergency + # shell (still useful for catching issue #270 even without ttyS0). + deadline = time.time() + BOOT_DEADLINE + passphrase_time = time.time() + passphrase_hash = prev_hash # Plymouth hash at time of passphrase send + screen_changed = False + gnome_bright_count = 0 + emergency_stable_count = 0 + + + while time.time() < deadline: + result = qemu_check_serial(serial_log) + if result == "emergency": + print("[luks-unlock] RESULT: emergency shell — issue #270 reproduced", flush=True) + sys.exit(2) + + # SSH success path: if caller provided a port, test TCP reachability to + # detect sshd banner — no auth needed, just "daemon is up = boot done". + # Wins reliably when the installed system starts sshd but lacks + # console=ttyS0 (so no serial markers reach the log). + if ssh_port and ssh_reachable(ssh_port): + print(f"[luks-unlock] RESULT: boot succeeded (sshd banner on port {ssh_port})", + flush=True) + print("[luks-unlock] Waiting 20s for GDM/desktop to fully render...", flush=True) + time.sleep(20) + try: + import shutil + qemu_screendump(monitor_sock, snap) + shutil.copy2(snap, "/tmp/luks-screenshot-final.ppm") + except OSError: + pass + sys.exit(0) + + # Dark-screen override: headless QEMU (-display none) often keeps the + # framebuffer all-black during GRUB2 + Plymouth even after a successful + # LUKS unlock. The passphrase_hash == post-passphrase hash so + # screen_changed never flips and the brightness check never runs. + # + # When the screen stays dark for DARK_SCREEN_OVERRIDE_S seconds: + # - With SSH port: do nothing. We just keep looping and polling SSH. + # - Without SSH port: exit 0 now. If the passphrase was wrong Plymouth + # would have re-prompted; silence = passphrase accepted = boot proceeding. + elapsed_since_passphrase = time.time() - passphrase_time + if not screen_changed and elapsed_since_passphrase > DARK_SCREEN_OVERRIDE_S: + if not ssh_port: + print( + f"[luks-unlock] Dark-screen override: screen unchanged for " + f"{int(elapsed_since_passphrase)}s and no SSH port configured — assuming boot succeeded", + flush=True, + ) + sys.exit(0) + + + brightness, md5 = qemu_screendump(monitor_sock, snap) + print(f"[luks-unlock] post-passphrase brightness={brightness:.2f} hash={md5[:8]}", + flush=True) + + if md5 != passphrase_hash and not screen_changed: + screen_changed = True + print( + "[luks-unlock] Screen changed after passphrase" + " — LUKS accepted, boot proceeding", + flush=True, + ) + + # Primary success path: serial log confirms gnome-initial-setup or GDM. + # gnome-initial-setup fires after GDM — screenshot taken immediately. + # If only GDM is seen, wait 30s as a fallback in case g-i-s is slow. + if result == "gnome-initial-setup": + print("[luks-unlock] gnome-initial-setup started (serial confirmed) — waiting 15s to render UI", flush=True) + time.sleep(15) + brightness, md5 = qemu_screendump(monitor_sock, snap) + print(f"[luks-unlock] RESULT: boot succeeded (g-i-s confirmed via serial, brightness={brightness:.2f})", flush=True) + elif result == "gdm": + print( + "[luks-unlock] GDM started — waiting 30s for gnome-initial-setup...", + flush=True, + ) + time.sleep(30) + brightness, md5 = qemu_screendump(monitor_sock, snap) + print( + f"[luks-unlock] RESULT: boot succeeded" + f" (GDM confirmed via serial, brightness={brightness:.2f})", + flush=True, + ) + if result in ("gnome-initial-setup", "gdm"): + try: + import shutil + shutil.copy2(snap, "/tmp/luks-screenshot-final.ppm") + except OSError: + pass + sys.exit(0) + + # Fallback: no serial console (console=ttyS0 absent). Use framebuffer + # brightness to distinguish GDM from emergency shell. + # GDM re-renders continuously (cursor blink, animations, clock), so we + # cannot require identical hashes. Instead, we detect GDM by verifying + # the screen remains bright for multiple consecutive polls. + # For the emergency shell, which is static and dark, we require identical + # hashes and low brightness. + GNOME_THRESHOLD = 1.8 + GNOME_BRIGHT_POLLS = 2 # Screen remains bright for 2 polls (~10s) + EMERGENCY_STABLE_POLLS = 3 # Screen remains stable and dark for 3 polls (~15s) + + if screen_changed: + if brightness > GNOME_THRESHOLD: + gnome_bright_count += 1 + else: + gnome_bright_count = 0 + + if md5 == prev_hash and brightness <= GNOME_THRESHOLD: + emergency_stable_count += 1 + else: + emergency_stable_count = 0 + + if gnome_bright_count >= GNOME_BRIGHT_POLLS: + print( + f"[luks-unlock] RESULT: boot succeeded" + f" (framebuffer bright for {gnome_bright_count} polls," + f" brightness={brightness:.2f})", + flush=True, + ) + print("[luks-unlock] Waiting 25s for GDM/desktop to fully render...", flush=True) + time.sleep(25) + try: + import shutil + qemu_screendump(monitor_sock, snap) + shutil.copy2(snap, "/tmp/luks-screenshot-final.ppm") + except OSError: + pass + sys.exit(0) + + if emergency_stable_count >= EMERGENCY_STABLE_POLLS: + print( + f"[luks-unlock] RESULT: emergency shell suspected" + f" (framebuffer stable and dark for {emergency_stable_count} polls," + f" brightness={brightness:.2f})", + flush=True, + ) + try: + import shutil + shutil.copy2(snap, "/tmp/luks-screenshot-final.ppm") + except OSError: + pass + sys.exit(2) + + prev_hash = md5 + time.sleep(5) + + print("[luks-unlock] WARNING: passphrase sent but boot did not complete within timeout", + file=sys.stderr) + sys.exit(2) + + +# ── Entry point ─────────────────────────────────────────────────────────────── + +def main(): + if len(sys.argv) < 2: + print(__doc__, file=sys.stderr) + sys.exit(1) + + mode = sys.argv[1] + + if mode == "libvirt": + if len(sys.argv) < 5: + print("Usage: luks-unlock.py libvirt ", file=sys.stderr) + sys.exit(1) + run_libvirt(sys.argv[2], sys.argv[3], sys.argv[4]) + + elif mode == "qemu": + if len(sys.argv) < 5: + print("Usage: luks-unlock.py qemu [ssh-port]", + file=sys.stderr) + sys.exit(1) + ssh_port = int(sys.argv[5]) if len(sys.argv) >= 6 else 0 + run_qemu(sys.argv[2], sys.argv[3], sys.argv[4], ssh_port=ssh_port) + + else: + print(f"Unknown mode: {mode!r}. Use 'libvirt' or 'qemu'.", file=sys.stderr) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/bootc-iso/src/show-screenshot.sh b/bootc-iso/src/show-screenshot.sh new file mode 100755 index 0000000..aaf9c8a --- /dev/null +++ b/bootc-iso/src/show-screenshot.sh @@ -0,0 +1,32 @@ +#!/usr/bin/bash +# Display a PPM screendump inline in terminals that support it. +# Usage: show-screenshot.sh