Skip to main content

max / mountaineer

2.5 KB · 79 lines History Blame Raw
1 #!/bin/sh
2 # vm-test-boot.sh — boot the latest Mountaineer ISO in a fresh disposable
3 # target VM, NO install config attached. The live env comes up; ssh in
4 # on TARGET_SSH_PORT with the builder ed25519 key.
5 #
6 # Useful for poking at the live environment, verifying the apkovl
7 # applied, running `mountaineer-install --dry-run` interactively, etc.
8 #
9 # For the unattended install loop, use vm-test-install.sh.
10
11 . "$(dirname "$0")/common.sh"
12 ensure_dirs
13
14 ISO=$(ls -t "$ROOT/out"/*.iso 2>/dev/null | head -1 || true)
15 if [ -z "$ISO" ] || [ ! -f "$ISO" ]; then
16 echo "error: no ISO found in $ROOT/out/. Run tools/qemu/vm-build.sh first." >&2
17 exit 1
18 fi
19
20 TARGET_DISK="$DISK_DIR/target.qcow2"
21 TARGET_SIZE="${TARGET_SIZE:-20G}"
22 NVRAM="$NVRAM_DIR/target_VARS.fd"
23
24 # Fresh disk + NVRAM every run.
25 rm -f "$TARGET_DISK" "$NVRAM" "$VMS/target.pid"
26 qemu-img create -f qcow2 "$TARGET_DISK" "$TARGET_SIZE" >/dev/null
27 cp "$OVMF_VARS_TEMPLATE" "$NVRAM"
28
29 LOG="$VMS/logs/target-boot-serial.log"
30 MON="$VMS/sockets/target-mon.sock"
31 rm -f "$LOG" "$MON"
32
33 echo "==> booting target VM with $ISO (no install config)"
34 # shellcheck disable=SC2046,SC2086
35 qemu-system-x86_64 \
36 -name target \
37 -machine type=q35 \
38 $ACCEL_ARGS \
39 -cpu max -smp $SMP -m $MEM \
40 -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \
41 -drive if=pflash,format=raw,file="$NVRAM" \
42 -drive file="$TARGET_DISK",if=virtio,format=qcow2 \
43 -cdrom "$ISO" \
44 -boot d \
45 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:$TARGET_SSH_PORT-:22 \
46 -device virtio-net-pci,netdev=net0 \
47 -device virtio-rng-pci \
48 -display none \
49 -serial file:"$LOG" \
50 -monitor unix:"$MON",server,nowait \
51 -daemonize \
52 -pidfile "$VMS/target.pid"
53
54 echo "==> target VM running (pid $(cat $VMS/target.pid))"
55 echo " serial log: $LOG"
56 echo " ssh: ssh -p $TARGET_SSH_PORT -i $KEYS_DIR/builder_ed25519 root@127.0.0.1"
57 echo " stop: printf 'quit\\n' | nc -U $MON"
58 echo ""
59 echo "==> waiting up to 5 min for sshd to come up on 127.0.0.1:$TARGET_SSH_PORT"
60 deadline=$(( $(date +%s) + 300 ))
61 while [ "$(date +%s)" -lt "$deadline" ]; do
62 if ssh -p "$TARGET_SSH_PORT" \
63 -i "$KEYS_DIR/builder_ed25519" \
64 -o StrictHostKeyChecking=no \
65 -o UserKnownHostsFile=/dev/null \
66 -o ConnectTimeout=3 \
67 -o BatchMode=yes \
68 root@127.0.0.1 'true' 2>/dev/null; then
69 echo "==> ssh ready"
70 exit 0
71 fi
72 sleep 5
73 printf '.'
74 done
75
76 echo ""
77 echo "warning: sshd not reachable in 5 min — check $LOG"
78 exit 1
79