#!/usr/bin/env bash # # Copyright 2025, Stormux, # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this package; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # # Boot Stormux x86_64 ISO in QEMU with audio support set -e # Parse command line arguments bootInstalled=false while getopts "ih" opt; do case "$opt" in i) bootInstalled=true ;; h) echo "Usage: $0 [options]" echo echo "Options:" echo " -i Boot from installed system (virtual disk) instead of ISO" echo " -h Show this help" echo echo "Without -i flag, boots from ISO with virtual disk attached for installation." echo "With -i flag, boots only from virtual disk (installed system)." exit 0 ;; *) echo "Use -h for help" exit 1 ;; esac done # Get the directory where this script is located scriptDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" outDir="${scriptDir}/out" logDir="${scriptDir}/logs" diskFile="${scriptDir}/stormux-test-disk.qcow2" # Create logs directory if it doesn't exist mkdir -p "$logDir" # Generate timestamp for log files timestamp=$(date +%Y%m%d_%H%M%S) qemuLog="${logDir}/qemu-boot_${timestamp}.log" serialLog="${logDir}/serial-console_${timestamp}.log" # Create virtual disk if it doesn't exist if [[ ! -f "$diskFile" ]]; then echo "Creating virtual disk: $diskFile (10GB)" qemu-img create -f qcow2 "$diskFile" 10G echo "Virtual disk created successfully" echo fi # Find ISO file (only needed if not booting installed system) isoFile="" if [[ "$bootInstalled" == false ]]; then # Find the most recent ISO in the out directory if [[ ! -d "$outDir" ]]; then echo "Error: Output directory not found: $outDir" echo "Please build an ISO first using: sudo ./build.sh" exit 1 fi # Find the most recent ISO file isoFile=$(find "$outDir" -name "*.iso" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | cut -d' ' -f2-) if [[ -z "$isoFile" ]]; then echo "Error: No ISO file found in $outDir" echo "Please build an ISO first using: sudo ./build.sh" exit 1 fi fi if [[ "$bootInstalled" == true ]]; then echo "Booting installed system from: $diskFile" else echo "Found ISO: $isoFile" echo "Booting Stormux ISO in QEMU with virtual disk attached..." echo "Virtual disk: $diskFile" fi echo echo "Logging to:" echo " QEMU log: $qemuLog" echo " Serial console: $serialLog" echo if [[ "$bootInstalled" == false ]]; then echo "Note: After boot, press Ctrl+Alt+F2 to switch to tty2" echo " where the stormux user will be logged in with Fenrir screen reader." echo " Run 'sudo install-stormux' to install to the virtual disk." echo " After installation, use './qemu-boot.sh -i' to boot the installed system." else echo "Note: Booting from installed system on virtual disk." fi echo " You can monitor the serial console log in real-time with:" echo " tail -f $serialLog" echo # Export DISPLAY for console usage export DISPLAY="${DISPLAY:-:0}" # Build QEMU command based on boot mode # Common options for both modes # shellcheck disable=SC2054 qemuCmd=( qemu-system-x86_64 -enable-kvm -m 2048 -drive file="$diskFile",format=qcow2 -audiodev pa,id=snd0 -device intel-hda -device hda-duplex,audiodev=snd0 -serial file:"$serialLog" -D "$qemuLog" -d guest_errors,cpu_reset -display gtk ) # Add ISO and boot order if booting from ISO if [[ "$bootInstalled" == false ]]; then qemuCmd+=(-cdrom "$isoFile" -boot order=dc) else qemuCmd+=(-boot c) fi # Boot QEMU with audio support and logging # -D: QEMU debug log (shows QEMU errors, device issues) # -d: Debug categories (guest_errors, cpu_reset) # -serial: Capture guest serial console (systemd messages, boot logs) # -audiodev: PulseAudio backend for audio # -device intel-hda: Intel HD Audio controller # -device hda-duplex: HD Audio codec with input/output, connected to audiodev exec "${qemuCmd[@]}"