Read port forwards from per-VM forwards.conf files

A QEMU config file section cannot hold more than one hostfwd entry, so
the forwards move out of the ini files into qemu/<vm>/forwards.conf, one
"LABEL HOST_PORT GUEST_PORT" rule per line. The new vmforwards.py parses
them, skips rules whose host port is taken and builds the -netdev
argument, which every launcher now passes instead of relying on a
netdev section in the ini or on -nic.

The ini files move to qemu/<vm>/config.ini and qemu/<vm>/<os>-<arch>.ini.
The *_SSH_PORT / *_RDP_PORT variables and --rdp-port / --ssh-port still
replace the host port of the SSH and RDP rules.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
GuofangandClaude Sonnet 5.5 committed 2026-10-29 14:55:30 +08:00
1 parent 07a2c6db3e
commit 78f6fd424b
29 files changed
+272 -131

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Host ports forwarded to the guest: LABEL HOST_PORT GUEST_PORT
SSH 2223 22
@@ -1,6 +1,6 @@
# QEMU configuration for the Debian 13 virtual machine, shared by all
# architectures. The accelerators, machine type and
# platform-specific devices are in debian13-<os>-<arch>.ini (os is linux or darwin),
# platform-specific devices are in <os>-<arch>.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
@@ -50,10 +50,9 @@
driver = "virtio-blk-pci"
drive = "seed0"
# User-mode networking with guest SSH forwarded to the host.
[netdev "net0"]
type = "user"
hostfwd = "tcp::2222-:22"
# The NIC is attached to the user-mode network "net0", which the launcher
# defines with -netdev from qemu/debian13/forwards.conf because a config file
# section cannot hold more than one hostfwd.
[device "nic0"]
driver = "virtio-net-pci"
@@ -1,4 +1,4 @@
# macOS host, arm64 part of the Debian 13 QEMU configuration; read after debian13.ini.
# macOS host, arm64 part of the Debian 13 QEMU configuration; read after config.ini.
# Accelerators are tried in order: HVF on macOS, else emulation.
[accel]
+2
View File
@@ -0,0 +1,2 @@
# Host ports forwarded to the guest: LABEL HOST_PORT GUEST_PORT
SSH 2222 22
@@ -1,4 +1,4 @@
# Linux host, amd64 part of the Debian 13 QEMU configuration; read after debian13.ini.
# Linux host, amd64 part of the Debian 13 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,4 +1,4 @@
# Linux host, arm64 part of the Debian 13 QEMU configuration; read after debian13.ini.
# Linux host, arm64 part of the Debian 13 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,6 +1,6 @@
# QEMU configuration for the Fedora 44 virtual machine, shared by all
# architectures. The accelerators, machine type and
# platform-specific devices are in fedora44-<os>-<arch>.ini (os is linux or darwin),
# platform-specific devices are in <os>-<arch>.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
@@ -50,10 +50,9 @@
driver = "virtio-blk-pci"
drive = "seed0"
# User-mode networking with guest SSH forwarded to the host.
[netdev "net0"]
type = "user"
hostfwd = "tcp::2224-:22"
# The NIC is attached to the user-mode network "net0", which the launcher
# defines with -netdev from qemu/fedora44/forwards.conf because a config file
# section cannot hold more than one hostfwd.
[device "nic0"]
driver = "virtio-net-pci"
@@ -1,4 +1,4 @@
# macOS host, arm64 part of the Fedora 44 QEMU configuration; read after fedora44.ini.
# macOS host, arm64 part of the Fedora 44 QEMU configuration; read after config.ini.
# Accelerators are tried in order: HVF on macOS, else emulation.
[accel]
+2
View File
@@ -0,0 +1,2 @@
# Host ports forwarded to the guest: LABEL HOST_PORT GUEST_PORT
SSH 2224 22
@@ -1,4 +1,4 @@
# Linux host, amd64 part of the Fedora 44 QEMU configuration; read after fedora44.ini.
# Linux host, amd64 part of the Fedora 44 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,4 +1,4 @@
# Linux host, arm64 part of the Fedora 44 QEMU configuration; read after fedora44.ini.
# Linux host, arm64 part of the Fedora 44 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,6 +1,6 @@
# QEMU configuration for the Ubuntu 26.04 virtual machine, shared by all
# architectures. The accelerators, machine type and
# platform-specific devices are in ubuntu2604-<os>-<arch>.ini (os is linux or darwin),
# platform-specific devices are in <os>-<arch>.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
@@ -50,10 +50,9 @@
driver = "virtio-blk-pci"
drive = "seed0"
# User-mode networking with guest SSH forwarded to the host.
[netdev "net0"]
type = "user"
hostfwd = "tcp::2225-:22"
# The NIC is attached to the user-mode network "net0", which the launcher
# defines with -netdev from qemu/ubuntu2604/forwards.conf because a config file
# section cannot hold more than one hostfwd.
[device "nic0"]
driver = "virtio-net-pci"
@@ -1,4 +1,4 @@
# macOS host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini.
# macOS host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after config.ini.
# Accelerators are tried in order: HVF on macOS, else emulation.
[accel]
+2
View File
@@ -0,0 +1,2 @@
# Host ports forwarded to the guest: LABEL HOST_PORT GUEST_PORT
SSH 2225 22
@@ -1,4 +1,4 @@
# Linux host, amd64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini.
# Linux host, amd64 part of the Ubuntu 26.04 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,4 +1,4 @@
# Linux host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after ubuntu2604.ini.
# Linux host, arm64 part of the Ubuntu 26.04 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,5 +1,5 @@
# QEMU configuration for the Windows 11 virtual machine. The accelerators and machine type
# are in windows11-<os>-<arch>.ini (os is linux or darwin), which QEMU reads after
# are in <os>-<arch>.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
@@ -30,8 +30,8 @@
# System disk image; the device that exposes it (and the NIC, which is
# attached to the user-mode network "net0" that the launcher defines with
# -netdev because a config file section cannot hold more than one hostfwd) is in
# the architecture file.
# -netdev from qemu/windows11/forwards.conf because a config file section cannot hold
# more than one hostfwd) is in the architecture file.
[drive "system_disk"]
if = "none"
format = "qcow2"
@@ -1,4 +1,4 @@
# macOS host, arm64 part of the Windows 11 QEMU configuration; read after windows11.ini.
# macOS host, arm64 part of the Windows 11 QEMU configuration; read after config.ini.
# Accelerators are tried in order: HVF on macOS, else emulation.
[accel]
+5
View File
@@ -0,0 +1,5 @@
# Host ports forwarded to the guest: LABEL HOST_PORT GUEST_PORT
# --rdp-port and --ssh-port (or WIN11_VM_RDP_PORT and WIN11_VM_SSH_PORT)
# replace the host port of the RDP and SSH rules.
RDP 3389 3389
SSH 2222 22
@@ -1,4 +1,4 @@
# Linux host, amd64 part of the Windows 11 QEMU configuration; read after windows11.ini.
# Linux host, amd64 part of the Windows 11 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]
@@ -1,4 +1,4 @@
# Linux host, arm64 part of the Windows 11 QEMU configuration; read after windows11.ini.
# Linux host, arm64 part of the Windows 11 QEMU configuration; read after config.ini.
# Accelerators are tried in order: KVM on Linux, else emulation.
[accel]