From fd1d9d651d8523c4b15d0a1cbd81724d58c70aea Mon Sep 17 00:00:00 2001 From: Guofang Date: Sat, 17 Oct 2026 15:05:02 +0800 Subject: [PATCH] Split the QEMU configs by host system and architecture Replace qemu/-.ini with qemu/--.ini, where os is linux or darwin, the name platform.system() reports. The accelerators move out of the shared .ini into these files (KVM on Linux, HVF on macOS, TCG as the fallback). The launchers pick the file from the host system and architecture, and reject amd64 guests on macOS hosts, so no darwin-amd64 files exist. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 24 ++++++------- qemu/debian13-amd64.ini | 4 --- ...04-arm64.ini => debian13-darwin-arm64.ini} | 9 ++++- qemu/debian13-linux-amd64.ini | 11 ++++++ ...n13-arm64.ini => debian13-linux-arm64.ini} | 9 ++++- qemu/debian13.ini | 15 ++------ qemu/fedora44-amd64.ini | 4 --- ...44-arm64.ini => fedora44-darwin-arm64.ini} | 9 ++++- qemu/fedora44-linux-amd64.ini | 11 ++++++ qemu/fedora44-linux-arm64.ini | 24 +++++++++++++ qemu/fedora44.ini | 15 ++------ qemu/ubuntu2604-amd64.ini | 4 --- qemu/ubuntu2604-darwin-arm64.ini | 24 +++++++++++++ qemu/ubuntu2604-linux-amd64.ini | 11 ++++++ qemu/ubuntu2604-linux-arm64.ini | 24 +++++++++++++ qemu/ubuntu2604.ini | 15 ++------ ...1-arm64.ini => windows11-darwin-arm64.ini} | 9 ++++- ...11-amd64.ini => windows11-linux-amd64.ini} | 9 ++++- qemu/windows11-linux-arm64.ini | 34 +++++++++++++++++++ qemu/windows11.ini | 15 ++------ run-debian13.py | 13 ++++--- run-fedora44.py | 13 ++++--- run-ubuntu2604.py | 13 ++++--- run-windows11.py | 11 +++--- 24 files changed, 234 insertions(+), 96 deletions(-) delete mode 100644 qemu/debian13-amd64.ini rename qemu/{ubuntu2604-arm64.ini => debian13-darwin-arm64.ini} (57%) create mode 100644 qemu/debian13-linux-amd64.ini rename qemu/{debian13-arm64.ini => debian13-linux-arm64.ini} (57%) delete mode 100644 qemu/fedora44-amd64.ini rename qemu/{fedora44-arm64.ini => fedora44-darwin-arm64.ini} (57%) create mode 100644 qemu/fedora44-linux-amd64.ini create mode 100644 qemu/fedora44-linux-arm64.ini delete mode 100644 qemu/ubuntu2604-amd64.ini create mode 100644 qemu/ubuntu2604-darwin-arm64.ini create mode 100644 qemu/ubuntu2604-linux-amd64.ini create mode 100644 qemu/ubuntu2604-linux-arm64.ini rename qemu/{windows11-arm64.ini => windows11-darwin-arm64.ini} (78%) rename qemu/{windows11-amd64.ini => windows11-linux-amd64.ini} (64%) create mode 100644 qemu/windows11-linux-arm64.ini diff --git a/README.md b/README.md index 27c87de..841121c 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,14 @@ original qcow2 image as its backing file. The base image therefore stays unchanged. Run `./run-debian13.py --help` for the supported environment variables. -The Debian VM hardware (accelerator, 8G memory, 8 CPUs, drives, network) is +The Debian VM hardware (8G memory, 8 CPUs, drives, network) is defined in the QEMU config file `qemu/debian13.ini`; the machine type and -architecture-specific devices are in `qemu/debian13-amd64.ini` and -`qemu/debian13-arm64.ini`. Edit these files to change the settings. The +architecture-specific devices are in `qemu/debian13--.ini` +(os `linux` or `darwin`, arch `amd64` or `arm64`), together with the +accelerators. Edit these files to change the settings. The launcher fills in the `${...}` file path placeholders of `qemu/debian13.ini`, writes the result to `.vm/debian13/qemu.ini` and starts QEMU with -`-readconfig` for that file followed by the one for the guest architecture. +`-readconfig` for that file followed by the one for the host system and guest architecture. QEMU arguments given after `--` override the config files, for example `./run-debian13.py -- -m 4G -smp 4`. @@ -122,9 +123,8 @@ GNOME package group through its native package module, then reboots the guest. Keep the VM running until this initial installation and reboot have completed. Like the Debian VM, the Fedora VM hardware (8G memory, 8 CPUs, drives, SSH -port `2224`) is defined in `qemu/fedora44.ini`, with the machine type and -architecture-specific devices in `qemu/fedora44-amd64.ini` and -`qemu/fedora44-arm64.ini`. Other Fedora settings use the `FEDORA_VM_` prefix. +port `2224`) is defined in `qemu/fedora44.ini`, with the accelerators, machine type and +platform-specific devices in `qemu/fedora44--.ini`. Other Fedora settings use the `FEDORA_VM_` prefix. Run `./run-fedora44.py --help` for the complete list of overrides. ## Ubuntu 26.04 @@ -151,8 +151,8 @@ guest. Keep the VM running until this initial installation and reboot have completed. The VM hardware (8G memory, 8 CPUs, drives, SSH port `2225`) is defined in -`qemu/ubuntu2604.ini`, with the machine type and architecture-specific devices -in `qemu/ubuntu2604-amd64.ini` and `qemu/ubuntu2604-arm64.ini`. Other Ubuntu +`qemu/ubuntu2604.ini`, with the accelerators, machine type and platform-specific +devices in `qemu/ubuntu2604--.ini`. Other Ubuntu settings use the `UBUNTU_VM_` prefix. Run `./run-ubuntu2604.py --help` for the complete list of overrides. @@ -175,9 +175,9 @@ passwordless administrator login. The installer includes the VirtIO drivers, SPI and QEMU Guest Agent. Connect with `ssh guofang@localhost -p 2222`. The launcher exposes the vdagent channel for host/guest clipboard integration and the QEMU Guest Agent at `.vm/windows11/qemu-guest-agent.sock`. Change the password after first login. -The Windows VM hardware (accelerator, 8G memory, 8 CPUs, system disk, devices) -is defined in `qemu/windows11.ini`, with the machine type in -`qemu/windows11-amd64.ini`; the launcher renders the former to +The Windows VM hardware (8G memory, 8 CPUs, system disk, devices) +is defined in `qemu/windows11.ini`, with the accelerators and machine type in +`qemu/windows11--.ini`; the launcher renders the former to `.vm/windows11/qemu.ini` and loads both with `-readconfig`. Only the network and the installation media are still set by the launcher. QEMU arguments after `--` override the config files, for example `./run-windows11.py -- -m 4G -smp 4`. diff --git a/qemu/debian13-amd64.ini b/qemu/debian13-amd64.ini deleted file mode 100644 index 17272d3..0000000 --- a/qemu/debian13-amd64.ini +++ /dev/null @@ -1,4 +0,0 @@ -# amd64 part of the Debian 13 QEMU configuration; read after debian13.ini. - -[machine] - type = "q35" diff --git a/qemu/ubuntu2604-arm64.ini b/qemu/debian13-darwin-arm64.ini similarity index 57% rename from qemu/ubuntu2604-arm64.ini rename to qemu/debian13-darwin-arm64.ini index effacd3..6eddee8 100644 --- a/qemu/ubuntu2604-arm64.ini +++ b/qemu/debian13-darwin-arm64.ini @@ -1,4 +1,11 @@ -# arm64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini. +# macOS host, arm64 part of the Debian 13 QEMU configuration; read after debian13.ini. + +# Accelerators are tried in order: HVF on macOS, else emulation. +[accel] + accel = "hvf" + +[accel] + accel = "tcg" [machine] type = "virt" diff --git a/qemu/debian13-linux-amd64.ini b/qemu/debian13-linux-amd64.ini new file mode 100644 index 0000000..b13077b --- /dev/null +++ b/qemu/debian13-linux-amd64.ini @@ -0,0 +1,11 @@ +# Linux host, amd64 part of the Debian 13 QEMU configuration; read after debian13.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "q35" diff --git a/qemu/debian13-arm64.ini b/qemu/debian13-linux-arm64.ini similarity index 57% rename from qemu/debian13-arm64.ini rename to qemu/debian13-linux-arm64.ini index 68865a7..86def34 100644 --- a/qemu/debian13-arm64.ini +++ b/qemu/debian13-linux-arm64.ini @@ -1,4 +1,11 @@ -# arm64 part of the Debian 13 QEMU configuration; read after debian13.ini. +# Linux host, arm64 part of the Debian 13 QEMU configuration; read after debian13.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" [machine] type = "virt" diff --git a/qemu/debian13.ini b/qemu/debian13.ini index bec8b8b..3899ee7 100644 --- a/qemu/debian13.ini +++ b/qemu/debian13.ini @@ -1,6 +1,7 @@ # QEMU configuration for the Debian 13 virtual machine, shared by all -# architectures. The machine type and architecture-specific devices are in -# debian13-.ini, which QEMU reads after this file. +# architectures. The accelerators, machine type and +# platform-specific devices are in debian13--.ini (os is linux or darwin), +# which QEMU reads after this file. # # run-debian13.py fills in the file path placeholders below, writes the result # to /qemu.ini and passes it to QEMU with -readconfig. Options that @@ -10,16 +11,6 @@ [name] guest = "debian13" -# Accelerators are tried in order: KVM on Linux, HVF on macOS, else emulation. -[accel] - accel = "kvm" - -[accel] - accel = "hvf" - -[accel] - accel = "tcg" - [memory] size = "8G" diff --git a/qemu/fedora44-amd64.ini b/qemu/fedora44-amd64.ini deleted file mode 100644 index 82c356b..0000000 --- a/qemu/fedora44-amd64.ini +++ /dev/null @@ -1,4 +0,0 @@ -# amd64 part of the Fedora 44 QEMU configuration; read after fedora44.ini. - -[machine] - type = "q35" diff --git a/qemu/fedora44-arm64.ini b/qemu/fedora44-darwin-arm64.ini similarity index 57% rename from qemu/fedora44-arm64.ini rename to qemu/fedora44-darwin-arm64.ini index d54c4b9..20c8426 100644 --- a/qemu/fedora44-arm64.ini +++ b/qemu/fedora44-darwin-arm64.ini @@ -1,4 +1,11 @@ -# arm64 part of the Fedora 44 QEMU configuration; read after fedora44.ini. +# macOS host, arm64 part of the Fedora 44 QEMU configuration; read after fedora44.ini. + +# Accelerators are tried in order: HVF on macOS, else emulation. +[accel] + accel = "hvf" + +[accel] + accel = "tcg" [machine] type = "virt" diff --git a/qemu/fedora44-linux-amd64.ini b/qemu/fedora44-linux-amd64.ini new file mode 100644 index 0000000..a72a827 --- /dev/null +++ b/qemu/fedora44-linux-amd64.ini @@ -0,0 +1,11 @@ +# Linux host, amd64 part of the Fedora 44 QEMU configuration; read after fedora44.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "q35" diff --git a/qemu/fedora44-linux-arm64.ini b/qemu/fedora44-linux-arm64.ini new file mode 100644 index 0000000..f03985e --- /dev/null +++ b/qemu/fedora44-linux-arm64.ini @@ -0,0 +1,24 @@ +# Linux host, arm64 part of the Fedora 44 QEMU configuration; read after fedora44.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "virt" + +# Unlike q35, the "virt" machine has no default GPU or USB input devices. +[device "gpu0"] + driver = "virtio-gpu-pci" + +[device "usb0"] + driver = "qemu-xhci" + +[device "kbd0"] + driver = "usb-kbd" + +[device "tablet0"] + driver = "usb-tablet" diff --git a/qemu/fedora44.ini b/qemu/fedora44.ini index e2a7b2b..f98037e 100644 --- a/qemu/fedora44.ini +++ b/qemu/fedora44.ini @@ -1,6 +1,7 @@ # QEMU configuration for the Fedora 44 virtual machine, shared by all -# architectures. The machine type and architecture-specific devices are in -# fedora44-.ini, which QEMU reads after this file. +# architectures. The accelerators, machine type and +# platform-specific devices are in fedora44--.ini (os is linux or darwin), +# which QEMU reads after this file. # # run-fedora44.py fills in the file path placeholders below, writes the result # to /qemu.ini and passes it to QEMU with -readconfig. Options that @@ -10,16 +11,6 @@ [name] guest = "fedora44" -# Accelerators are tried in order: KVM on Linux, HVF on macOS, else emulation. -[accel] - accel = "kvm" - -[accel] - accel = "hvf" - -[accel] - accel = "tcg" - [memory] size = "8G" diff --git a/qemu/ubuntu2604-amd64.ini b/qemu/ubuntu2604-amd64.ini deleted file mode 100644 index 837e71a..0000000 --- a/qemu/ubuntu2604-amd64.ini +++ /dev/null @@ -1,4 +0,0 @@ -# amd64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini. - -[machine] - type = "q35" diff --git a/qemu/ubuntu2604-darwin-arm64.ini b/qemu/ubuntu2604-darwin-arm64.ini new file mode 100644 index 0000000..105c1ed --- /dev/null +++ b/qemu/ubuntu2604-darwin-arm64.ini @@ -0,0 +1,24 @@ +# macOS host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini. + +# Accelerators are tried in order: HVF on macOS, else emulation. +[accel] + accel = "hvf" + +[accel] + accel = "tcg" + +[machine] + type = "virt" + +# Unlike q35, the "virt" machine has no default GPU or USB input devices. +[device "gpu0"] + driver = "virtio-gpu-pci" + +[device "usb0"] + driver = "qemu-xhci" + +[device "kbd0"] + driver = "usb-kbd" + +[device "tablet0"] + driver = "usb-tablet" diff --git a/qemu/ubuntu2604-linux-amd64.ini b/qemu/ubuntu2604-linux-amd64.ini new file mode 100644 index 0000000..b7dba90 --- /dev/null +++ b/qemu/ubuntu2604-linux-amd64.ini @@ -0,0 +1,11 @@ +# Linux host, amd64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "q35" diff --git a/qemu/ubuntu2604-linux-arm64.ini b/qemu/ubuntu2604-linux-arm64.ini new file mode 100644 index 0000000..6b4d3c7 --- /dev/null +++ b/qemu/ubuntu2604-linux-arm64.ini @@ -0,0 +1,24 @@ +# Linux host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "virt" + +# Unlike q35, the "virt" machine has no default GPU or USB input devices. +[device "gpu0"] + driver = "virtio-gpu-pci" + +[device "usb0"] + driver = "qemu-xhci" + +[device "kbd0"] + driver = "usb-kbd" + +[device "tablet0"] + driver = "usb-tablet" diff --git a/qemu/ubuntu2604.ini b/qemu/ubuntu2604.ini index 4d641ef..bbaf7e7 100644 --- a/qemu/ubuntu2604.ini +++ b/qemu/ubuntu2604.ini @@ -1,6 +1,7 @@ # QEMU configuration for the Ubuntu 26.04 virtual machine, shared by all -# architectures. The machine type and architecture-specific devices are in -# ubuntu2604-.ini, which QEMU reads after this file. +# architectures. The accelerators, machine type and +# platform-specific devices are in ubuntu2604--.ini (os is linux or darwin), +# which QEMU reads after this file. # # run-ubuntu2604.py fills in the file path placeholders below, writes the result # to /qemu.ini and passes it to QEMU with -readconfig. Options that @@ -10,16 +11,6 @@ [name] guest = "ubuntu2604" -# Accelerators are tried in order: KVM on Linux, HVF on macOS, else emulation. -[accel] - accel = "kvm" - -[accel] - accel = "hvf" - -[accel] - accel = "tcg" - [memory] size = "8G" diff --git a/qemu/windows11-arm64.ini b/qemu/windows11-darwin-arm64.ini similarity index 78% rename from qemu/windows11-arm64.ini rename to qemu/windows11-darwin-arm64.ini index 7f1e35f..d728f71 100644 --- a/qemu/windows11-arm64.ini +++ b/qemu/windows11-darwin-arm64.ini @@ -1,4 +1,11 @@ -# arm64 part of the Windows 11 QEMU configuration; read after windows11.ini. +# macOS host, arm64 part of the Windows 11 QEMU configuration; read after windows11.ini. + +# Accelerators are tried in order: HVF on macOS, else emulation. +[accel] + accel = "hvf" + +[accel] + accel = "tcg" [machine] type = "virt" diff --git a/qemu/windows11-amd64.ini b/qemu/windows11-linux-amd64.ini similarity index 64% rename from qemu/windows11-amd64.ini rename to qemu/windows11-linux-amd64.ini index ce18c9a..3fbf28c 100644 --- a/qemu/windows11-amd64.ini +++ b/qemu/windows11-linux-amd64.ini @@ -1,4 +1,11 @@ -# amd64 part of the Windows 11 QEMU configuration; read after windows11.ini. +# Linux host, amd64 part of the Windows 11 QEMU configuration; read after windows11.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" [machine] type = "q35" diff --git a/qemu/windows11-linux-arm64.ini b/qemu/windows11-linux-arm64.ini new file mode 100644 index 0000000..0001bef --- /dev/null +++ b/qemu/windows11-linux-arm64.ini @@ -0,0 +1,34 @@ +# Linux host, arm64 part of the Windows 11 QEMU configuration; read after windows11.ini. + +# Accelerators are tried in order: KVM on Linux, else emulation. +[accel] + accel = "kvm" + +[accel] + accel = "tcg" + +[machine] + type = "virt" + +# The "virt" machine has no IDE. NVMe and USB mass storage (used by the +# installation media of --install-from-iso) both have inbox Windows drivers. +[device "system_disk-dev"] + driver = "nvme" + drive = "system_disk" + serial = "win11disk" + bootindex = "1" + +# Windows has no inbox driver for virtio-net; the guest tools installed by +# Configure-Windows.ps1 provide it. +[device "nic0"] + driver = "virtio-net-pci" + netdev = "net0" + +# Unlike q35, "virt" has no default GPU or keyboard. ramfb is used rather than +# virtio-gpu because the firmware's virtio-gpu output freezes at the Windows +# boot manager; Windows drives either one through its basic display driver. +[device "gpu0"] + driver = "ramfb" + +[device "kbd0"] + driver = "usb-kbd" diff --git a/qemu/windows11.ini b/qemu/windows11.ini index c11da63..b39b9f5 100644 --- a/qemu/windows11.ini +++ b/qemu/windows11.ini @@ -1,5 +1,6 @@ -# QEMU configuration for the Windows 11 virtual machine. The machine type is in -# windows11-.ini, which QEMU reads after this file. +# QEMU configuration for the Windows 11 virtual machine. The accelerators and machine type +# are in windows11--.ini (os is linux or darwin), which QEMU reads after +# this file. # # run-windows11.py fills in the file path placeholders below, writes the result # to /qemu.ini and passes it to QEMU with -readconfig. Options that @@ -9,16 +10,6 @@ [name] guest = "windows11" -# Accelerators are tried in order: KVM on Linux, HVF on macOS, else emulation. -[accel] - accel = "kvm" - -[accel] - accel = "hvf" - -[accel] - accel = "tcg" - [memory] size = "8G" diff --git a/run-debian13.py b/run-debian13.py index bdaacd0..5fea77e 100755 --- a/run-debian13.py +++ b/run-debian13.py @@ -69,7 +69,10 @@ native_arch = normalize_arch(platform.machine()) host_arch = normalize_arch(env("VM_IMAGE_ARCH") or native_arch) qemu_binary = "qemu-system-aarch64" if host_arch == "arm64" else "qemu-system-x86_64" qemu_config_template = Path(env("VM_QEMU_CONFIG") or script_dir / "qemu" / "debian13.ini") -qemu_arch_config = script_dir / "qemu" / f"debian13-{host_arch}.ini" +host_os = platform.system().lower() +if host_os == "darwin" and host_arch == "amd64": + die("amd64 guests are not supported on macOS hosts; use an arm64 image") +qemu_platform_config = script_dir / "qemu" / f"debian13-{host_os}-{host_arch}.ini" def pick_firmware(override, *candidates): @@ -124,7 +127,7 @@ Start the Debian 13 virtual machine. A writable overlay is created in the state directory (default: .vm/debian13/), so the downloaded base image is never modified. The VM hardware (memory, CPUs, SSH port forward, ...) is defined in qemu/debian13.ini, which is rendered to qemu.ini in the state directory and -loaded with QEMU's -readconfig, followed by qemu/debian13-.ini. Later +loaded with QEMU's -readconfig, followed by qemu/debian13--.ini (os is linux or darwin, arch is amd64 or arm64). Later QEMU arguments override them, e.g. `-- -m 4G -smp 4`. Options: @@ -251,7 +254,7 @@ for key, value in config_values.items(): # QEMU's config file parser has no escape syntax for quoted values. if any(char in str(value) for char in '"\n'): die(f"{key} must not contain double quotes or newlines: {value}") -for config_file in (qemu_config_template, qemu_arch_config): +for config_file in (qemu_config_template, qemu_platform_config): if not config_file.is_file(): die(f"QEMU config file was not found: {config_file}") try: @@ -263,7 +266,7 @@ qemu_config.write_text(qemu_config_text) qemu_args = [ "-readconfig", str(qemu_config), - "-readconfig", str(qemu_arch_config), + "-readconfig", str(qemu_platform_config), # "max" is the host CPU under KVM/HVF and the fullest model under TCG. "-cpu", "max", # The config file's [netdev] does not stop QEMU from adding its default @@ -273,7 +276,7 @@ qemu_args = [ ] print(f"Starting {host_arch} VM from {qemu_config_template} " - f"and {qemu_arch_config}.", flush=True) + f"and {qemu_platform_config}.", flush=True) # The SSH port forward lives in the config file, e.g. hostfwd = "tcp::2222-:22". ssh_forward = re.search(r'hostfwd\s*=\s*"tcp:[^:"]*:(\d+)-[^:"]*:22"', qemu_config_text) if ssh_forward: diff --git a/run-fedora44.py b/run-fedora44.py index 6d9bf29..ec2a52c 100755 --- a/run-fedora44.py +++ b/run-fedora44.py @@ -70,7 +70,10 @@ host_arch = normalize_arch(env("VM_IMAGE_ARCH") or native_arch) qemu_binary = "qemu-system-aarch64" if host_arch == "arm64" else "qemu-system-x86_64" qemu_config_template = Path( env("FEDORA_VM_QEMU_CONFIG") or script_dir / "qemu" / "fedora44.ini") -qemu_arch_config = script_dir / "qemu" / f"fedora44-{host_arch}.ini" +host_os = platform.system().lower() +if host_os == "darwin" and host_arch == "amd64": + die("amd64 guests are not supported on macOS hosts; use an arm64 image") +qemu_platform_config = script_dir / "qemu" / f"fedora44-{host_os}-{host_arch}.ini" def pick_firmware(override, *candidates): @@ -126,7 +129,7 @@ base image through the shared image helper and creates a writable overlay in the state directory, leaving the base image unchanged. The VM hardware (memory, CPUs, SSH port forward, ...) is defined in qemu/fedora44.ini, which is rendered to qemu.ini in the state directory and loaded with QEMU's -readconfig, -followed by qemu/fedora44-.ini. Later QEMU arguments override them, e.g. +followed by qemu/fedora44--.ini (os is linux or darwin, arch is amd64 or arm64). Later QEMU arguments override them, e.g. `-- -m 4G -smp 4`. Options: @@ -253,7 +256,7 @@ for key, value in config_values.items(): # QEMU's config file parser has no escape syntax for quoted values. if any(char in str(value) for char in '"\n'): die(f"{key} must not contain double quotes or newlines: {value}") -for config_file in (qemu_config_template, qemu_arch_config): +for config_file in (qemu_config_template, qemu_platform_config): if not config_file.is_file(): die(f"QEMU config file was not found: {config_file}") try: @@ -265,7 +268,7 @@ qemu_config.write_text(qemu_config_text) qemu_args = [ "-readconfig", str(qemu_config), - "-readconfig", str(qemu_arch_config), + "-readconfig", str(qemu_platform_config), # "max" is the host CPU under KVM/HVF and the fullest model under TCG. "-cpu", "max", # The config file's [netdev] does not stop QEMU from adding its default @@ -275,7 +278,7 @@ qemu_args = [ ] print(f"Starting Fedora 44 ({host_arch}) from {qemu_config_template} " - f"and {qemu_arch_config}.", flush=True) + f"and {qemu_platform_config}.", flush=True) # The SSH port forward lives in the config file, e.g. hostfwd = "tcp::2224-:22". ssh_forward = re.search(r'hostfwd\s*=\s*"tcp:[^:"]*:(\d+)-[^:"]*:22"', qemu_config_text) if ssh_forward: diff --git a/run-ubuntu2604.py b/run-ubuntu2604.py index 67f5f93..db81a73 100755 --- a/run-ubuntu2604.py +++ b/run-ubuntu2604.py @@ -70,7 +70,10 @@ host_arch = normalize_arch(env("VM_IMAGE_ARCH") or native_arch) qemu_binary = "qemu-system-aarch64" if host_arch == "arm64" else "qemu-system-x86_64" qemu_config_template = Path( env("UBUNTU_VM_QEMU_CONFIG") or script_dir / "qemu" / "ubuntu2604.ini") -qemu_arch_config = script_dir / "qemu" / f"ubuntu2604-{host_arch}.ini" +host_os = platform.system().lower() +if host_os == "darwin" and host_arch == "amd64": + die("amd64 guests are not supported on macOS hosts; use an arm64 image") +qemu_platform_config = script_dir / "qemu" / f"ubuntu2604-{host_os}-{host_arch}.ini" def pick_firmware(override, *candidates): @@ -126,7 +129,7 @@ created in the state directory (default: .vm/ubuntu2604/), so the downloaded base image is never modified. The VM hardware (memory, CPUs, SSH port forward, ...) is defined in qemu/ubuntu2604.ini, which is rendered to qemu.ini in the state directory and loaded with QEMU's -readconfig, followed by -qemu/ubuntu2604-.ini. Later QEMU arguments override them, e.g. +qemu/ubuntu2604--.ini (os is linux or darwin, arch is amd64 or arm64). Later QEMU arguments override them, e.g. `-- -m 4G -smp 4`. Options: @@ -253,7 +256,7 @@ for key, value in config_values.items(): # QEMU's config file parser has no escape syntax for quoted values. if any(char in str(value) for char in '"\n'): die(f"{key} must not contain double quotes or newlines: {value}") -for config_file in (qemu_config_template, qemu_arch_config): +for config_file in (qemu_config_template, qemu_platform_config): if not config_file.is_file(): die(f"QEMU config file was not found: {config_file}") try: @@ -265,7 +268,7 @@ qemu_config.write_text(qemu_config_text) qemu_args = [ "-readconfig", str(qemu_config), - "-readconfig", str(qemu_arch_config), + "-readconfig", str(qemu_platform_config), # "max" is the host CPU under KVM/HVF and the fullest model under TCG. "-cpu", "max", # The config file's [netdev] does not stop QEMU from adding its default @@ -275,7 +278,7 @@ qemu_args = [ ] print(f"Starting Ubuntu 26.04 ({host_arch}) from {qemu_config_template} " - f"and {qemu_arch_config}.", flush=True) + f"and {qemu_platform_config}.", flush=True) # The SSH port forward lives in the config file, e.g. hostfwd = "tcp::2225-:22". ssh_forward = re.search(r'hostfwd\s*=\s*"tcp:[^:"]*:(\d+)-[^:"]*:22"', qemu_config_text) if ssh_forward: diff --git a/run-windows11.py b/run-windows11.py index 0d6d7a3..7bc82ae 100755 --- a/run-windows11.py +++ b/run-windows11.py @@ -79,7 +79,10 @@ def normalize_arch(arch): host_arch = normalize_arch(env("VM_IMAGE_ARCH") or platform.machine()) qemu_binary = "qemu-system-aarch64" if host_arch == "arm64" else "qemu-system-x86_64" -qemu_arch_config = script_dir / "qemu" / f"windows11-{host_arch}.ini" +host_os = platform.system().lower() +if host_os == "darwin" and host_arch == "amd64": + die("amd64 guests are not supported on macOS hosts; use an arm64 image") +qemu_platform_config = script_dir / "qemu" / f"windows11-{host_os}-{host_arch}.ini" def pick_firmware(override, *candidates): @@ -136,7 +139,7 @@ If the system disk (DIR/disk.qcow2, see --state-dir) is missing, create it from the Windows 11 QCOW2 base image. The VM hardware (accelerator, memory, CPUs, drives, devices) is defined in qemu/windows11.ini, which is rendered to qemu.ini in the state directory and -loaded with QEMU's -readconfig, followed by qemu/windows11-.ini (amd64 or arm64, chosen from the host +loaded with QEMU's -readconfig, followed by qemu/windows11--.ini (os is linux or darwin, arch is amd64 or arm64, chosen from the host system and architecture or VM_IMAGE_ARCH). Later QEMU arguments override them, e.g. -- -m 4G -smp 4. Use --install-from-iso to perform an automatic ISO installation instead. If it exists, start Windows normally without attaching installation media. @@ -327,7 +330,7 @@ for key, value in config_values.items(): # QEMU's config file parser has no escape syntax for quoted values. if any(char in str(value) for char in '"\n'): die(f"{key} must not contain double quotes or newlines: {value}") -for config_file in (qemu_config_template, qemu_arch_config): +for config_file in (qemu_config_template, qemu_platform_config): if not config_file.is_file(): die(f"QEMU config file was not found: {config_file}") try: @@ -352,7 +355,7 @@ for label, host_port, guest_port in (("RDP", rdp_port, 3389), ("SSH", ssh_port, qemu_args = [ "-readconfig", str(qemu_config), - "-readconfig", str(qemu_arch_config), + "-readconfig", str(qemu_platform_config), # "max" is the host CPU under KVM/HVF and the fullest model under TCG. "-cpu", "max", # A config file section cannot hold two hostfwd entries, so the network