tools/vm: install-vm.sh, a VM that installs Fennec OS from the installer ISO
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
69
tools/vm/install-vm.sh
Executable file
69
tools/vm/install-vm.sh
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# A VM that installs Fennec OS from the installer ISO, like a real machine
|
||||||
|
# from a USB stick: an empty disk, the ISO as a CD. Headless; drive it with
|
||||||
|
# the other tools/vm scripts (the monitor socket and the ssh port are the
|
||||||
|
# same as run-qemu.sh's, so only one of the two VMs can run at a time).
|
||||||
|
#
|
||||||
|
# sudo bash tools/vm/install-vm.sh install # wipe the disk, boot the ISO
|
||||||
|
# sudo bash tools/vm/install-vm.sh boot # boot the installed disk
|
||||||
|
# sudo bash tools/vm/install-vm.sh stop
|
||||||
|
#
|
||||||
|
# screenshot.sh /root/shot.png what the screen shows (installer, launcher)
|
||||||
|
# vmkey.sh 1 ret key presses (the installer asks for a disk
|
||||||
|
# number, then "igen")
|
||||||
|
# vmssh.sh --wait 'cmd' ssh into the installed system (in a VM sshd
|
||||||
|
# is on without the remote debugging switch)
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SRC="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||||
|
WORK="${SMARTFOX_WORK:-/root/smartfox}"
|
||||||
|
ISO="${ISO:-$SRC/image/out/smartfox-installer.iso}"
|
||||||
|
DIR="$WORK/image/install-vm"
|
||||||
|
DISK="$DIR/disk.raw"
|
||||||
|
VARS="$DIR/ovmf-vars.fd"
|
||||||
|
MON=/root/qemu-monitor.sock
|
||||||
|
PID="$DIR/qemu.pid"
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
if [ -f "$PID" ] && kill -0 "$(cat "$PID")" 2>/dev/null; then
|
||||||
|
echo quit | socat - UNIX-CONNECT:"$MON" >/dev/null 2>&1 || kill "$(cat "$PID")"
|
||||||
|
for _ in $(seq 20); do kill -0 "$(cat "$PID")" 2>/dev/null || break; sleep 0.5; done
|
||||||
|
fi
|
||||||
|
rm -f "$PID"
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
local cd=()
|
||||||
|
[ "${1:-}" = iso ] && cd=(-drive file="$ISO",media=cdrom,readonly=on,if=none,id=cd -device ide-cd,drive=cd,bootindex=0)
|
||||||
|
qemu-system-x86_64 \
|
||||||
|
-name "Fennec OS (install VM)" -machine q35,accel=kvm -cpu host -smp 4 -m 4096 \
|
||||||
|
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
|
||||||
|
-drive if=pflash,format=raw,file="$VARS" \
|
||||||
|
-drive file="$DISK",format=raw,if=none,id=disk -device virtio-blk-pci,drive=disk,bootindex=1 \
|
||||||
|
"${cd[@]}" \
|
||||||
|
-device virtio-vga,edid=on,xres=1920,yres=1080 -display none \
|
||||||
|
-device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0 \
|
||||||
|
-monitor unix:"$MON",server,nowait \
|
||||||
|
-nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 \
|
||||||
|
-daemonize -pidfile "$PID"
|
||||||
|
echo "VM running (pid $(cat "$PID"))"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${1:-}" in
|
||||||
|
install)
|
||||||
|
[ -f "$ISO" ] || { echo "missing $ISO (image/build-iso.sh)"; exit 1; }
|
||||||
|
stop
|
||||||
|
mkdir -p "$DIR"
|
||||||
|
rm -f "$DISK"
|
||||||
|
truncate -s "${DISK_SIZE:-32G}" "$DISK"
|
||||||
|
cp /usr/share/OVMF/OVMF_VARS_4M.fd "$VARS"
|
||||||
|
start iso
|
||||||
|
;;
|
||||||
|
boot)
|
||||||
|
[ -f "$DISK" ] || { echo "nothing installed yet: install first"; exit 1; }
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop) stop ;;
|
||||||
|
*) sed -n '2,17p' "$0"; exit 2 ;;
|
||||||
|
esac
|
||||||
Reference in New Issue
Block a user