Environment=SYSTEMD_REPART_MKFS_OPTIONS_EROFS="--quiet"
[Runtime]
- QemuKvm=yes
+ KVM=yes
EOF
# TODO: Remove once all distros have recent enough systemd that knows systemd.default_device_timeout_sec.
another existing distribution, update the `[Match]` blocks for the
existing distribution to also match against the new distribution. To
test whether all necessary changes were made, you can run
- `mkosi -d <distribution> --tools-tree -t disk -f qemu`.
+ `mkosi -d <distribution> --tools-tree -t disk -f vm`.
KernelModulesInitrdInclude=default
[Runtime]
-QemuMem=4G
+RAM=4G
Format=|cpio
[Runtime]
-QemuMem=8G
+RAM=8G
if verb == Verb.boot:
check_systemd_tool(config, "systemd-nspawn", version="254", reason="boot images")
- if verb == Verb.qemu and config.vmm == Vmm.vmspawn:
+ if verb in (Verb.vm, Verb.qemu) and config.vmm == Vmm.vmspawn:
check_systemd_tool(config, "systemd-vmspawn", version="256", reason="boot images with vmspawn")
if verb == Verb.sysupdate:
{
Verb.shell: run_shell,
Verb.boot: run_shell,
+ Verb.vm: run_vm,
Verb.qemu: run_vm,
Verb.serve: run_serve,
Verb.burn: run_burn,
cat_config = enum.auto()
shell = enum.auto()
boot = enum.auto()
+ vm = enum.auto()
qemu = enum.auto()
ssh = enum.auto()
serve = enum.auto()
Verb.build,
Verb.shell,
Verb.boot,
+ Verb.vm,
Verb.qemu,
Verb.ssh,
Verb.journalctl,
Verb.build,
Verb.shell,
Verb.boot,
+ Verb.vm,
Verb.qemu,
Verb.serve,
Verb.burn,
@dataclasses.dataclass(frozen=True)
-class QemuDrive:
+class Drive:
id: str
size: int
directory: Optional[Path]
# We use negative numbers for specifying special constants
# for VSock CIDs since they're not valid CIDs anyway.
-class QemuVsockCID(enum.IntEnum):
+class VsockCID(enum.IntEnum):
auto = -1
hash = -2
@classmethod
def format(cls, cid: int) -> str:
- if cid == QemuVsockCID.auto:
+ if cid == VsockCID.auto:
return "auto"
- if cid == QemuVsockCID.hash:
+ if cid == VsockCID.hash:
return "hash"
return str(cid)
never = enum.auto()
-class QemuFirmware(StrEnum):
+class Firmware(StrEnum):
auto = enum.auto()
linux = enum.auto()
uefi = enum.auto()
bios = enum.auto()
def is_uefi(self) -> bool:
- return self in (QemuFirmware.uefi, QemuFirmware.uefi_secure_boot)
+ return self in (Firmware.uefi, Firmware.uefi_secure_boot)
+
+
+class ConsoleMode(StrEnum):
+ interactive = enum.auto()
+ read_only = enum.auto()
+ native = enum.auto()
+ gui = enum.auto()
class Network(StrEnum):
return a
- def supports_smbios(self, firmware: QemuFirmware) -> bool:
+ def supports_smbios(self, firmware: Firmware) -> bool:
if self.is_x86_variant():
return True
return value
-def parse_drive(value: str) -> QemuDrive:
+def parse_drive(value: str) -> Drive:
parts = value.split(":", maxsplit=3)
if not parts or not parts[0]:
die(f"No ID specified for drive '{value}'")
options = parts[3] if len(parts) > 3 and parts[3] else None
file_id = parts[4] if len(parts) > 4 and parts[4] else id
- return QemuDrive(id=id, size=size, directory=directory, options=options, file_id=file_id)
+ return Drive(id=id, size=size, directory=directory, options=options, file_id=file_id)
def config_parse_sector_size(value: Optional[str], old: Optional[int]) -> Optional[int]:
return None
if value == "auto":
- return QemuVsockCID.auto
+ return VsockCID.auto
if value == "hash":
- return QemuVsockCID.hash
+ return VsockCID.hash
try:
cid = int(value)
ssh_certificate: Optional[Path]
machine: Optional[str]
forward_journal: Optional[Path]
- vmm: Vmm
- # QEMU-specific options
- qemu_gui: bool
- qemu_smp: int
- qemu_mem: int
- qemu_kvm: ConfigFeature
- qemu_vsock: ConfigFeature
- qemu_vsock_cid: int
- qemu_swtpm: ConfigFeature
- qemu_cdrom: bool
- qemu_removable: bool
- qemu_firmware: QemuFirmware
- qemu_firmware_variables: Optional[Path]
- qemu_kernel: Optional[Path]
- qemu_drives: list[QemuDrive]
+ vmm: Vmm
+ console: ConsoleMode
+ cpus: int
+ ram: int
+ kvm: ConfigFeature
+ vsock: ConfigFeature
+ vsock_cid: int
+ tpm: ConfigFeature
+ cdrom: bool
+ removable: bool
+ firmware: Firmware
+ firmware_variables: Optional[Path]
+ linux: Optional[Path]
+ drives: list[Drive]
qemu_args: list[str]
image: Optional[str]
metavar="NAME=VALUE",
section="Runtime",
parse=config_make_dict_parser(delimiter=" ", parse=parse_key_value, allow_paths=True, unescape=True),
- help="Pass a systemd credential to systemd-nspawn or qemu",
+ help="Pass a systemd credential to a systemd-nspawn container or a virtual machine",
paths=("mkosi.credentials",),
),
ConfigSetting(
choices=Vmm.choices(),
parse=config_make_enum_parser(Vmm),
default=Vmm.qemu,
- help="Set the virtual machine monitor to use for mkosi qemu",
+ help="Set the virtual machine monitor to use for mkosi vm",
),
ConfigSetting(
dest="machine",
help="Directory containing systemd-sysupdate transfer definitions",
),
ConfigSetting(
- dest="qemu_gui",
- metavar="BOOL",
+ dest="console",
+ metavar="MODE",
nargs="?",
section="Runtime",
- parse=config_parse_boolean,
- help="Start QEMU in graphical mode",
+ parse=config_make_enum_parser(ConsoleMode),
+ help="Configure the virtual machine console mode to use",
+ default=ConsoleMode.native,
),
ConfigSetting(
- dest="qemu_smp",
- metavar="SMP",
+ dest="cpus",
+ name="CPUs",
+ metavar="CPUS",
section="Runtime",
parse=config_parse_number,
default=1,
- help="Configure guest's SMP settings",
+ help="Configure number of CPUs in virtual machine",
+ compat_longs=("--qemu-smp",),
+ compat_names=("QemuSmp",),
),
ConfigSetting(
- dest="qemu_mem",
- metavar="MEM",
+ dest="ram",
+ name="RAM",
+ metavar="BYTES",
section="Runtime",
parse=config_parse_bytes,
default=parse_bytes("2G"),
help="Configure guest's RAM size",
+ compat_longs=("--qemu-mem",),
+ compat_names=("QemuMem",),
),
ConfigSetting(
- dest="qemu_kvm",
+ dest="kvm",
+ name="KVM",
metavar="FEATURE",
nargs="?",
section="Runtime",
parse=config_parse_feature,
help="Configure whether to use KVM or not",
+ compat_longs=("--qemu-kvm",),
+ compat_names=("QemuKvm",),
),
ConfigSetting(
- dest="qemu_vsock",
+ dest="vsock",
metavar="FEATURE",
nargs="?",
section="Runtime",
parse=config_parse_feature,
- help="Configure whether to use qemu with a vsock or not",
+ help="Configure whether to use vsock or not",
+ compat_longs=("--qemu-vsock",),
+ compat_names=("QemuVsock",),
),
ConfigSetting(
- dest="qemu_vsock_cid",
- name="QemuVsockConnectionId",
- long="--qemu-vsock-cid",
+ dest="vsock_cid",
+ name="VsockConnectionId",
+ long="--vsock-cid",
metavar="NUMBER|auto|hash",
section="Runtime",
parse=config_parse_vsock_cid,
- default=QemuVsockCID.auto,
- help="Specify the VSock connection ID to use",
+ default=VsockCID.auto,
+ help="Specify the vsock connection ID to use",
+ compat_longs=("--qemu-vsock-cid",),
+ compat_names=("QemuVsockConnectionId",),
),
ConfigSetting(
- dest="qemu_swtpm",
+ dest="tpm",
+ name="TPM",
metavar="FEATURE",
nargs="?",
section="Runtime",
parse=config_parse_feature,
- help="Configure whether to use qemu with swtpm or not",
+ help="Configure whether to use a virtual tpm or not",
+ compat_longs=("--qemu-swtpm",),
+ compat_names=("QemuSwtpm",),
),
ConfigSetting(
- dest="qemu_cdrom",
+ dest="cdrom",
metavar="BOOLEAN",
nargs="?",
section="Runtime",
parse=config_parse_boolean,
help="Attach the image as a CD-ROM to the virtual machine",
+ compat_longs=("--qemu-cdrom",),
+ compat_names=("QemuCdrom",),
),
ConfigSetting(
- dest="qemu_removable",
+ dest="removable",
metavar="BOOLEAN",
nargs="?",
section="Runtime",
parse=config_parse_boolean,
help="Attach the image as a removable drive to the virtual machine",
+ compat_longs=("--qemu-removable",),
+ compat_names=("QemuRemovable",),
),
ConfigSetting(
- dest="qemu_firmware",
+ dest="firmware",
section="Runtime",
- parse=config_make_enum_parser(QemuFirmware),
- default=QemuFirmware.auto,
- help="Set qemu firmware to use",
- choices=QemuFirmware.choices(),
+ parse=config_make_enum_parser(Firmware),
+ default=Firmware.auto,
+ help="Select the virtual machine firmware to use",
+ choices=Firmware.choices(),
+ compat_longs=("--qemu-firmware",),
+ compat_names=("QemuFirmware",),
),
ConfigSetting(
- dest="qemu_firmware_variables",
+ dest="firmware_variables",
metavar="PATH",
section="Runtime",
parse=config_make_path_parser(constants=("custom", "microsoft")),
- help="Set the path to the qemu firmware variables file to use",
+ help="Set the path to the firmware variables file to use",
+ compat_longs=("--qemu-firmware-variables",),
+ compat_names=("QemuFirmwareVariables",),
),
ConfigSetting(
- dest="qemu_kernel",
+ dest="linux",
metavar="PATH",
section="Runtime",
parse=config_make_path_parser(),
- help="Specify the kernel to use for qemu direct kernel boot",
+ help="Specify the kernel to use for direct kernel boot",
+ compat_longs=("--qemu-kernel",),
+ compat_names=("QemuKernel",),
),
ConfigSetting(
- dest="qemu_drives",
- long="--qemu-drive",
+ dest="drives",
+ long="--drive",
metavar="DRIVE",
section="Runtime",
parse=config_make_list_parser(delimiter=" ", parse=parse_drive),
- help="Specify a qemu drive that mkosi should create and pass to qemu",
+ help="Specify drive that mkosi should create and pass to the virtual machine",
+ compat_longs=("--qemu-drive",),
+ compat_names=("QemuDrives",),
),
ConfigSetting(
dest="qemu_args",
mkosi [options…] {b}build{e} [command line…]
mkosi [options…] {b}shell{e} [command line…]
mkosi [options…] {b}boot{e} [nspawn settings…]
- mkosi [options…] {b}qemu{e} [qemu parameters…]
+ mkosi [options…] {b}vm{e} [vmm parameters…]
mkosi [options…] {b}ssh{e} [command line…]
mkosi [options…] {b}journalctl{e} [command line…]
mkosi [options…] {b}coredumpctl{e} [command line…]
hint="Build with -f to generate a new history file from scratch",
)
- # If we're operating on a previously built image (qemu, boot, shell, ...), we're not rebuilding the
+ # If we're operating on a previously built image (vm, boot, shell, ...), we're not rebuilding the
# image and the configuration of the latest build is available, we load the config that was used to
# build the previous image from there instead of parsing configuration files, except for the Host
# section settings which we allow changing without requiring a rebuild of the image.
Register guest with machined: {yes_no(config.register)}
Virtual Machine Monitor: {config.vmm}
- QEMU GUI: {yes_no(config.qemu_gui)}
- QEMU CPU Cores: {config.qemu_smp}
- QEMU Memory: {config.qemu_mem}
- QEMU Use KVM: {config.qemu_kvm}
- QEMU Use VSock: {config.qemu_vsock}
- QEMU VSock Connection ID: {QemuVsockCID.format(config.qemu_vsock_cid)}
- QEMU Use Swtpm: {config.qemu_swtpm}
- QEMU Use CD-ROM: {yes_no(config.qemu_cdrom)}
- QEMU Firmware: {config.qemu_firmware}
- QEMU Firmware Variables: {none_to_none(config.qemu_firmware_variables)}
- QEMU Kernel: {none_to_none(config.qemu_kernel)}
+ Console: {config.console}
+ CPU Cores: {config.cpus}
+ RAM: {format_bytes(config.ram)}
+ KVM: {config.kvm}
+ VSock: {config.vsock}
+ VSock Connection ID: {VsockCID.format(config.vsock_cid)}
+ TPM: {config.tpm}
+ CD-ROM: {yes_no(config.cdrom)}
+ Firmware: {config.firmware}
+ Firmware Variables: {none_to_none(config.firmware_variables)}
+ Linux: {none_to_none(config.linux)}
QEMU Extra Arguments: {line_join_list(config.qemu_args)}
"""
enumtype = fieldtype.__args__[0] # type: ignore
return [enumtype[e] for e in enumlist]
- def config_drive_transformer(
- drives: list[dict[str, Any]], fieldtype: type[QemuDrive]
- ) -> list[QemuDrive]:
+ def config_drive_transformer(drives: list[dict[str, Any]], fieldtype: type[Drive]) -> list[Drive]:
# TODO: exchange for TypeGuard and list comprehension once on 3.10
ret = []
assert "Id" in d
assert "Size" in d
ret.append(
- QemuDrive(
+ Drive(
id=d["Id"],
size=d["Size"] if isinstance(d["Size"], int) else parse_bytes(d["Size"]),
directory=Path(d["Directory"]) if d.get("Directory") else None,
ConfigFeature: enum_transformer,
Distribution: enum_transformer,
OutputFormat: enum_transformer,
- QemuFirmware: enum_transformer,
+ Firmware: enum_transformer,
SecureBootSignTool: enum_transformer,
Incremental: enum_transformer,
Optional[Distribution]: optional_enum_transformer,
list[ManifestFormat]: enum_list_transformer,
Verb: enum_transformer,
DocFormat: enum_transformer,
- list[QemuDrive]: config_drive_transformer,
+ list[Drive]: config_drive_transformer,
GenericVersion: generic_version_transformer,
Cacheonly: enum_transformer,
Network: enum_transformer,
list[UKIProfile]: uki_profile_transformer,
list[ArtifactOutput]: enum_list_transformer,
CertificateSource: certificate_source_transformer,
+ ConsoleMode: enum_transformer,
}
def json_transformer(key: str, val: Any) -> Any:
Args,
Config,
ConfigFeature,
+ ConsoleMode,
+ Drive,
+ Firmware,
Network,
OutputFormat,
- QemuDrive,
- QemuFirmware,
- QemuVsockCID,
+ VsockCID,
finalize_term,
format_bytes,
systemd_tool_version,
def feature(self, config: Config) -> ConfigFeature:
return {
- QemuDeviceNode.kvm: config.qemu_kvm,
- QemuDeviceNode.vhost_vsock: config.qemu_vsock,
+ QemuDeviceNode.kvm: config.kvm,
+ QemuDeviceNode.vhost_vsock: config.vsock,
}[self]
def open(self) -> int:
vars_format: str
-def find_ovmf_firmware(config: Config, firmware: QemuFirmware) -> Optional[OvmfConfig]:
+def find_ovmf_firmware(config: Config, firmware: Firmware) -> Optional[OvmfConfig]:
if not firmware.is_uefi():
return None
)
continue
- if firmware == QemuFirmware.uefi_secure_boot and "secure-boot" not in j["features"]:
+ if firmware == Firmware.uefi_secure_boot and "secure-boot" not in j["features"]:
logging.debug(f"{p.name} firmware description does not include secure boot, skipping")
continue
- if firmware != QemuFirmware.uefi_secure_boot and "secure-boot" in j["features"]:
+ if firmware != Firmware.uefi_secure_boot and "secure-boot" in j["features"]:
logging.debug(f"{p.name} firmware description includes secure boot, skipping")
continue
- if config.qemu_firmware_variables == Path("microsoft") and "enrolled-keys" not in j["features"]:
+ if config.firmware_variables == Path("microsoft") and "enrolled-keys" not in j["features"]:
logging.debug(f"{p.name} firmware description does not have enrolled Microsoft keys, skipping")
continue
- if config.qemu_firmware_variables != Path("microsoft") and "enrolled-keys" in j["features"]:
+ if config.firmware_variables != Path("microsoft") and "enrolled-keys" in j["features"]:
logging.debug(f"{p.name} firmware description has enrolled Microsoft keys, skipping")
continue
) -> Iterator[Path]:
virtiofsd = find_virtiofsd(root=config.tools(), extra=config.extra_search_paths)
if virtiofsd is None:
- die("virtiofsd must be installed to boot directory images or use RuntimeTrees= with mkosi qemu")
+ die("virtiofsd must be installed to boot directory images or use RuntimeTrees= with mkosi vm")
cmdline: list[PathString] = [
virtiofsd,
cmdline += ["--fd", str(SD_LISTEN_FDS_START)]
- # We want RuntimeBuildSources= and RuntimeTrees= to do the right thing even when running mkosi qemu
+ # We want RuntimeBuildSources= and RuntimeTrees= to do the right thing even when running mkosi vm
# as root without the source directories necessarily being owned by root. We achieve this by running
# virtiofsd as the owner of the source directory and then mapping that uid to root.
if not name:
yield Path(scratch.name)
-def finalize_qemu_firmware(config: Config, kernel: Optional[Path]) -> QemuFirmware:
- if config.qemu_firmware != QemuFirmware.auto:
- return config.qemu_firmware
+def finalize_firmware(config: Config, kernel: Optional[Path]) -> Firmware:
+ if config.firmware != Firmware.auto:
+ return config.firmware
if kernel:
if KernelType.identify(config, kernel) != KernelType.unknown:
- return QemuFirmware.uefi_secure_boot
+ return Firmware.uefi_secure_boot
- return QemuFirmware.linux
+ return Firmware.linux
if (
config.output_format in (OutputFormat.cpio, OutputFormat.directory)
or config.architecture.to_efi() is None
):
- return QemuFirmware.linux
+ return Firmware.linux
# At the moment there are no qemu firmware descriptions for non-x86 architectures that advertise
# secure-boot support so let's default to no secure boot for non-x86 architectures.
if config.architecture.is_x86_variant():
- return QemuFirmware.uefi_secure_boot
+ return Firmware.uefi_secure_boot
- return QemuFirmware.uefi
+ return Firmware.uefi
def finalize_firmware_variables(
stack: contextlib.ExitStack,
) -> tuple[Path, str]:
ovmf_vars = stack.enter_context(tempfile.NamedTemporaryFile(prefix="mkosi-ovmf-vars-"))
- if config.qemu_firmware_variables in (None, Path("custom"), Path("microsoft")):
+ if config.firmware_variables in (None, Path("custom"), Path("microsoft")):
ovmf_vars_format = ovmf.vars_format
else:
ovmf_vars_format = "raw"
- if config.qemu_firmware_variables == Path("custom"):
+ if config.firmware_variables == Path("custom"):
assert config.secure_boot_certificate
run(
[
else:
vars = (
config.tools() / ovmf.vars.relative_to("/")
- if config.qemu_firmware_variables == Path("microsoft") or not config.qemu_firmware_variables
- else config.qemu_firmware_variables
+ if config.firmware_variables == Path("microsoft") or not config.firmware_variables
+ else config.firmware_variables
)
shutil.copy2(vars, Path(ovmf_vars.name))
@contextlib.contextmanager
-def finalize_drive(config: Config, drive: QemuDrive) -> Iterator[Path]:
+def finalize_drive(config: Config, drive: Drive) -> Iterator[Path]:
with tempfile.NamedTemporaryFile(
dir=drive.directory or "/var/tmp",
prefix=f"mkosi-drive-{drive.id}",
):
cmdline += [f"systemd.hostname={config.machine}"]
- if config.qemu_cdrom:
+ if config.cdrom:
# CD-ROMs are read-only so tell systemd to boot in volatile mode.
cmdline += ["systemd.volatile=yes"]
- if not config.qemu_gui:
+ if config.console != ConsoleMode.gui:
cmdline += [
f"systemd.tty.term.console={term}",
f"systemd.tty.columns.console={columns}",
if (
config.output_format in (OutputFormat.cpio, OutputFormat.uki, OutputFormat.esp)
- and config.qemu_firmware not in (QemuFirmware.auto, QemuFirmware.linux)
- and not config.qemu_firmware.is_uefi()
+ and config.firmware not in (Firmware.auto, Firmware.linux)
+ and not config.firmware.is_uefi()
):
- die(f"{config.output_format} images cannot be booted with the '{config.qemu_firmware}' firmware")
+ die(f"{config.output_format} images cannot be booted with the '{config.firmware}' firmware")
- if config.runtime_trees and config.qemu_firmware == QemuFirmware.bios:
+ if config.runtime_trees and config.firmware == Firmware.bios:
die("RuntimeTrees= cannot be used when booting in BIOS firmware")
- if config.qemu_kvm == ConfigFeature.enabled and not config.architecture.is_native():
+ if config.kvm == ConfigFeature.enabled and not config.architecture.is_native():
die(
f"KVM acceleration requested but {config.architecture} does not match "
"the native host architecture"
)
- if config.qemu_firmware_variables == Path("custom") and not config.secure_boot_certificate:
- die("SecureBootCertificate= must be configured to use QemuFirmwareVariables=custom")
+ if config.firmware_variables == Path("custom") and not config.secure_boot_certificate:
+ die("SecureBootCertificate= must be configured to use FirmwareVariables=custom")
# After we unshare the user namespace to sandbox qemu, we might not have access to /dev/kvm or related
# device nodes anymore as access to these might be gated behind the kvm group and we won't be part of the
have_kvm = (qemu_version(config, qemu) < QEMU_KVM_DEVICE_VERSION and QemuDeviceNode.kvm.available()) or (
qemu_version(config, qemu) >= QEMU_KVM_DEVICE_VERSION and QemuDeviceNode.kvm in qemu_device_fds
)
- if config.qemu_kvm == ConfigFeature.enabled and not have_kvm:
+ if config.kvm == ConfigFeature.enabled and not have_kvm:
die("KVM acceleration requested but cannot access /dev/kvm")
- if config.qemu_vsock == ConfigFeature.enabled and QemuDeviceNode.vhost_vsock not in qemu_device_fds:
+ if config.vsock == ConfigFeature.enabled and QemuDeviceNode.vhost_vsock not in qemu_device_fds:
die("VSock requested but cannot access /dev/vhost-vsock")
- if config.qemu_kernel:
- kernel = config.qemu_kernel
+ if config.console not in (ConsoleMode.native, ConsoleMode.gui):
+ die(
+ f"Console mode {config.console} is not supported by the qemu vmm",
+ hint="Try the vmspawn vmm instead",
+ )
+
+ if config.linux:
+ kernel = config.linux
elif "-kernel" in args.cmdline:
kernel = Path(args.cmdline[args.cmdline.index("-kernel") + 1])
else:
if config.output_format in (OutputFormat.uki, OutputFormat.esp) and kernel:
logging.warning(
- f"Booting UKI output, kernel {kernel} configured with QemuKernel= or "
+ f"Booting UKI output, kernel {kernel} configured with Linux= or "
"passed with -kernel will not be used"
)
kernel = None
if kernel and not kernel.exists():
die(f"Kernel not found at {kernel}")
- firmware = finalize_qemu_firmware(config, kernel)
+ firmware = finalize_firmware(config, kernel)
if not kernel and (
- firmware == QemuFirmware.linux
+ firmware == Firmware.linux
or config.output_format in (OutputFormat.cpio, OutputFormat.directory, OutputFormat.uki)
):
if firmware.is_uefi():
if not kernel.exists():
die(
f"Kernel or UKI not found at {kernel}, please install a kernel in the image "
- "or provide a -kernel argument to mkosi qemu"
+ "or provide a -kernel argument to mkosi vm"
)
ovmf = find_ovmf_firmware(config, firmware)
or config.runtime_home
or config.output_format == OutputFormat.directory
):
- shm = ["-object", f"memory-backend-memfd,id=mem,size={config.qemu_mem // 1024**2}M,share=on"]
+ shm = ["-object", f"memory-backend-memfd,id=mem,size={config.ram // 1024**2}M,share=on"]
machine = f"type={config.architecture.default_qemu_machine()}"
if firmware.is_uefi() and config.architecture.supports_smm():
- machine += f",smm={'on' if firmware == QemuFirmware.uefi_secure_boot else 'off'}"
+ machine += f",smm={'on' if firmware == Firmware.uefi_secure_boot else 'off'}"
if shm:
machine += ",memory-backend=mem"
cmdline: list[PathString] = [
qemu,
"-machine", machine,
- "-smp", str(config.qemu_smp or os.cpu_count()),
- "-m", f"{config.qemu_mem // 1024**2}M",
+ "-smp", str(config.cpus or os.cpu_count()),
+ "-m", f"{config.ram // 1024**2}M",
"-object", "rng-random,filename=/dev/urandom,id=rng0",
"-device", "virtio-rng-pci,rng=rng0,id=rng-device0",
"-device", "virtio-balloon,free-page-reporting=on",
elif config.runtime_network == Network.none:
cmdline += ["-nic", "none"]
- if config.qemu_kvm != ConfigFeature.disabled and have_kvm and config.architecture.can_kvm():
+ if config.kvm != ConfigFeature.disabled and have_kvm and config.architecture.can_kvm():
accel = "kvm"
if qemu_version(config, qemu) >= QEMU_KVM_DEVICE_VERSION:
index = list(qemu_device_fds.keys()).index(QemuDeviceNode.kvm)
cid: Optional[int] = None
if QemuDeviceNode.vhost_vsock in qemu_device_fds:
- if config.qemu_vsock_cid == QemuVsockCID.auto:
+ if config.vsock_cid == VsockCID.auto:
cid = find_unused_vsock_cid(config, qemu_device_fds[QemuDeviceNode.vhost_vsock])
- elif config.qemu_vsock_cid == QemuVsockCID.hash:
+ elif config.vsock_cid == VsockCID.hash:
cid = hash_to_vsock_cid(hash_output(config))
else:
- cid = config.qemu_vsock_cid
+ cid = config.vsock_cid
if vsock_cid_in_use(qemu_device_fds[QemuDeviceNode.vhost_vsock], cid):
die(
f"VSock connection ID {cid} is already in use by another virtual machine",
- hint="Use QemuVsockConnectionId=auto to have mkosi automatically "
+ hint="Use VsockConnectionId=auto to have mkosi automatically "
"find a free vsock connection ID",
)
index = list(qemu_device_fds.keys()).index(QemuDeviceNode.vhost_vsock)
cmdline += ["-device", f"vhost-vsock-pci,guest-cid={cid},vhostfd={SD_LISTEN_FDS_START + index}"]
- if config.qemu_gui:
+ if config.console == ConsoleMode.gui:
if config.architecture.is_arm_variant():
cmdline += ["-device", "virtio-gpu-pci"]
else:
ovmf_vars, ovmf_vars_format = finalize_firmware_variables(config, qemu, ovmf, stack)
cmdline += ["-drive", f"file={ovmf_vars},if=pflash,format={ovmf_vars_format}"]
- if firmware == QemuFirmware.uefi_secure_boot:
+ if firmware == Firmware.uefi_secure_boot:
cmdline += [
"-global", "ICH9-LPC.disable_s3=1",
"-global", "driver=cfi.pflash01,property=secure,value=on",
] # fmt: skip
- if config.qemu_cdrom and config.output_format in (OutputFormat.disk, OutputFormat.esp):
+ if config.cdrom and config.output_format in (OutputFormat.disk, OutputFormat.esp):
# CD-ROM devices have sector size 2048 so we transform disk images into ones with sector size
# 2048.
src = (config.output_dir_or_cwd() / config.output_with_compression).resolve()
cache = f"cache.writeback=on,cache.direct={yes_no(direct)},cache.no-flush={yes_no(ephemeral)},aio=io_uring" # noqa: E501
device_type = "virtio-blk-pci"
- if config.qemu_cdrom:
+ if config.cdrom:
device_type = "scsi-cd"
- elif config.qemu_removable:
+ elif config.removable:
device_type = "scsi-hd,removable=on"
cmdline += [
"-device", f"{device_type},drive=mkosi,bootindex=1",
] # fmt: skip
- if config.qemu_swtpm == ConfigFeature.enabled or (
- config.qemu_swtpm == ConfigFeature.auto
+ if config.tpm == ConfigFeature.enabled or (
+ config.tpm == ConfigFeature.auto
and firmware.is_uefi()
and config.find_binary("swtpm") is not None
):
f"type=11,value=io.systemd.boot.kernel-cmdline-extra={' '.join(kcl).replace(',', ',,')}",
]
- for _, drives in groupby(config.qemu_drives, key=lambda d: d.file_id):
+ for _, drives in groupby(config.drives, key=lambda d: d.file_id):
file = stack.enter_context(finalize_drive(config, drives[0]))
for drive in drives:
if not (p := INVOKING_USER.runtime_dir() / "machine" / f"{config.machine_or_name()}.json").exists():
die(
f"{p} not found, cannot SSH into virtual machine {config.machine_or_name()}",
- hint="Is the machine running and was it built with Ssh=yes and QemuVsock=yes?",
+ hint="Is the machine running and was it built with Ssh=yes and Vsock=yes?",
)
state = json.loads(p.read_text())
`mkosi [options…] boot [nspawn settings…]`
-`mkosi [options…] qemu [qemu parameters…]`
+`mkosi [options…] vm [vmm parameters…]`
`mkosi [options…] ssh [command line…]`
the `boot` verb, which can contain extra nspawn options as well as arguments
which are passed as the *kernel command line* to the init system in the image.
-`qemu`
+`vm`
: Similar to `boot`, but uses the configured virtual machine monitor (by
default `qemu`) to boot up the image, i.e. instead of container
virtualization, virtual machine virtualization is used. How extra
`ssh`
: When the image is built with the `Ssh=yes` option, this command
- connects to a booted virtual machine (`qemu`) via SSH. Make sure to
- run `mkosi ssh` with the same config as `mkosi build` so that it has
+ connects to a booted virtual machine via SSH. Make sure to run `mkosi ssh`
+ with the same config as `mkosi build` so that it has
the necessary information available to connect to the running virtual
machine via SSH. Specifically, the SSH private key from the `SshKey=`
setting is used to connect to the virtual machine. Use `mkosi genkey`
The `Machine=` option can be used to give the machine a custom
hostname when booting it which can later be used to ssh into the image
- (e.g. `mkosi --machine=mymachine qemu` followed by
+ (e.g. `mkosi --machine=mymachine vm` followed by
`mkosi --machine=mymachine ssh`).
`journalctl`
`sandbox`
: Run arbitrary commands inside of the same sandbox used to execute
- other verbs such as `boot`, `shell`, `qemu` and more. This means
+ other verbs such as `boot`, `shell`, `vm` and more. This means
`/usr` will be replaced by `/usr` from the tools tree if one is used
while everything else will remain in place. If no command is provided,
`$SHELL` will be executed or `bash` if `$SHELL` is not set.
8, which default to `xz`, and OCI images, which default to `gzip`.
Note that when applied to block device image types,
compression means the image cannot be started directly but needs to be
- decompressed first. This also means that the `shell`, `boot`, `qemu` verbs
+ decompressed first. This also means that the `shell`, `boot`, `vm` verbs
are not available when this option is used. Implied for `tar`, `cpio`, `uki`,
`esp`, and `oci`.
`Ssh=`, `--ssh`
: If specified, an sshd socket unit and matching service are installed
in the final image that expose SSH over VSock. When building with this
- option and running the image using `mkosi qemu`, the `mkosi ssh`
+ option and running the image using `mkosi vm`, the `mkosi ssh`
command can be used to connect to the container/VM via SSH. Note that
you still have to make sure openssh is installed in the image to make
this option behave correctly. Run `mkosi genkey` to automatically
build without specifying `--force`.
To give an example of why this is useful, if you run
- `mkosi -O my-custom-output-dir -f` followed by `mkosi qemu`, `mkosi`
+ `mkosi -O my-custom-output-dir -f` followed by `mkosi vm`, `mkosi`
will fail saying the image hasn't been built yet. If you run
`mkosi -O my-custom-output-dir --history=yes -f` followed by
- `mkosi qemu`, it will boot the image built in the previous step as
+ `mkosi vm`, it will boot the image built in the previous step as
expected.
`BuildSources=`, `--build-sources=`
invocation and are interpreted as extra vmspawn options and extra
kernel command line arguments.
-`QemuGui=`, `--qemu-gui=`
-: If enabled, qemu is executed with its graphical interface instead of
- with a serial console.
+`Console=`, `--console=`
+: Configures how to set up the console of the VM. Takes one of `interactive`, `read-only`, `native`, or
+ `gui`. Defaults to `interactive`. `interactive` provides an interactive terminal interface to the VM.
+ `read-only` is similar, but is strictly read-only, i.e. does not accept any input from the user.
+ `native` also provides a TTY-based interface, but uses qemu's native implementation (which means the qemu
+ monitor is available). `gui` shows the qemu graphical UI.
-`QemuSmp=`, `--qemu-smp=`
-: When used with the `qemu` verb, this options sets `qemu`'s `-smp`
- argument which controls the number of guest's CPUs. Defaults to `2`.
+`CPUs=`, `--cpus=`
+: Configures the number of CPU cores to assign to the guest when booting a virtual machine.
+ Defaults to `2`.
When set to `0`, the number of CPUs available to the mkosi process
will be used.
-`QemuMem=`, `--qemu-mem=`
-: When used with the `qemu` verb, this options sets `qemu`'s `-m`
- argument which controls the amount of guest's RAM. Defaults to `2G`.
+`RAM=`, `--ram=`
+: Configures the amount of RAM assigned to the guest when booting a virtual machine. Defaults to `2G`.
-`QemuKvm=`, `--qemu-kvm=`
-: When used with the `qemu` verb, this option specifies whether QEMU should use KVM acceleration. Takes a
+`KVM=`, `--kvm=`
+: Configures whether KVM acceleration should be used when booting a virtual machine. Takes a
boolean value or `auto`. Defaults to `auto`.
-`QemuVsock=`, `--qemu-vsock=`
-: When used with the `qemu` verb, this option specifies whether QEMU should be configured with a vsock. Takes
+`Vsock=`, `--vsock=`
+: Configures whether to provision a vsock when booting a virtual machine. Takes
a boolean value or `auto`. Defaults to `auto`.
-`QemuVsockConnectionId=`, `--qemu-vsock-cid=`
-: When used with the `qemu` verb, this option specifies the vsock
- connection ID to use. Takes a number in the interval `[3, 0xFFFFFFFF)`
- or `hash` or `auto`. Defaults to `auto`. When set to `hash`, the
- connection ID will be derived from the full path to the image. When
- set to `auto`, `mkosi` will try to find a free connection ID
- automatically. Otherwise, the provided number will be used as is.
-
-`QemuSwtpm=`, `--qemu-swtpm=`
-: When used with the `qemu` verb, this option specifies whether to start an instance of swtpm to be used as a
- TPM with qemu. This requires swtpm to be installed on the host. Takes a boolean value or `auto`. Defaults
- to `auto`.
-
-`QemuCdrom=`, `--qemu-cdrom=`
-: When used with the `qemu` verb, this option specifies whether to
- attach the image to the virtual machine as a CD-ROM device. Takes a
- boolean. Defaults to `no`.
-
-`QemuRemovable=`, `--qemu-removable=`
-: When used with the `qemu` verb, this option specifies whether to attach the image to the virtual machine
- as a removable device. Takes a boolean. Defaults to `no`.
-
-`QemuFirmware=`, `--qemu-firmware=`
-: When used with the `qemu` verb, this option specifies which firmware
- to use. Takes one of `uefi`, `uefi-secure-boot`, `bios`, `linux`, or
- `auto`. Defaults to `auto`. When set to `uefi`, the OVMF firmware
- without secure boot support is used. When set to `uefi-secure-boot`,
- the OVMF firmware with secure boot support is used. When set to
- `bios`, the default SeaBIOS firmware is used. When set to `linux`,
- direct kernel boot is used. See the `QemuKernel=` option for more
- details on which kernel image is used with direct kernel boot. When
- set to `auto`, `uefi-secure-boot` is used if possible and `linux`
- otherwise.
-
-`QemuFirmwareVariables=`, `--qemu-firmware-variables=`
-: When used with the `qemu` verb, this option specifies the path to the
- the firmware variables file to use. Currently, this option is only
- taken into account when the `uefi` or `uefi-secure-boot` firmware is
- used. If not specified, mkosi will search for the default variables
- file and use that instead.
+`VsockConnectionId=`, `vsock-cid=`
+: Configures the vsock connection ID to use when booting a virtual machine.
+ Takes a number in the interval `[3, 0xFFFFFFFF)` or `hash` or `auto`.
+ Defaults to `auto`. When set to `hash`, the connection ID will be derived
+ from the full path to the image. When set to `auto`, `mkosi` will try to
+ find a free connection ID automatically. Otherwise, the provided number will
+ be used as is.
+
+`TPM=`, `--tpm=`
+: Configure whether to use a virtual TPM when booting a virtual machine.
+ Takes a boolean value or `auto`. Defaults to `auto`.
+
+`Cdrom=`, `--cdrom=`
+: Configures whether to attach the image as a CD-ROM device when booting a
+ virtual machine. Takes a boolean. Defaults to `no`.
+
+`Removable=`, `--removable=`
+: Configures whether to attach the image as a removable device when booting
+ a virtual machine. Takes a boolean. Defaults to `no`.
+
+`Firmware=`, `--firmware=`
+: Configures the virtual machine firmware to use. Takes one of `uefi`,
+ `uefi-secure-boot`, `bios`, `linux`, or `auto`. Defaults to `auto`.
+ When set to `uefi`, the OVMF firmware without secure boot support
+ is used. When set to `uefi-secure-boot`, the OVMF firmware with
+ secure boot support is used. When set to `bios`, the default SeaBIOS
+ firmware is used. When set to `linux`, direct kernel boot is used.
+ See the `Linux=` option for more details on which kernel image is
+ used with direct kernel boot. When set to `auto`, `uefi-secure-boot`
+ is used if possible and `linux` otherwise.
+
+`FirmwareVariables=`, `--firmware-variables=`
+: Configures the path to the the virtual machine firmware variables file
+ to use. Currently, this option is only taken into account when the `uefi`
+ or `uefi-secure-boot` firmware is used. If not specified, mkosi will search
+ for the default variables file and use that instead.
When set to `microsoft`, a firmware variables file with the Microsoft
secure boot certificates already enrolled will be used.
[virt-firmware](https://gitlab.com/kraxel/virt-firmware) project can
be used to customize OVMF variable files.
-`QemuKernel=`, `--qemu-kernel=`
+`Linux=`, `--linux=`
: Set the kernel image to use for qemu direct kernel boot. If not
specified, mkosi will use the kernel provided via the command line
(`-kernel` option) or latest the kernel that was installed into
configured firmware, qemu might boot the kernel itself or using the
configured firmware.
-`QemuDrives=`, `--qemu-drive=`
-: Add a qemu drive. Takes a colon-delimited string of format
+`Drives=`, `--drive=`
+: Add a drive. Takes a colon-delimited string of format
`<id>:<size>[:<directory>[:<options>[:<file-id>]]]`. `id` specifies
- the qemu ID assigned to the drive. This can be used as the `drive=`
+ the ID assigned to the drive. This can be used as the `drive=`
property in various qemu devices. `size` specifies the size of the
drive. This takes a size in bytes. Additionally, the suffixes `K`, `M`
and `G` can be used to specify a size in kilobytes, megabytes and
```ini
[Runtime]
- QemuDrives=btrfs:10G
- ext4:20G
+ Drives=btrfs:10G
+ ext4:20G
QemuArgs=-device nvme,serial=btrfs,drive=btrfs
-device nvme,serial=ext4,drive=ext4
```
qemu.
`Ephemeral=`, `--ephemeral`
-: When used with the `shell`, `boot`, or `qemu` verbs, this option runs the specified verb on a temporary
+: When used with the `shell`, `boot`, or `vm` verbs, this option runs the specified verb on a temporary
snapshot of the output image that is removed immediately when the container terminates. Taking the
temporary snapshot is more efficient on file systems that support reflinks natively (btrfs or xfs)
than on more traditional file systems that do not (ext4).
`Credentials=`, `--credential=`
-: Set credentials to be passed to systemd-nspawn or qemu respectively
- when `mkosi shell/boot` or `mkosi qemu` are used. This option takes a
+: Set credentials to be passed to systemd-nspawn or the virtual machine respectively
+ when `mkosi shell/boot` or `mkosi vm` are used. This option takes a
space separated list of values which can be either key=value pairs or
paths. If a path is provided, if it is a file, the credential name
will be the name of the file. If the file is executable, the
machine in these directories will be owned by the user running mkosi
on the host.
- Note that when using `mkosi qemu` with this feature systemd v254 or
+ Note that when using `mkosi vm` with this feature systemd v254 or
newer has to be installed in the image.
`RuntimeSize=`, `--runtime-size=`
: If specified, disk images are grown to the specified size when
- they're booted with `mkosi boot` or `mkosi qemu`. Takes a size in
+ they're booted with `mkosi boot` or `mkosi vm`. Takes a size in
bytes. Additionally, the suffixes `K`, `M` and `G` can be used to
specify a size in kilobytes, megabytes and gigabytes respectively.
: Takes a boolean value or `auto`. Specifies whether to mount extra
scratch space to `/var/tmp`. If enabled, practically unlimited scratch
space is made available under `/var/tmp` when booting the image with
- `mkosi qemu`, `mkosi boot` or `mkosi shell`.
+ `mkosi vm`, `mkosi boot` or `mkosi shell`.
- Note that using this feature with `mkosi qemu` requires systemd v254
+ Note that using this feature with `mkosi vm` requires systemd v254
or newer in the guest.
`RuntimeNetwork=`, `--runtime-network=`
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`.
+ `mkosi vm` and `mkosi vmspawn`.
Note that when using `interface`, mkosi does not automatically
configure the host interface. It is expected that a recent version of
: Mount the build sources configured with `BuildSources=` and the build
directory (if one is configured) to the same locations in `/work` that
they were mounted to when running the build script when using `mkosi
- boot` or `mkosi qemu`.
+ boot` or `mkosi vm`.
`RuntimeHome=`, `--runtime-home=`
: Mount the current home directory from which mkosi is running to
- `/root` when using `mkosi boot` or `mkosi qemu`.
+ `/root` when using `mkosi boot` or `mkosi vm`.
`UnitProperties=`, `--unit-property=`
: Configure systemd unit properties to add to the systemd scopes
- allocated when using `mkosi boot` or `mkosi qemu`. These are passed
+ allocated when using `mkosi boot` or `mkosi vm`. These are passed
directly to the `--property` options of `systemd-nspawn` and
`systemd-run` respectively.
`SshKey=`, `--ssh-key=`
: Path to the X509 private key in PEM format to use to connect to a
- virtual machine started with `mkosi qemu` and built with the `Ssh=`
+ virtual machine started with `mkosi vm` and built with the `Ssh=`
option enabled via the `mkosi ssh` command. If not configured and
`mkosi.key` exists in the working directory, it will automatically be
used for this purpose. Run `mkosi genkey` to automatically generate
`SshCertificate=`, `--ssh-certificate=`
: Path to the X509 certificate in PEM format to provision as the SSH
- public key in virtual machines started with `mkosi qemu`. If not
+ public key in virtual machines started with `mkosi vm`. If not
configured and `mkosi.crt` exists in the working directory, it will
automatically be used for this purpose. Run `mkosi genkey` to
automatically generate a certificate in `mkosi.crt`.
modify the configuration. It receives the configuration serialized as
JSON on stdin and should output the modified configuration serialized
as JSON on stdout. Note that this script only runs when building or
- booting the image (`build`, `qemu`, `boot` and `shell` verbs). If a
+ booting the image (`build`, `vm`, `boot` and `shell` verbs). If a
default tools tree is configured, it will be built before running the
configure scripts and the configure scripts will run with the tools
tree available. This also means that the modifications made by
```console
$ mkosi -d fedora -p kernel-core -p systemd -p systemd-boot -p udev -o foobar.raw
# mkosi --output foobar.raw boot
-$ mkosi --output foobar.raw qemu
+$ mkosi --output foobar.raw vm
```
Create and run a *Fedora Linux* image in a plain directory:
# systemd-nspawn -bi image.raw
```
-## Different ways to boot with `qemu`
+## Different ways to boot with `vm`
The easiest way to boot a virtual machine is to build an image with the
required components and let `mkosi` call `qemu` with all the right options:
--autologin \
-p systemd-udev,systemd-boot,kernel-core \
build
-$ mkosi -d fedora qemu
+$ mkosi -d fedora vm
...
fedora login: root (automatic login)
[root@fedora ~]#
or shut down the machine quickly. Alternatively the machine can be shut down
using `Ctrl-a x`.
-To boot with a graphical window, add `--qemu-qui`:
+To boot with a graphical window, add `--console=gui`:
```console
-$ mkosi -d fedora --qemu-gui qemu
+$ mkosi -d fedora --console=gui qemu
```
A kernel may be booted directly with
-`mkosi qemu -kernel ... -initrd ... -append '...'`.
+`mkosi vm -kernel ... -initrd ... -append '...'`.
This is a bit faster because no boot loader is used, and it is also
easier to experiment with different kernels and kernel commandlines.
Note that despite the name, qemu's `-append` option replaces
The UKI is also copied into the output directory and may be booted directly:
```console
-$ mkosi qemu -kernel mkosi.output/fedora~38/image.efi
+$ mkosi vm -kernel mkosi.output/fedora~38/image.efi
```
When booting using an external kernel, we don't need the kernel *in* the image,
It is also possible to do a *direct kernel boot* into a boot loader,
taking advantage of the fact that `systemd-boot(7)` is a valid UEFI binary:
```console
-$ mkosi qemu -kernel /usr/lib/systemd/boot/efi/systemd-bootx64.efi
+$ mkosi vm -kernel /usr/lib/systemd/boot/efi/systemd-bootx64.efi
```
In this scenario, the kernel is loaded from the ESP in the image by `systemd-boot`.
# Frequently Asked Questions (FAQ)
-- Why does `mkosi qemu` with KVM not work on Debian/Kali/Ubuntu?
+- Why does `mkosi vm` with KVM not work on Debian/Kali/Ubuntu?
While other distributions are OK with allowing access to `/dev/kvm`, on
Debian/Kali/Ubuntu this is only allowed for users in the `kvm` group. Because
from mkosi.config import (
Args,
Config,
+ Firmware,
Network,
OutputFormat,
- QemuFirmware,
yes_no,
)
from mkosi.log import die
apply_runtime_size,
copy_ephemeral,
finalize_credentials,
+ finalize_firmware,
finalize_kernel_command_line_extra,
- finalize_qemu_firmware,
)
from mkosi.run import run
from mkosi.types import PathString
if config.output_format not in (OutputFormat.disk, OutputFormat.esp, OutputFormat.directory):
die(f"{config.output_format} images cannot be booted in systemd-vmspawn")
- if config.qemu_firmware == QemuFirmware.bios:
+ if config.firmware == Firmware.bios:
die("systemd-vmspawn cannot boot BIOS firmware images")
- if config.qemu_cdrom:
+ if config.cdrom:
die("systemd-vmspawn does not support CD-ROM images")
- if config.qemu_firmware_variables and config.qemu_firmware_variables != Path("microsoft"):
- die("mkosi vmspawn does not support QemuFirmwareVariables=")
+ if config.firmware_variables and config.firmware_variables != Path("microsoft"):
+ die("mkosi vmspawn does not support FirmwareVariables=")
- kernel = config.qemu_kernel
- firmware = finalize_qemu_firmware(config, kernel)
+ kernel = config.linux
+ firmware = finalize_firmware(config, kernel)
- if not kernel and firmware == QemuFirmware.linux:
+ if not kernel and firmware == Firmware.linux:
kernel = config.output_dir_or_cwd() / config.output_split_kernel
if not kernel.exists():
die(
f"Kernel or UKI not found at {kernel}",
- hint="Please install a kernel in the image or provide a --qemu-kernel"
+ hint="Please install a kernel in the image or provide a --linux"
" argument to mkosi vmspawn",
)
cmdline: list[PathString] = [
"systemd-vmspawn",
- "--cpus", str(config.qemu_smp or os.cpu_count()),
- "--ram", str(config.qemu_mem),
- "--kvm", config.qemu_kvm.to_tristate(),
- "--vsock", config.qemu_vsock.to_tristate(),
- "--tpm", config.qemu_swtpm.to_tristate(),
+ "--cpus", str(config.cpus or os.cpu_count()),
+ "--ram", str(config.ram),
+ "--kvm", config.kvm.to_tristate(),
+ "--vsock", config.vsock.to_tristate(),
+ "--tpm", config.tpm.to_tristate(),
"--secure-boot", yes_no(config.secure_boot),
"--register", yes_no(config.register),
+ "--console", str(config.console),
] # fmt: skip
if config.runtime_network == Network.user:
elif config.runtime_network == Network.interface:
cmdline += ["--network-tap"]
- if config.qemu_gui:
- cmdline += ["--console=gui"]
-
cmdline += [f"--set-credential={k}:{v}" for k, v in finalize_credentials(config).items()]
with contextlib.ExitStack() as stack:
return result
- def vm(self, verb: str, options: Sequence[str] = (), args: Sequence[str] = ()) -> CompletedProcess:
+ def vm(self, options: Sequence[str] = (), args: Sequence[str] = ()) -> CompletedProcess:
result = self.mkosi(
- verb,
+ "vm",
[
"--runtime-build-sources=no",
- "--qemu-vsock=yes",
+ "--vsock=yes",
# TODO: Drop once both Hyper-V bugs are fixed in Github Actions.
"--qemu-args=-cpu max,pcid=off",
- "--qemu-mem=2G",
+ "--ram=2G",
"--ephemeral",
*options,
],
return result
- def qemu(self, options: Sequence[str] = (), args: Sequence[str] = ()) -> CompletedProcess:
- return self.vm("qemu", options, args)
-
- def vmspawn(self, options: Sequence[str] = (), args: Sequence[str] = ()) -> CompletedProcess:
- return self.vm("vmspawn", options, args)
-
def genkey(self) -> CompletedProcess:
return self.mkosi("genkey", ["--force"], user=self.uid, group=self.gid)
import pytest
-from mkosi.config import Bootloader, OutputFormat, QemuFirmware
+from mkosi.config import Bootloader, Firmware, OutputFormat
from mkosi.distributions import Distribution
from mkosi.qemu import find_virtiofsd
from mkosi.run import find_binary, run
if format == OutputFormat.directory and not find_virtiofsd():
return
- image.qemu()
+ image.vm()
if have_vmspawn() and format in (OutputFormat.disk, OutputFormat.directory):
- image.vmspawn()
+ image.vm(options=["--vmm=vmspawn"])
if format != OutputFormat.disk:
return
- image.qemu(["--qemu-firmware=bios"])
+ image.vm(["--firmware=bios"])
@pytest.mark.parametrize("bootloader", Bootloader)
if config.distribution == Distribution.rhel_ubi:
return
- firmware = QemuFirmware.linux if bootloader == Bootloader.none else QemuFirmware.auto
+ firmware = Firmware.linux if bootloader == Bootloader.none else Firmware.auto
with Image(config) as image:
image.genkey()
image.build(["--format=disk", "--bootloader", str(bootloader)])
- image.qemu(["--qemu-firmware", str(firmware)])
+ image.vm(["--firmware", str(firmware)])
Distribution=fedora
[Runtime]
- QemuKvm=yes
+ KVM=yes
"""
)
assert config.profiles == ["profile"]
# The profile should override mkosi.conf.d/
assert config.distribution == Distribution.fedora
- assert config.qemu_kvm == ConfigFeature.enabled
+ assert config.kvm == ConfigFeature.enabled
(d / "mkosi.conf").unlink()
assert config.profiles == ["profile"]
# The profile should override mkosi.conf.d/
assert config.distribution == Distribution.fedora
- assert config.qemu_kvm == ConfigFeature.enabled
+ assert config.kvm == ConfigFeature.enabled
(d / "mkosi.conf").write_text(
"""\
assert parse_config(["shell"])[0].verb == Verb.shell
assert parse_config(["boot"])[0].verb == Verb.boot
assert parse_config(["qemu"])[0].verb == Verb.qemu
+ assert parse_config(["vm"])[0].verb == Verb.vm
assert parse_config(["journalctl"])[0].verb == Verb.journalctl
assert parse_config(["coredumpctl"])[0].verb == Verb.coredumpctl
with pytest.raises(SystemExit):
def test_initrd(config: ImageConfig) -> None:
with Image(config) as image:
image.build(options=["--format=disk"])
- image.qemu()
+ image.vm()
@pytest.mark.skipif(os.getuid() != 0, reason="mkosi-initrd LVM test can only be executed as root")
lvm.rename(Path(image.output_dir) / "image.raw")
- image.qemu(
+ image.vm(
[
- "--qemu-firmware=linux",
+ "--firmware=linux",
# LVM confuses systemd-repart so we mask it for this test.
"--kernel-command-line-extra=systemd.mask=systemd-repart.service",
"--kernel-command-line-extra=root=LABEL=root",
with Image(config) as image:
image.build(["--repart-directory", repartd, "--passphrase", passphrase, "--format=disk"])
- image.qemu(["--credential=cryptsetup.passphrase=mkosi"])
+ image.vm(["--credential=cryptsetup.passphrase=mkosi"])
@pytest.mark.skipif(os.getuid() != 0, reason="mkosi-initrd LUKS+LVM test can only be executed as root")
lvm.rename(Path(image.output_dir) / "image.raw")
- image.qemu(
+ image.vm(
[
"--format=disk",
"--credential=cryptsetup.passphrase=mkosi",
- "--qemu-firmware=linux",
+ "--firmware=linux",
"--kernel-command-line-extra=root=LABEL=root",
f"--kernel-command-line-extra=rd.luks.uuid={luks_uuid}",
]
Config,
ConfigFeature,
ConfigTree,
+ ConsoleMode,
DocFormat,
+ Drive,
+ Firmware,
Incremental,
KeySource,
KeySourceType,
ManifestFormat,
Network,
OutputFormat,
- QemuDrive,
- QemuFirmware,
- QemuVsockCID,
SecureBootSignTool,
ShimBootloader,
UKIProfile,
Verb,
Vmm,
+ VsockCID,
)
from mkosi.distributions import Distribution
from mkosi.versioncomp import GenericVersion
}
],
"BuildSourcesEphemeral": true,
+ "CPUs": 2,
"CacheDirectory": "/is/this/the/cachedir",
"CacheOnly": "always",
+ "Cdrom": false,
"Checksum": false,
"CleanPackageMetadata": "auto",
"CleanScripts": [
"ConfigureScripts": [
"/configure"
],
+ "Console": "gui",
"Credentials": {
"credkey": "credval"
},
"dep1"
],
"Distribution": "fedora",
+ "Drives": [
+ {
+ "Directory": "/foo/bar",
+ "FileId": "red",
+ "Id": "abc",
+ "Options": "abc,qed",
+ "Size": 200
+ },
+ {
+ "Directory": null,
+ "FileId": "wcd",
+ "Id": "abc",
+ "Options": "",
+ "Size": 200
+ }
+ ],
"Environment": {
"BAR": "BAR",
"Qux": "Qux",
"ExtraTrees": [],
"Files": [],
"FinalizeScripts": [],
+ "Firmware": "linux",
+ "FirmwareVariables": "/foo/bar",
"Format": "uki",
"ForwardJournal": "/mkosi.journal",
"History": true,
"/efi/initrd1",
"/efi/initrd2"
],
+ "KVM": "auto",
"KernelCommandLine": [],
"KernelCommandLineExtra": [
"look",
"KernelModulesInitrdIncludeHost": true,
"Key": null,
"Keymap": "wow, so much keymap",
+ "Linux": null,
"LocalMirror": null,
"Locale": "en_C.UTF-8",
"LocaleMessages": "",
"ProxyPeerCertificate": "/my/peer/cert",
"ProxyUrl": "https://my/proxy",
"QemuArgs": [],
- "QemuCdrom": false,
- "QemuDrives": [
- {
- "Directory": "/foo/bar",
- "FileId": "red",
- "Id": "abc",
- "Options": "abc,qed",
- "Size": 200
- },
- {
- "Directory": null,
- "FileId": "wcd",
- "Id": "abc",
- "Options": "",
- "Size": 200
- }
- ],
- "QemuFirmware": "linux",
- "QemuFirmwareVariables": "/foo/bar",
- "QemuGui": true,
- "QemuKernel": null,
- "QemuKvm": "auto",
- "QemuMem": 123,
- "QemuRemovable": false,
- "QemuSmp": 2,
- "QemuSwtpm": "auto",
- "QemuVsock": "enabled",
- "QemuVsockConnectionId": -2,
+ "RAM": 123,
"Register": true,
"Release": "53",
+ "Removable": false,
"RemoveFiles": [],
"RemovePackages": [
"all"
"/sync"
],
"SysupdateDirectory": "/sysupdate",
+ "TPM": "auto",
"Timezone": null,
"ToolsTree": null,
"ToolsTreeCertificates": true,
"VolatilePackages": [
"abc"
],
+ "Vsock": "enabled",
+ "VsockConnectionId": -2,
"WithDocs": true,
"WithNetwork": false,
"WithRecommends": true,
build_dir=None,
build_packages=["pkg1", "pkg2"],
build_scripts=[Path("/path/to/buildscript")],
- build_sources=[ConfigTree(Path("/qux"), Path("/frob"))],
build_sources_ephemeral=True,
+ build_sources=[ConfigTree(Path("/qux"), Path("/frob"))],
cache_dir=Path("/is/this/the/cachedir"),
cacheonly=Cacheonly.always,
+ cdrom=False,
checksum=False,
clean_package_metadata=ConfigFeature.auto,
clean_scripts=[Path("/clean")],
compress_level=3,
compress_output=Compression.bz2,
configure_scripts=[Path("/configure")],
+ console=ConsoleMode.gui,
+ cpus=2,
credentials={"credkey": "credval"},
dependencies=["dep1"],
distribution=Distribution.fedora,
- environment={"foo": "foo", "BAR": "BAR", "Qux": "Qux"},
+ drives=[Drive("abc", 200, Path("/foo/bar"), "abc,qed", "red"), Drive("abc", 200, None, "", "wcd")],
environment_files=[],
+ environment={"foo": "foo", "BAR": "BAR", "Qux": "Qux"},
ephemeral=True,
extra_search_paths=[],
extra_trees=[],
files=[],
finalize_scripts=[],
+ firmware_variables=Path("/foo/bar"),
+ firmware=Firmware.linux,
forward_journal=Path("/mkosi.journal"),
history=True,
hostname=None,
- vmm=Vmm.qemu,
- image="default",
image_id="myimage",
image_version="5",
+ image="default",
incremental=Incremental.no,
initrd_packages=["clevis"],
initrd_volatile_packages=["abc"],
initrds=[Path("/efi/initrd1"), Path("/efi/initrd2")],
- microcode_host=True,
- kernel_command_line=[],
kernel_command_line_extra=["look", "im", "on", "the", "kernel", "command", "line"],
+ kernel_command_line=[],
kernel_modules_exclude=["nvidia"],
- kernel_modules_include=["loop"],
kernel_modules_include_host=True,
- kernel_modules_initrd=True,
+ kernel_modules_include=["loop"],
kernel_modules_initrd_exclude=[],
- kernel_modules_initrd_include=[],
kernel_modules_initrd_include_host=True,
+ kernel_modules_initrd_include=[],
+ kernel_modules_initrd=True,
key=None,
keymap="wow, so much keymap",
+ kvm=ConfigFeature.auto,
+ linux=None,
local_mirror=None,
- locale="en_C.UTF-8",
locale_messages="",
- machine="machine",
+ locale="en_C.UTF-8",
machine_id=uuid.UUID("b58253b0cc924a348782bcd99b20d07f"),
+ machine="machine",
make_initrd=False,
manifest_format=[ManifestFormat.json, ManifestFormat.changelog],
+ microcode_host=True,
minimum_version=GenericVersion("123"),
mirror=None,
nspawn_settings=None,
openpgp_tool="gpg",
- output="outfile",
output_dir=Path("/your/output/here"),
output_format=OutputFormat.uki,
output_mode=0o123,
+ output="outfile",
overlay=True,
package_cache_dir=Path("/a/b/c"),
package_directories=[],
- sandbox_trees=[ConfigTree(Path("/foo/bar"), None)],
packages=[],
pass_environment=["abc"],
passphrase=None,
proxy_peer_certificate=Path("/my/peer/cert"),
proxy_url="https://my/proxy",
qemu_args=[],
- qemu_cdrom=False,
- qemu_removable=False,
- qemu_drives=[
- QemuDrive("abc", 200, Path("/foo/bar"), "abc,qed", "red"),
- QemuDrive("abc", 200, None, "", "wcd"),
- ],
- qemu_firmware=QemuFirmware.linux,
- qemu_firmware_variables=Path("/foo/bar"),
- qemu_gui=True,
- qemu_kernel=None,
- qemu_kvm=ConfigFeature.auto,
- qemu_mem=123,
- qemu_smp=2,
- qemu_swtpm=ConfigFeature.auto,
- qemu_vsock=ConfigFeature.enabled,
- qemu_vsock_cid=QemuVsockCID.hash,
+ ram=123,
register=True,
release="53",
+ removable=False,
remove_files=[],
remove_packages=["all"],
repart_dirs=[],
ConfigTree(Path("/foo/bar"), Path("/baz")),
ConfigTree(Path("/bar/baz"), Path("/qux")),
],
+ sandbox_trees=[ConfigTree(Path("/foo/bar"), None)],
sector_size=None,
- secure_boot=True,
secure_boot_auto_enroll=True,
- secure_boot_certificate=None,
secure_boot_certificate_source=CertificateSource(type=CertificateSourceType.file),
- secure_boot_key=Path("/path/to/keyfile"),
+ secure_boot_certificate=None,
secure_boot_key_source=KeySource(type=KeySourceType.file),
+ secure_boot_key=Path("/path/to/keyfile"),
secure_boot_sign_tool=SecureBootSignTool.systemd_sbsign,
+ secure_boot=True,
seed=uuid.UUID("7496d7d8-7f08-4a2b-96c6-ec8c43791b60"),
selinux_relabel=ConfigFeature.disabled,
shim_bootloader=ShimBootloader.none,
- sign=False,
- sign_expected_pcr=ConfigFeature.disabled,
- sign_expected_pcr_key=Path("/my/key"),
- sign_expected_pcr_key_source=KeySource(type=KeySourceType.file),
- sign_expected_pcr_certificate=Path("/my/cert"),
sign_expected_pcr_certificate_source=CertificateSource(type=CertificateSourceType.file),
+ sign_expected_pcr_certificate=Path("/my/cert"),
+ sign_expected_pcr_key_source=KeySource(type=KeySourceType.file),
+ sign_expected_pcr_key=Path("/my/key"),
+ sign_expected_pcr=ConfigFeature.disabled,
+ sign=False,
skeleton_trees=[ConfigTree(Path("/foo/bar"), Path("/")), ConfigTree(Path("/bar/baz"), Path("/qux"))],
source_date_epoch=12345,
split_artifacts=[ArtifactOutput.uki, ArtifactOutput.kernel],
- ssh=False,
ssh_certificate=Path("/path/to/cert"),
ssh_key=None,
+ ssh=False,
sync_scripts=[Path("/sync")],
sysupdate_dir=Path("/sysupdate"),
timezone=None,
- tools_tree=None,
tools_tree_certificates=True,
tools_tree_distribution=Distribution.fedora,
tools_tree_mirror=None,
- tools_tree_sandbox_trees=[ConfigTree(Path("/a/b/c"), Path("/"))],
- tools_tree_packages=[],
tools_tree_package_directories=[Path("/abc")],
+ tools_tree_packages=[],
tools_tree_release=None,
tools_tree_repositories=["abc"],
+ tools_tree_sandbox_trees=[ConfigTree(Path("/a/b/c"), Path("/"))],
+ tools_tree=None,
+ tpm=ConfigFeature.auto,
unified_kernel_image_format="myuki",
unified_kernel_image_profiles=[UKIProfile(profile={"key": "value"}, cmdline=["key=value"])],
unified_kernel_images=ConfigFeature.auto,
unit_properties=["PROPERTY=VALUE"],
use_subvolumes=ConfigFeature.auto,
- verity=ConfigFeature.enabled,
+ verity_certificate_source=CertificateSource(type=CertificateSourceType.file),
verity_certificate=Path("/path/to/cert"),
- verity_key=None,
verity_key_source=KeySource(type=KeySourceType.file),
- verity_certificate_source=CertificateSource(type=CertificateSourceType.file),
+ verity_key=None,
+ verity=ConfigFeature.enabled,
+ vmm=Vmm.qemu,
volatile_package_directories=[Path("def")],
volatile_packages=["abc"],
+ vsock_cid=VsockCID.hash,
+ vsock=ConfigFeature.enabled,
with_docs=True,
with_network=False,
with_recommends=True,