Repository navigation
Prebuilt RPi4 SD-card image with captive-portal WiFi onboarding (#183) - #186
Merged
Merged
Conversation
Adds the stage tree + build wrapper that produces a flashable Raspberry Pi 4 image with forty-two-watts preconfigured. The image boots with hostname `42w` so avahi exposes the dashboard at http://42w.local:8080/ with no user configuration. A systemd oneshot (ftw-firstboot.service) runs `docker compose pull && up -d` against the compose file we already ship, so the image stays in lockstep with the release artifacts coming out of release.yml. Phase 1 of #183. Captive-portal WiFi onboarding via wifi-connect and the CI release-job integration land in follow-up commits. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Ships balena-os/wifi-connect v4.11.84 in the image so a user who flashes the SD card without pre-configuring WiFi through Raspberry Pi Imager gets a `42w-setup` access point + captive portal instead of a silent brick. The 42w-wifi-onboarding.service runs ordered-before ftw-firstboot so docker compose pull doesn't race a dead network. It's a one-shot gated on /var/lib/ftw/wifi-configured — once the user finishes the portal flow, the sentinel lands and subsequent boots are a no-op. Disables dhcpcd so NetworkManager owns wlan0 uncontested; otherwise wifi-connect's AP-mode toggling races the default Raspberry Pi OS dhcpcd supplicant and both sides lose. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds an rpi-image job to release.yml that runs pi-gen on the release tag and uploads the resulting .img.xz to the GitHub release. Gated on the docker job so users who flash the image don't hit a firstboot that tries to pull images that haven't been published yet. Frees ~30 GB of runner disk space up-front because pi-gen's chroot stages exceed ubuntu-latest's stock 14 GB free. Pins PI_GEN_REF to master for now — tightens to a specific tag once upstream ships a breaking change. Intentionally not added to the discord job's needs: pi-gen can fail for reasons orthogonal to the release being useful, and the announcement should still go out with binary + image links when that happens. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds docs/rpi-image.md covering the end-user flow (flash → boot → dashboard), the two WiFi onboarding paths (Imager advanced options vs. the 42w-setup captive portal), troubleshooting recipes for the ftw-firstboot service, and how to rebuild the image locally. Promotes the image to README Option A; the existing curl|bash installer moves to Option B, source build to Option C. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds .github/workflows/rpi-image-build.yml — a companion to release.yml's rpi-image job that runs on PR pushes (when files that affect the image change) and on manual workflow_dispatch. Purpose is CI signal on image-scaffolding PRs plus a one-click hand-built image for real-hardware testing before the release flow ever runs. Output is a workflow artifact, not a GitHub Release asset — release-tagged builds still go through release.yml. Concurrency-cancels in-flight runs on the same ref so a new push doesn't chain 30 min of queued pi-gen builds behind the last one. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pi-gen's build-docker.sh does its qemu presence check on the host runner, not inside the build container, and aborts with "qemu-arm not found (please install qemu-user-binfmt)" when the binary is missing. ubuntu-latest doesn't ship qemu-user-static by default, so add an apt-get step ahead of the pi-gen invocation. Applies to both the PR-triggered preview workflow and the tag- triggered release job — same failure mode would have blocked the real release. Fixes the rpi-image-build failure on #186. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Previous fix installed the wrong package. pi-gen's check at build-docker.sh is `which qemu-arm` — it wants the non-static binary at /usr/bin/qemu-arm, which qemu-user-binfmt installs. qemu-user-static ships /usr/bin/qemu-arm-static, so the check still failed with the same "qemu-arm not found" message. Confirmed against RPi-Distro/pi-gen master — the check then registers qemu-arm in /proc/sys/fs/binfmt_misc so chroot stages can execute aarch64 binaries. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Installing qemu-user-binfmt alone gets us past pi-gen's host-side `which qemu-arm` check but the kernel registration it triggers isn't usable from inside the pi-gen chroot — arch-test reports "armhf: not supported on this machine/kernel" and the build fails before any stage runs. tonistiigi/binfmt registers handlers with the F (fix-binary) flag, which opens the interpreter at registration time and keeps the fd valid across mount namespaces. Same approach docker/setup-qemu-action uses internally; the direct docker-run form keeps the dependency footprint minimal. Apply to both the preview workflow and the release job. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Third attempt still hits "armhf: not supported on this machine/kernel" despite tonistiigi/binfmt claiming to register handlers. Dump the kernel's actual view so we can see what's registered, what interpreter path pi-gen is matching against, and whether qemu-user on the host provides what pi-gen's `which qemu-arm` check wants. Switched qemu-user-binfmt -> qemu-user so its postinst doesn't re-register non-F-flagged handlers that would collide with tonistiigi's F-flagged registration (a plausible but unproven cause of the failure). Part of #183 — revert this diag step once the root cause is fixed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Diagnostics on run 24875338536 showed the kernel's binfmt_misc qemu-arm entry had interpreter `/usr/libexec/qemu-binfmt/arm-binfmt-P` — a shell wrapper provided by qemu-user-binfmt. That path doesn't exist inside pi-gen's Raspberry Pi OS chroot, so arch-test exits with "armhf: not supported" even though qemu-user was nominally in place. qemu-user Recommends qemu-user-binfmt, so a plain `apt-get install qemu-user` pulls the latter in and its postinst registers the broken handlers before tonistiigi/binfmt gets the chance — tonistiigi then silently skips install with "arm qemu-arm already registered". --no-install-recommends holds qemu-user-binfmt out of the set. tonistiigi then registers F-flagged handlers with statically- linked interpreters that survive the chroot. Same fix in both workflows. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Symlinks pointing outside the pi-gen build context become dangling inside the pi-gen Docker container (\`COPY . /pi-gen/\` copies the symlink verbatim, and the target path doesn't exist under the container rootfs). pi-gen fails with "realpath: /pi-gen/stage-42w: No such file or directory" before any stage runs. Observed on run 24875429101 of rpi-image-build. cp -R preserves executable bits on the scripts and works identically on Linux and macOS. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pi-gen's master moved to Debian trixie; our config says bookworm, so stage0/prerun.sh warned about the mismatch and debootstrap then failed with "Invalid Release signature" because the baked-in apt keys are for trixie, not bookworm. Pinning PI_GEN_REF=bookworm-arm64 matches our RELEASE=bookworm, uses the Debian-based aarch64 branch (64-bit RPi OS Lite bookworm is Debian, not Raspbian), and keeps the SD image on the same base OS our curl|bash installer targets. Same pin in build.sh default, preview workflow, and release workflow. Observed on run 24878112852. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pi-gen's bookworm-arm64 branch checks for /usr/bin/qemu-aarch64- static (the -static variant from qemu-user-static), not qemu-arm like master does. Observed on run 24878263028 which debootstrapped bookworm successfully (after the PI_GEN_REF pin) and then tripped on "qemu-aarch64-static not found". --no-install-recommends still needed to block qemu-user-binfmt from registering wrapper handlers that break inside the chroot. Same fix in both workflows. Part of #183. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pi-gen runs NN-run-chroot.sh as \`on_chroot < script.sh\` — the
script is piped to bash inside the chroot as stdin, so its CWD
is the chroot root and the stage's files/ directory is
unreachable. Observed on run 24879975771 which got all the way
through Docker install before failing with
"cannot stat 'files/docker-compose.yml'".
The canonical pi-gen pattern (see stage2/01-sys-tweaks/01-run.sh)
is to use NN-run.sh instead: it executes on the host with CWD
set to the stage subdir, has read access to files/, can write
into the chroot via \${ROOTFS_DIR}/... paths, and gets a pi-gen-
exported on_chroot() helper for the handful of commands that
actually need to run inside the chroot (apt installs, systemctl
enable, sed /etc/hosts).
Restructured both our stages to that pattern:
- 01-ftw-setup/00-run-chroot.sh -> 00-run.sh
- 02-wifi-onboarding/01-run-chroot.sh -> 01-run.sh
Part of #183.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Real-hardware test on run 24881931326 booted a Pi from the workflow
artifact, but it was vanilla Raspberry Pi OS Lite — no Docker, no
ftw-firstboot, /home/ftw/ empty except for default dotfiles.
Three independent bugs all needed fixing:
1. Workflow uploaded the wrong image. pi-gen produced both
`…-42w-rpi4-arm64-lite.img.xz` (stage2 stock Lite, 467 MB) and
`…-42w-rpi4-arm64.img.xz` (stage-42w with our customizations,
562 MB). The artifact-finder did `ls *.img.xz | head -n1` —
alphabetical sort puts -lite ahead of the bare basename, so
the wrong one shipped. Replaced with an explicit pattern +
filter that rejects `-lite.img.xz` even if it appears.
2. Stage2 was emitting a separate image artifact at all. We need
stage2 to RUN (it's the rootfs base for stage-42w), but it
shouldn't produce its own `.img.xz`. Added stage2 to the
SKIP_IMAGES touch loop in build.sh — stage3-5 already had
both SKIP and SKIP_IMAGES; stage2 only needs SKIP_IMAGES.
3. /home/ftw/forty-two-watts/ was being clobbered at first boot.
Stage-42w wrote files to /home/ftw/ at build time, but the
bookworm-arm64 user-rename mechanism defers `pi → ftw` to a
first-boot wizard that runs `usermod -m`, moving /home/pi/*
onto /home/ftw/ — wiping anything we'd pre-staged at the
destination. Switched the install paths in 01-ftw-setup to
/home/pi/ so files travel with the rename and land in
/home/ftw/forty-two-watts/ exactly as firstboot.sh expects.
After these, the artifact should be the right image AND it should
boot with /home/ftw/forty-two-watts/{docker-compose.yml,…} present
and Docker installed, so ftw-firstboot can actually do its job.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 25, 2026
This was referenced Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships a flashable
42w-rpi4-arm64-vX.Y.Z.img.xzfor every release so new users can go from "downloaded file" to a working dashboard athttp://42w.local:8080/without a terminal.docker-compose.ymlinto a Raspberry Pi OS Lite (Bookworm) image, hostname42wso avahi gives us mDNS for free.ftw-firstboot.servicerunsdocker compose pull && up -don first boot.wifi-connectv4.11.84 fallback. If NetworkManager doesn't have a live connection ~30 s after boot, the Pi exposes a42w-setupAP + captive portal. Ordered before firstboot so docker pull doesn't race a dead network.rpi-imagejob inrelease.ymlso the image gets cut + uploaded to the GitHub Release alongside the existing binaries + docker tags.docs/rpi-image.mdplus a new Option A inREADME.md.Plus a companion
rpi-image-build.ymlworkflow that runs on PR pushes so the build gets CI signal before we ever cut a release.Closes #183.
Testing this PR
rpi-image build (on-demand)workflow fires automatically on this PR. Once green, grab the.img.xzfrom the workflow run's Artifacts panel (14-day retention).http://42w.local:8080/should respond within ~60 s on a pre-configured WiFi. If no WiFi: phone connects to42w-setup, portal opens automatically, user picks network.Test plan
rpi-image-buildworkflow goes green on this branchhttp://42w.local:8080/setupresponds42w-setupAP appears, captive portal opens, credentials accepted, Pi joins networkdocker compose pson the Pi shows all three services (forty-two-watts, ftw-updater, mosquitto) Upftw-updatersidecar pulls a new image when triggered from the UI)ftw-firstboot, no repeat captive portal42w.localresolves on macOS + Linux + Windows + iOS + AndroidNot in this PR (follow-ups, good-first-issues)
/boot/42w.txtoverrides,docker system prunetuning, retry-on-reboot refinement. Wait for first hands-on test to know what to fix.POST /api/wifi/resetendpoint in the Go app so re-onboarding doesn't require SSH🤖 Generated with Claude Code