):
cmdline += [f"systemd.hostname={config.machine}"]
- if config.console != ConsoleMode.gui:
+ if config.console not in (ConsoleMode.gui, ConsoleMode.headless):
cmdline += [
f"systemd.tty.term.console={term}",
f"systemd.tty.columns.console={columns}",
"console=hvc0",
f"TERM={term}",
]
- elif config.architecture.is_arm_variant():
+ elif config.console == ConsoleMode.gui and config.architecture.is_arm_variant():
cmdline += ["console=tty0"]
for s in config.kernel_command_line_extra:
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.console not in (ConsoleMode.native, ConsoleMode.gui) and not config.find_binary(
- "systemd-pty-forward"
- ):
+ if config.console not in (
+ ConsoleMode.native,
+ ConsoleMode.gui,
+ ConsoleMode.headless,
+ ) and not config.find_binary("systemd-pty-forward"):
die(f"Console mode {config.console} requested but systemd-pty-forward not found")
if config.linux:
cmdline += [
"-nographic",
"-nodefaults",
- "-chardev", "stdio,mux=on,id=console,signal=off",
- "-device", "virtio-serial-pci,id=mkosi-virtio-serial-pci",
- "-device", "virtconsole,chardev=console",
- "-mon", "console",
] # fmt: skip
+ if config.console != ConsoleMode.headless:
+ cmdline += [
+ "-chardev", "stdio,mux=on,id=console,signal=off",
+ "-device", "virtio-serial-pci,id=mkosi-virtio-serial-pci",
+ "-device", "virtconsole,chardev=console",
+ "-mon", "console",
+ ] # fmt: skip
+
# QEMU has built-in logic to look for the BIOS firmware so we don't need to do anything special for that.
if firmware.is_uefi():
assert ovmf
kernel command line arguments.
`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.
+: Configures how to set up the console of the VM. Takes one of `interactive`, `read-only`, `native`,
+ `gui`, or `headless`. 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. `headless` runs the VM without
+ any console attached, useful for fully automated or scripted VM usage. `headless` is only supported by
+ the `qemu` verb.
`CPUs=`, `--cpus=`
: Configures the number of CPU cores to assign to the guest when booting a virtual machine.
from mkosi.config import (
Args,
Config,
+ ConsoleMode,
Firmware,
Network,
OutputFormat,
if config.firmware_variables and config.firmware_variables != Path("microsoft"):
die("mkosi vmspawn does not support FirmwareVariables=")
+ if config.console == ConsoleMode.headless:
+ die("Console=headless is not supported by vmspawn")
+
kernel = config.expand_linux_specifiers() if config.linux else None
firmware = finalize_firmware(config, kernel)