refactor(vm): share QEMU profile builder in ISO launcher
- commit
- 941cbebda5fafa2ac2b74b0c2d3c5d4777cffa7f
- author
- brice · · 2026-02-27 04:45 UTC
- parent
- 1501418
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +29 -22
M test/vm/start-qemu-arch-iso.sh +29 -22
| @@ -1,32 +1,39 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | - | # Start Arch ISO in QEMU with UEFI support and SSH access | |
| 2 | + | # Start Arch ISO in QEMU with realistic hardware profile | |
| 3 | + | # Usage: ./start-qemu-arch-iso.sh [--profile desktop|laptop] [--secure-boot on|off] [--ssh-port PORT] | |
| 4 | + | set -euo pipefail | |
| 3 | 5 | ||
| 4 | - | set -e | |
| 5 | - | ||
| 6 | - | # Get test directory | |
| 7 | 6 | TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| 8 | 7 | ISO_FILE="$TEST_DIR/archlinux-x86_64.iso" | |
| 9 | 8 | ISO_URL="https://geo.mirror.pkgbuild.com/iso/latest/archlinux-x86_64.iso" | |
| 10 | 9 | ||
| 11 | - | # Download latest Arch ISO if not present | |
| 10 | + | PROFILE="desktop" | |
| 11 | + | SECURE_BOOT="off" | |
| 12 | + | SSH_PORT="2222" | |
| 13 | + | ||
| 14 | + | while [[ $# -gt 0 ]]; do | |
| 15 | + | case "$1" in | |
| 16 | + | --profile) PROFILE="$2"; shift 2 ;; | |
| 17 | + | --secure-boot) SECURE_BOOT="$2"; shift 2 ;; | |
| 18 | + | --ssh-port) SSH_PORT="$2"; shift 2 ;; | |
| 19 | + | *) echo "Unknown flag: $1"; exit 1 ;; | |
| 20 | + | esac | |
| 21 | + | done | |
| 22 | + | ||
| 12 | 23 | if [[ ! -f "$ISO_FILE" ]]; then | |
| 13 | - | echo "Arch Linux ISO not found in $TEST_DIR" | |
| 14 | - | echo "Downloading latest Arch ISO from $ISO_URL..." | |
| 15 | - | curl -L -o "$ISO_FILE" "$ISO_URL" | |
| 16 | - | echo "Download complete!" | |
| 24 | + | echo "Arch Linux ISO not found in $TEST_DIR" | |
| 25 | + | echo "Downloading latest Arch ISO from $ISO_URL..." | |
| 26 | + | curl -L -o "$ISO_FILE" "$ISO_URL" | |
| 27 | + | echo "Download complete!" | |
| 17 | 28 | else | |
| 18 | - | echo "Using existing ISO: $ISO_FILE" | |
| 29 | + | echo "Using existing ISO: $ISO_FILE" | |
| 19 | 30 | fi | |
| 20 | 31 | ||
| 21 | - | qemu-system-x86_64 \ | |
| 22 | - | -enable-kvm \ | |
| 23 | - | -m 2048 \ | |
| 24 | - | -smp 2 \ | |
| 25 | - | -bios /usr/share/edk2/x64/OVMF.4m.fd \ | |
| 26 | - | -boot d \ | |
| 27 | - | -cdrom "$ISO_FILE" \ | |
| 28 | - | -drive file="$TEST_DIR/arch-test.qcow2",format=qcow2,if=virtio \ | |
| 29 | - | -display gtk \ | |
| 30 | - | -vga virtio \ | |
| 31 | - | -net nic,model=virtio \ | |
| 32 | - | -net user,hostfwd=tcp::2222-:22 | |
| 32 | + | source "$TEST_DIR/lib/qemu-profile.sh" | |
| 33 | + | build_qemu_args "$PROFILE" "$SECURE_BOOT" "$SSH_PORT" "$TEST_DIR" | |
| 34 | + | ||
| 35 | + | # ISO boot additions | |
| 36 | + | QEMU_ARGS+=(-boot d) | |
| 37 | + | QEMU_ARGS+=(-cdrom "$ISO_FILE") | |
| 38 | + | ||
| 39 | + | exec qemu-system-x86_64 "${QEMU_ARGS[@]}" | |
| @@ -1,32 +1,39 @@ | |||||
| 1 | #!/bin/bash | 1 | #!/bin/bash | ||
| 2 | - | # Start Arch ISO in QEMU with UEFI support and SSH access | 2 | + | # Start Arch ISO in QEMU with realistic hardware profile |
| 3 | + | # Usage: ./start-qemu-arch-iso.sh [--profile desktop|laptop] [--secure-boot on|off] [--ssh-port PORT] | |||
| 4 | + | set -euo pipefail | |||
| 3 | 5 | ||||
| 4 | - | set -e | |||
| 5 | - | ||||
| 6 | - | # Get test directory | |||
| 7 | TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | 6 | TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 8 | ISO_FILE="$TEST_DIR/archlinux-x86_64.iso" | 7 | ISO_FILE="$TEST_DIR/archlinux-x86_64.iso" | ||
| 9 | ISO_URL="https://geo.mirror.pkgbuild.com/iso/latest/archlinux-x86_64.iso" | 8 | ISO_URL="https://geo.mirror.pkgbuild.com/iso/latest/archlinux-x86_64.iso" | ||
| 10 | 9 | ||||
| 11 | - | # Download latest Arch ISO if not present | 10 | + | PROFILE="desktop" |
| 11 | + | SECURE_BOOT="off" | |||
| 12 | + | SSH_PORT="2222" | |||
| 13 | + | ||||
| 14 | + | while [[ $# -gt 0 ]]; do | |||
| 15 | + | case "$1" in | |||
| 16 | + | --profile) PROFILE="$2"; shift 2 ;; | |||
| 17 | + | --secure-boot) SECURE_BOOT="$2"; shift 2 ;; | |||
| 18 | + | --ssh-port) SSH_PORT="$2"; shift 2 ;; | |||
| 19 | + | *) echo "Unknown flag: $1"; exit 1 ;; | |||
| 20 | + | esac | |||
| 21 | + | done | |||
| 22 | + | ||||
| 12 | if [[ ! -f "$ISO_FILE" ]]; then | 23 | if [[ ! -f "$ISO_FILE" ]]; then | ||
| 13 | - | echo "Arch Linux ISO not found in $TEST_DIR" | 24 | + | echo "Arch Linux ISO not found in $TEST_DIR" |
| 14 | - | echo "Downloading latest Arch ISO from $ISO_URL..." | 25 | + | echo "Downloading latest Arch ISO from $ISO_URL..." |
| 15 | - | curl -L -o "$ISO_FILE" "$ISO_URL" | 26 | + | curl -L -o "$ISO_FILE" "$ISO_URL" |
| 16 | - | echo "Download complete!" | 27 | + | echo "Download complete!" |
| 17 | else | 28 | else | ||
| 18 | - | echo "Using existing ISO: $ISO_FILE" | 29 | + | echo "Using existing ISO: $ISO_FILE" |
| 19 | fi | 30 | fi | ||
| 20 | 31 | ||||
| 21 | - | qemu-system-x86_64 \ | 32 | + | source "$TEST_DIR/lib/qemu-profile.sh" |
| 22 | - | -enable-kvm \ | 33 | + | build_qemu_args "$PROFILE" "$SECURE_BOOT" "$SSH_PORT" "$TEST_DIR" |
| 23 | - | -m 2048 \ | 34 | + | |
| 24 | - | -smp 2 \ | 35 | + | # ISO boot additions |
| 25 | - | -bios /usr/share/edk2/x64/OVMF.4m.fd \ | 36 | + | QEMU_ARGS+=(-boot d) |
| 26 | - | -boot d \ | 37 | + | QEMU_ARGS+=(-cdrom "$ISO_FILE") |
| 27 | - | -cdrom "$ISO_FILE" \ | 38 | + | |
| 28 | - | -drive file="$TEST_DIR/arch-test.qcow2",format=qcow2,if=virtio \ | 39 | + | exec qemu-system-x86_64 "${QEMU_ARGS[@]}" |
| 29 | - | -display gtk \ | |||
| 30 | - | -vga virtio \ | |||
| 31 | - | -net nic,model=virtio \ | |||
| 32 | - | -net user,hostfwd=tcp::2222-:22 | |||