Touches both boot scripts (`vm/boot-x86.sh`, `vm/boot-arm64.sh`) and the arm64 snapshot helper. No Rust, no device or backend code. A rail is one guest OS line. Rails are siblings under `vm/disks/rails/` (x86) and `vm/guest/rails/` (arm64), each owning its own immutable snapshot history, and `rails/current` names the one a bare boot gets: <rails>/<rail>/snapshots/<label>/... <rails>/<rail>/snapshots/current -> <label> <rails>/current -> <rail> Two coordinates select what boots — `--rail NAME` and `--snapshot LABEL`, each with its own `current` — and neither repoints anything. Snapshots could not stay flat once a second guest line existed: two lines share no history, so one namespace makes `current` mean "whichever guest was captured last", which is how a measurement gets attributed to the wrong OS. Captures land in the selected rail and move only that rail's `current`; `rails/current` is never touched, so capturing on one line cannot silently change what the next bare boot runs. An unknown rail or a half-populated snapshot is an error in every boot class. Falling through to the bootstrap path would boot the provisioned masters instead — a different guest than the one asked for — and under capture would then repoint `current` at it. Capture is now `--capture`. A bare `--snapshot` still means capture, because that is how every existing invocation in the docs and helper scripts spells it; with a label it selects instead. `--list-rails` and `--list-snapshots` answer before anything is built. A snapshot may carry its own `OVMF_CODE.fd` (x86) and a rail its own `vm.json` (arm64). A macOS release is installed under whatever OVMF build its installer ran on, and the NVRAM in `OVMF_VARS.fd` only means anything to the code half that wrote it — a split OVMF pair is a matched set. Likewise the ECID identifies the machine a guest was personalized against, so a second provisioned guest is a second vm.json rather than a second disk under the first one's identity. Both override only when present; a single-guest tree behaves exactly as before. An arm64 tree still holding `vm/guest/snapshots/` now refuses to boot and prints the three-line move that fixes it. That history is someone's only copy of a provisioned guest, and a boot script is the wrong thing to have rearranged it silently. Cleanups, each within one file rather than a shared one: - boot-x86.sh: the kernel-panic report was written out twice — once in the poll loop, once after QEMU exits on the panic reboot that `-action reboot=shutdown` turns into an apparently clean exit. Same regex, excerpt, keep-dir, exit code, and `basename` recomputed four times. Now `serial_has_panic` + `report_panic_and_revert`, called from both. - boot-arm64.sh: `--device NAME` and `--device=NAME` each carried a copy of the accepted set and the error string; they now share `set_gfx_device`, matching what boot-x86.sh already did. - boot-arm64.sh: `cp -c … || cp …` at four call sites becomes one `clone_file`, again matching boot-x86.sh. Verified on the x86 pathway, Linux host, rail `macos-13` (the guest the previous flat `current` pointed at, imported as a rail so the default boot is unchanged): - `--testing --device reims-vgpu-pci` boots and the guest answers SSH as macOS 13.7.8 — the pre-change behavior of a bare boot, preserved. - `--testing --device vmware-svga --rail macos-13` with TESTING_TIMEOUT=60 exits 124 through capture-then-revert and leaves no clone in the run dir, so the testing loop still works with the panic refactor inside it. - `--rail macos-11 --testing` reverts that rail and reaches the guest desktop. - Refusals exercised against a scratch tree: unknown rail, unknown snapshot, half-populated snapshot, `--rail ../etc`, unset default rail, and the pre-rail migration notice. - `serial_has_panic` / `report_panic_and_revert` driven against a synthetic serial log: clean log detects nothing, panicking log reproduces the excerpt, keep-file and message the two copies produced. - `clone_file` fallback exercised (GNU cp has no `-c`, so this host takes it). - Both `--device` spellings on both scripts accept and reject as before. - `bash -n` on both boot scripts and the snapshot helper. NOT verified: rails macos-12, macos-14, macos-15 and macos-26 are imported and resolve but were never booted. Nothing on the arm64 pathway ran — no Apple host — so its rail resolution, the per-rail vm.json, `clone_file` on APFS and the migration refusal were exercised only as far as a Linux shell reaches. `--capture` was not run on either pathway; no clean-shutdown capture happened. shellcheck is not installed on this host. Separately measured and NOT addressed here: rail macos-11 under `--device reims-vgpu-pci` boots, binds and presents zero-copy, but the composited frame is empty (`present_black_retain`, alpha-only) and the screen is black. Big Sur bring-up on the product device is its own problem, not an artifact of the import — the same snapshot renders under vmware-svga. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
90 lines
3.8 KiB
Bash
Executable File
90 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# scripts/vmapple-provision/vmapple-provision.sh
|
|
#
|
|
# Provision a FRESH arm macOS guest in this workspace (vm/guest/) with `macosvm`
|
|
# (the Virtualization.framework CLI). macosvm restores macOS from an IPSW
|
|
# non-interactively (VZMacOSInstaller) into a raw disk + aux image that QEMU's
|
|
# vmapple boots directly.
|
|
#
|
|
# Target: macOS 13.x (Ventura; 13.6/22G120 is the last 13.x with a full-restore
|
|
# IPSW — 13.7.x were OTA-only). Upstream vmapple documents only 12.x guests, but
|
|
# our fork carries the RFC v7 gicv2m/MSI patches for newer guests; 12.x remains
|
|
# the fallback. We do NOT apply RFC v7 patch 7 (the Tahoe private-ISA path needs
|
|
# host SIP disabled).
|
|
#
|
|
# Everything lands in-workspace; nothing is copied from any external tree.
|
|
#
|
|
# Usage:
|
|
# vmapple-provision.sh /path/to/UniversalMac_13.x_Restore.ipsw
|
|
# IPSW=/path/to.ipsw GUEST_DIR=... vmapple-provision.sh
|
|
#
|
|
# After this finishes, one interactive boot completes Setup Assistant + enables
|
|
# Remote Login (see the printed next steps), then the bundle is the golden image.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
|
|
GUEST_DIR="${GUEST_DIR:-$REPO_ROOT/vm/guest}"
|
|
DISK_SIZE="${DISK_SIZE:-64g}"
|
|
CPUS="${CPUS:-4}"
|
|
RAM="${RAM:-8g}"
|
|
# Pin the NIC MAC to the SAME value vm/boot-arm64.sh uses. Critical: a stable MAC from
|
|
# first boot means macOS configures networking for it once and that config stays
|
|
# valid across snapshot reverts (a changing MAC poisons the guest's network state
|
|
# and breaks DHCP on every reverted boot).
|
|
GUEST_MAC="${GUEST_MAC:-52:54:00:76:61:70}"
|
|
IPSW="${IPSW:-${1:-}}"
|
|
|
|
die() { echo "vmapple-provision: $*" >&2; exit 1; }
|
|
|
|
command -v macosvm >/dev/null || die "macosvm not found (brew install macosvm or build s-u/macosvm)"
|
|
[ -n "$IPSW" ] || die "no IPSW given. Pass the path to a UniversalMac restore IPSW (13.x target, 12.x fallback):
|
|
vmapple-provision.sh vm/ipsw/UniversalMac_13.6_22G120_Restore.ipsw
|
|
Acquire one (~13 GB) into vm/ipsw/ first (see scripts/vmapple-provision/README.md)."
|
|
[ -f "$IPSW" ] || die "IPSW not found: $IPSW"
|
|
|
|
mkdir -p "$GUEST_DIR"
|
|
DISK="$GUEST_DIR/disk.img"
|
|
AUX="$GUEST_DIR/aux.img"
|
|
VMJSON="$GUEST_DIR/vm.json"
|
|
|
|
if [ -f "$DISK" ]; then
|
|
die "refusing to overwrite an existing bundle at $GUEST_DIR (remove it first to re-provision)"
|
|
fi
|
|
|
|
echo "vmapple-provision: restoring $IPSW → $GUEST_DIR (this takes a while) ..."
|
|
# macosvm creates the disk + aux, restores macOS from the IPSW, and writes the VZ
|
|
# config (incl. machineId/ECID + hardwareModel) to the trailing config path.
|
|
macosvm \
|
|
--disk "$DISK,size=$DISK_SIZE" \
|
|
--aux "$AUX" \
|
|
--restore "$IPSW" \
|
|
--net nat \
|
|
--mac "$GUEST_MAC" \
|
|
-c "$CPUS" \
|
|
-r "$RAM" \
|
|
"$VMJSON"
|
|
|
|
[ -f "$VMJSON" ] || die "macosvm did not write $VMJSON (restore failed?)"
|
|
|
|
# Trim the aux metadata page for QEMU's vmapple (docs/system/arm/vmapple.rst).
|
|
echo "vmapple-provision: trimming aux.img → aux.img.trimmed for QEMU vmapple ..."
|
|
dd if="$AUX" of="$GUEST_DIR/aux.img.trimmed" bs=$((0x4000)) skip=1 status=none
|
|
|
|
UUID="$(plutil -extract machineId raw "$VMJSON" | base64 -d | plutil -extract ECID raw -)"
|
|
cat <<EOF
|
|
|
|
vmapple-provision: DONE. Golden-image bundle at $GUEST_DIR
|
|
disk.img / aux.img / aux.img.trimmed / vm.json (ECID/uuid=$UUID)
|
|
|
|
Next (one bootstrap boot to finish the golden image):
|
|
1. mkdir -p vm/guest/rails/<rail> # a rail is one guest OS line; name it for the OS
|
|
vm/boot-arm64.sh --rail <rail> --capture # rail is empty → boots write-through; complete Setup Assistant
|
|
2. In the guest: enable Remote Login (sudo systemsetup -setremotelogin on), then run
|
|
scripts/vmapple-guest-config (sleep off, SSH kept on)
|
|
3. Shut the guest down cleanly — that captures the first immutable snapshot
|
|
4. vm/boot-arm64.sh --testing then reverts to it; confirm ssh reaches localhost:2222
|
|
EOF
|