#!/usr/bin/env bash set -euo pipefail set -x # Default values ISO_FILE="" MEMORY="2048" CPUS="2" ARCH="" NOGRAPHIC=false usage() { cat </dev/null || echo "") if echo "$ISO_LABEL" | grep -q "aarch64"; then ARCH="aarch64" elif echo "$ISO_LABEL" | grep -q "x86"; then ARCH="x86_64" else echo "Could not detect architecture from ISO. Please specify with -a option." echo "Supported architectures: x86_64, aarch64" exit 1 fi fi fi echo "Booting $ISO_FILE with $ARCH architecture..." echo "Memory: $MEMORY MB, CPUs: $CPUS" # Build QEMU command based on architecture if [ "$ARCH" = "x86_64" ]; then echo "Starting x86_64 VM with EFI..." # Get the x86_64-linux UEFI firmware echo "Building x86_64-linux UEFI firmware..." UEFI_STORE_PATH=$(nix build --no-link --print-out-paths --system x86_64-linux nixpkgs#OVMF.fd) UEFI_FW="$UEFI_STORE_PATH/FV/OVMF.fd" if [ ! -f "$UEFI_FW" ]; then echo "Error: Could not find x86_64 UEFI firmware at $UEFI_FW" exit 1 fi echo "Using UEFI firmware: $UEFI_FW" if [ "$NOGRAPHIC" = true ]; then exec qemu-system-x86_64 \ -machine q35 \ -cpu qemu64 \ -m "$MEMORY" \ -smp "$CPUS" \ -accel tcg \ -bios "$UEFI_FW" \ -cdrom "$ISO_FILE" \ -boot d \ -nographic \ -serial mon:stdio else exec qemu-system-x86_64 \ -machine q35 \ -cpu qemu64 \ -m "$MEMORY" \ -smp "$CPUS" \ -accel tcg \ -bios "$UEFI_FW" \ -cdrom "$ISO_FILE" \ -boot d fi elif [ "$ARCH" = "aarch64" ]; then echo "Starting aarch64 VM..." # Get the aarch64-linux UEFI firmware echo "Building aarch64 UEFI firmware..." # Use the pre-built firmware path we know works UEFI_FW="/nix/store/2ciakp99mrcb3fx98j6ji0nxkxcyq5gy-OVMF-202505-fd/FV/QEMU_EFI.fd" if [ ! -f "$UEFI_FW" ]; then echo "Firmware not found in store, building..." UEFI_STORE_PATH=$(nix build --no-link --print-out-paths nixpkgs#OVMF-fd.aarch64-linux) UEFI_FW="$UEFI_STORE_PATH/FV/QEMU_EFI.fd" fi if [ ! -f "$UEFI_FW" ]; then echo "Error: Could not find aarch64 UEFI firmware at $UEFI_FW" exit 1 fi echo "Using UEFI firmware: $UEFI_FW" if [ "$NOGRAPHIC" = true ]; then exec qemu-system-aarch64 \ -machine virt \ -cpu cortex-a57 \ -m "$MEMORY" \ -smp "$CPUS" \ -accel tcg \ -bios "$UEFI_FW" \ -cdrom "$ISO_FILE" \ -boot d \ -nographic else exec qemu-system-aarch64 \ -machine virt \ -cpu cortex-a57 \ -m "$MEMORY" \ -smp "$CPUS" \ -accel tcg \ -bios "$UEFI_FW" \ -cdrom "$ISO_FILE" \ -boot d fi else echo "Error: Unsupported architecture '$ARCH'" echo "Supported architectures: x86_64, aarch64" exit 1 fi