DocFormat,
JsonEncoder,
ManifestFormat,
+ Network,
OutputFormat,
SecureBootSignTool,
ShimBootloader,
cmdline: list[PathString] = ["systemd-nspawn", "--quiet", "--link-journal=no"]
+ if config.runtime_network == Network.user:
+ cmdline += ["--resolv-conf=auto"]
+ elif config.runtime_network == Network.interface:
+ if os.getuid() != 0:
+ die("RuntimeNetwork=interface requires root privileges")
+
+ cmdline += ["--private-network", "--network-veth"]
+ elif config.runtime_network == Network.none:
+ cmdline += ["--private-network"]
+
# If we copied in a .nspawn file, make sure it's actually honoured
if config.nspawn_settings:
cmdline += ["--settings=trusted"]
bios = enum.auto()
+class Network(StrEnum):
+ interface = enum.auto()
+ user = enum.auto()
+ none = enum.auto()
+
+
class Architecture(StrEnum):
alpha = enum.auto()
arc = enum.auto()
runtime_trees: list[ConfigTree]
runtime_size: Optional[int]
runtime_scratch: ConfigFeature
+ runtime_network: Network
ssh_key: Optional[Path]
ssh_certificate: Optional[Path]
parse=config_parse_feature,
help="Mount extra scratch space to /var/tmp",
),
+ ConfigSetting(
+ dest="runtime_network",
+ metavar="NET",
+ section="Host",
+ parse=config_make_enum_parser(Network),
+ help="Set networking backend to use when booting the image",
+ ),
ConfigSetting(
dest="ssh_key",
metavar="PATH",
Runtime Trees: {line_join_list(config.runtime_trees)}
Runtime Size: {format_bytes_or_none(config.runtime_size)}
Runtime Scratch: {config.runtime_scratch}
+ Runtime Network: {config.runtime_network}
SSH Signing Key: {none_to_none(config.ssh_key)}
SSH Certificate: {none_to_none(config.ssh_certificate)}
list[QemuDrive]: config_drive_transformer,
GenericVersion: generic_version_transformer,
Cacheonly: enum_transformer,
+ Network: enum_transformer,
}
def json_transformer(key: str, val: Any) -> Any:
Args,
Config,
ConfigFeature,
+ Network,
OutputFormat,
QemuFirmware,
QemuVsockCID,
*shm,
]
- cmdline += ["-nic", f"user,model={config.architecture.default_qemu_nic_model()}"]
+ if config.runtime_network == Network.user:
+ cmdline += ["-nic", f"user,model={config.architecture.default_qemu_nic_model()}"]
+ elif config.runtime_network == Network.interface:
+ if os.getuid() != 0:
+ die("RuntimeNetwork=interface requires root privileges")
+
+ cmdline += ["-nic", "tap,script=no,model=virtio-net-pci"]
+ elif config.runtime_network == Network.none:
+ cmdline += ["-nic", "none"]
if config.qemu_kvm != ConfigFeature.disabled and have_kvm and config.architecture.is_native():
accel = "kvm"
: Note that using this feature with `mkosi qemu` requires systemd v254
or newer in the guest.
+`RuntimeNetwork=`: `--runtime-network=`
+
+: Takes one of `user`, `interface` or `none`. Specifies the networking
+ to set up when booting the image. `user` sets up usermode networking.
+ `interface` sets up a virtual network connection between the host and
+ the image. This translates to a veth interface for `mkosi shell` and
+ `mkosi boot` and a tap interface for `mkosi qemu` and `mkosi vmspawn`.
+
+: Note that when using `interface`, mkosi does not automatically
+ configure the host interface. It is expected that a recent version of
+ `systemd-networkd` is running on the host which will automatically
+ configure the host interface of the link.
+
`SshKey=`, `--ssh-key=`
: Path to the X509 private key in PEM format to use to connect to a
from mkosi.config import (
Args,
Config,
+ Network,
OutputFormat,
QemuFirmware,
yes_no,
"--secure-boot", yes_no(config.secure_boot),
]
+ if config.runtime_network == Network.user:
+ cmdline += ["--network-user-mode"]
+ elif config.runtime_network == Network.interface:
+ cmdline += ["--network-tap"]
+
if config.qemu_gui:
cmdline += ["--qemu-gui"]
ConfigTree,
DocFormat,
ManifestFormat,
+ Network,
OutputFormat,
QemuDrive,
QemuFirmware,
false
],
"RootShell": "/bin/tcsh",
+ "RuntimeNetwork": "interface",
"RuntimeScratch": "enabled",
"RuntimeSize": 8589934592,
"RuntimeTrees": [
repository_key_check = False,
root_password = ("test1234", False),
root_shell = "/bin/tcsh",
+ runtime_network = Network.interface,
runtime_scratch = ConfigFeature.enabled,
runtime_size = 8589934592,
runtime_trees = [ConfigTree(Path("/foo/bar"), Path("/baz")), ConfigTree(Path("/bar/baz"), Path("/qux"))],