summaryrefslogtreecommitdiff
path: root/scripts/run_qemu.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/run_qemu.sh')
-rwxr-xr-xscripts/run_qemu.sh110
1 files changed, 110 insertions, 0 deletions
diff --git a/scripts/run_qemu.sh b/scripts/run_qemu.sh
new file mode 100755
index 0000000..f48f445
--- /dev/null
+++ b/scripts/run_qemu.sh
@@ -0,0 +1,110 @@
+#!/bin/bash
+# ============================================================================
+# run_qemu.sh — Launch QEMU with UEFI firmware
+#
+# Usage: run_qemu.sh <arch> <disk_image>
+#
+# Requirements:
+# x86_64: OVMF firmware (usually in /usr/share/OVMF/ or /usr/share/edk2/)
+# aarch64: AAVMF firmware (usually in /usr/share/AAVMF/ or qemu-efi-aarch64)
+# ============================================================================
+
+set -e
+
+ARCH="$1"
+DISK="$2"
+
+if [ -z "$ARCH" ] || [ -z "$DISK" ]; then
+ echo "Usage: $0 <arch> <disk_image>"
+ exit 1
+fi
+
+# ── Find UEFI firmware ─────────────────────────────────────────────────────
+
+find_firmware() {
+ local candidates=("$@")
+ for path in "${candidates[@]}"; do
+ if [ -f "$path" ]; then
+ echo "$path"
+ return 0
+ fi
+ done
+ return 1
+}
+
+if [ "$ARCH" = "x86_64" ]; then
+ QEMU=qemu-system-x86_64
+
+ # Common OVMF paths across distros
+ OVMF=$(find_firmware \
+ /usr/share/OVMF/OVMF_CODE.fd \
+ /usr/share/edk2/ovmf/OVMF_CODE.fd \
+ /usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
+ /usr/share/qemu/OVMF_CODE.fd \
+ /usr/share/OVMF/OVMF_CODE_4M.fd \
+ ) || {
+ echo "ERROR: Cannot find OVMF firmware."
+ echo "Install it: apt install ovmf OR dnf install edk2-ovmf"
+ exit 1
+ }
+
+ echo "Using OVMF: $OVMF"
+ echo "Starting QEMU x86_64..."
+ echo "Press Ctrl+A, X to exit QEMU"
+ echo "─────────────────────────────────────"
+
+ exec $QEMU \
+ -machine q35 \
+ -cpu qemu64 \
+ -m 256M \
+ -drive if=pflash,format=raw,readonly=on,file="$OVMF" \
+ -drive format=raw,file="$DISK" \
+ -serial stdio \
+ -no-reboot \
+ -no-shutdown \
+ -d int,cpu_reset \
+ -D qemu_log.txt
+
+elif [ "$ARCH" = "aarch64" ]; then
+ QEMU=qemu-system-aarch64
+
+ # Common AAVMF / EDK2 paths
+ AAVMF=$(find_firmware \
+ /usr/share/AAVMF/AAVMF_CODE.fd \
+ /usr/share/qemu-efi-aarch64/QEMU_EFI.fd \
+ /usr/share/edk2/aarch64/QEMU_EFI.fd \
+ /usr/share/edk2-aarch64/QEMU_EFI.fd \
+ ) || {
+ echo "ERROR: Cannot find AAVMF firmware."
+ echo "Install it: apt install qemu-efi-aarch64 OR dnf install edk2-aarch64"
+ exit 1
+ }
+
+ echo "Using AAVMF: $AAVMF"
+ echo "Starting QEMU aarch64..."
+ echo "Press Ctrl+A, X to exit QEMU"
+ echo "─────────────────────────────────────"
+
+ # Create a pflash variable store (AAVMF needs separate code + vars)
+ VARS_FILE="${DISK}.vars.fd"
+ if [ ! -f "$VARS_FILE" ]; then
+ dd if=/dev/zero of="$VARS_FILE" bs=1M count=64 status=none
+ fi
+
+ exec $QEMU \
+ -machine virt \
+ -cpu cortex-a72 \
+ -m 256M \
+ -drive if=pflash,format=raw,readonly=on,file="$AAVMF" \
+ -drive if=pflash,format=raw,file="$VARS_FILE" \
+ -drive format=raw,file="$DISK" \
+ -serial stdio \
+ -no-reboot \
+ -no-shutdown \
+ -d int,cpu_reset \
+ -D qemu_log.txt
+
+else
+ echo "Unknown architecture: $ARCH"
+ exit 1
+fi