Split the QEMU configs by host system and architecture

Replace qemu/<guest>-<arch>.ini with qemu/<guest>-<os>-<arch>.ini, where os is
linux or darwin, the name platform.system() reports. The accelerators move out
of the shared <guest>.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 <noreply@anthropic.com>
This commit is contained in:
GuofangandClaude Sonnet 5.5 committed 2026-10-17 15:05:02 +08:00
1 parent c13ebc7d11
commit fd1d9d651d
24 files changed
+234 -96

No files matched your search

+8 -5
View File
@@ -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-<arch>.ini. Later QEMU arguments override them, e.g.
followed by qemu/fedora44-<os>-<arch>.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: