54 lines
1.8 KiB
Bash
54 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Boots the Fennec OS image in QEMU (KVM). Under WSL the window shows up via WSLg.
|
|
# sudo bash image/run-qemu.sh [--no-gl] [--bt VID:PID]
|
|
# ssh into the VM: ssh -p 2222 root@localhost (password: smartfox)
|
|
set -euo pipefail
|
|
|
|
WORK="${SMARTFOX_WORK:-/root/smartfox}"
|
|
IMG="$WORK/image/mkosi.output/smartfox.raw"
|
|
VARS="$WORK/image/ovmf-vars.fd"
|
|
GL=1
|
|
BT=""
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--no-gl) GL=0 ;;
|
|
--bt) BT="$2"; shift ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Free space for the data partition (/var) that the image creates on first boot.
|
|
if [ "$(stat -c %s "$IMG")" -lt $((8 * 1024 * 1024 * 1024)) ]; then
|
|
truncate -s 8G "$IMG"
|
|
fi
|
|
|
|
CODE=/usr/share/OVMF/OVMF_CODE_4M.fd
|
|
[ -f "$VARS" ] || cp /usr/share/OVMF/OVMF_VARS_4M.fd "$VARS"
|
|
|
|
if [ "$GL" = 1 ]; then
|
|
GPU=(-device virtio-vga-gl,edid=on,xres=1920,yres=1080 -display gtk,gl=on,zoom-to-fit=on)
|
|
else
|
|
GPU=(-device virtio-vga,edid=on,xres=1920,yres=1080 -display gtk,zoom-to-fit=on)
|
|
fi
|
|
|
|
USB=(-device qemu-xhci,id=xhci)
|
|
if [ -n "$BT" ]; then
|
|
USB+=(-device "usb-host,bus=xhci.0,vendorid=0x${BT%%:*},productid=0x${BT##*:}")
|
|
fi
|
|
|
|
AUDIO=()
|
|
if [ -n "${PULSE_SERVER:-}" ] || [ -S /mnt/wslg/PulseServer ]; then
|
|
export PULSE_SERVER="${PULSE_SERVER:-unix:/mnt/wslg/PulseServer}"
|
|
AUDIO=(-audiodev pa,id=snd0 -device ich9-intel-hda -device hda-output,audiodev=snd0)
|
|
fi
|
|
|
|
exec qemu-system-x86_64 \
|
|
-name "Fennec OS" -machine q35,accel=kvm -cpu host -smp 4 -m 4096 \
|
|
-drive if=pflash,format=raw,readonly=on,file="$CODE" \
|
|
-drive if=pflash,format=raw,file="$VARS" \
|
|
-drive file="$IMG",format=raw,if=virtio \
|
|
"${GPU[@]}" "${USB[@]}" "${AUDIO[@]}" \
|
|
-device usb-tablet,bus=xhci.0 \
|
|
-monitor unix:/root/qemu-monitor.sock,server,nowait \
|
|
-nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22
|