phoebus_os/installer/tests/vm/run-vm.sh
Phoebus 38214ea9e7 chore: import Phoebus OS installer and Rust migration
Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored.

Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
2026-09-20 02:07:33 -07:00

115 lines
3 KiB
Bash
Executable file

#!/usr/bin/env bash
# shellcheck shell=bash
#
# Boot a disposable UEFI VM with a scratch disk for installer testing.
#
# run-vm.sh --iso /path/to/livegui.iso --disk-size 32G --workdir /tmp/phoebus-vm
#
# The VM disk is a qcow2 file inside the work directory. No host disk is ever
# touched. Delete the work directory to discard the test.
set -euo pipefail
ISO=""
DISK_SIZE="32G"
WORKDIR="${TMPDIR:-/tmp}/phoebus-vm"
MEM="4096"
CPUS="4"
BOOT="d"
EXTRA=()
usage() {
cat <<'EOF'
Usage: run-vm.sh --iso PATH [options]
Options:
--iso PATH Live ISO to boot (required)
--disk-size SIZE Scratch disk size (default 32G)
--workdir DIR Directory for the scratch disk (default /tmp/phoebus-vm)
--mem MiB RAM in MiB (default 4096)
--cpus N vCPUs (default 4)
--disk-boot Boot from the scratch disk instead of the ISO
--help Show this help
Requires qemu-system-x86_64 and OVMF (edk2) firmware.
EOF
}
while (($#)); do
case "$1" in
--iso) shift; ISO="${1:-}" ;;
--disk-size) shift; DISK_SIZE="${1:-}" ;;
--workdir) shift; WORKDIR="${1:-}" ;;
--mem) shift; MEM="${1:-}" ;;
--cpus) shift; CPUS="${1:-}" ;;
--disk-boot) BOOT="c" ;;
--help|-h) usage; exit 0 ;;
*) echo "unknown option: $1" >&2; usage; exit 2 ;;
esac
shift
done
[[ -n "$ISO" ]] || { echo "error: --iso is required" >&2; usage; exit 2; }
[[ -r "$ISO" ]] || { echo "error: cannot read ISO: $ISO" >&2; exit 2; }
command -v qemu-system-x86_64 >/dev/null 2>&1 || {
echo "error: qemu-system-x86_64 not found" >&2; exit 1; }
# Locate OVMF firmware.
OVMF_CODE=""
OVMF_VARS_SRC=""
for cand in \
/usr/share/OVMF/OVMF_CODE.fd \
/usr/share/OVMF/OVMF_CODE_4M.fd \
/usr/share/edk2/x64/OVMF_CODE.fd \
/usr/share/edk2-ovmf/x64/OVMF_CODE.fd; do
if [[ -r "$cand" ]]; then OVMF_CODE="$cand"; fi
done
for cand in \
/usr/share/OVMF/OVMF_VARS.fd \
/usr/share/OVMF/OVMF_VARS_4M.fd \
/usr/share/edk2/x64/OVMF_VARS.fd \
/usr/share/edk2-ovmf/x64/OVMF_VARS.fd; do
if [[ -r "$cand" ]]; then OVMF_VARS_SRC="$cand"; fi
done
[[ -n "$OVMF_CODE" ]] || { echo "error: OVMF firmware not found" >&2; exit 1; }
mkdir -p "$WORKDIR"
DISK="$WORKDIR/phoebus-test.qcow2"
VARS="$WORKDIR/OVMF_VARS.fd"
if [[ ! -f "$DISK" ]]; then
echo "creating scratch disk $DISK ($DISK_SIZE)"
qemu-img create -f qcow2 "$DISK" "$DISK_SIZE" >/dev/null
fi
if [[ ! -f "$VARS" ]]; then
cp "$OVMF_VARS_SRC" "$VARS"
fi
ACCEL=()
if [[ -w /dev/kvm ]]; then ACCEL=(-enable-kvm); fi
echo "ISO: $ISO"
echo "Disk: $DISK"
echo "Workdir: $WORKDIR"
echo "Firmware:$OVMF_CODE"
echo
echo "Inside the VM run: /path/to/installer/bin/ai-installer"
echo "Remember: the scratch disk is disposable."
QEMU=(qemu-system-x86_64
-machine q35
"${ACCEL[@]}"
-m "$MEM"
-smp "$CPUS"
-cpu host
-drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE"
-drive if=pflash,format=raw,file="$VARS"
-drive file="$DISK",if=virtio,format=qcow2
-netdev user,id=n0 -device virtio-net-pci,netdev=n0
-device virtio-vga
-boot "order=$BOOT"
-cdrom "$ISO"
)
exec "${QEMU[@]}" "${EXTRA[@]}"