%entities; ]> systemd-vmspawn systemd systemd-vmspawn 1 systemd-vmspawn Spawn an OS in a virtual machine systemd-vmspawn OPTIONS ARGS Description systemd-vmspawn may be used to start a virtual machine from an OS image. In many ways it is similar to systemd-nspawn1, but launches a full virtual machine instead of using namespaces. File descriptors for /dev/kvm and /dev/vhost-vsock can be passed to systemd-vmspawn via systemd's native socket passing interface (see sd_listen_fds3 for details about the precise protocol used and the order in which the file descriptors are passed), these file descriptors must be passed with the names kvm and vhost-vsock respectively. Note: on Ubuntu/Debian derivatives systemd-vmspawn requires the user to be in the kvm group to use the VSOCK options. Options The excess arguments are passed as extra kernel command line arguments using SMBIOS. The following options are understood: Turns off any status output by the tool itself. When this switch is used, the only output from vmspawn will be the console output of the Virtual Machine OS itself. Specify whether to interact with the user manager or the system manager and whether to register with the user machined instance or the system machined instance. If unspecified, the system manager and machined instance will be used when running as root, otherwise the user manager and machined instance will be used. Image Options Directory to use as file system root for the virtual machine. One of either or must be specified. If neither are specified is assumed. Note: If mounting a non-root owned directory you may require to map into the user's subuid namespace. An example of how to use /etc/subuid for this is given later. If specified, the VM is run with a temporary snapshot of its file system that is removed immediately when the VM terminates. Only works with currently. Note that will not work with . Root file system disk image (or device node) for the virtual machine. Specifies the format of the disk image passed to . Takes either raw or qcow2. Defaults to raw. Note that qcow2 is only supported for regular files, not block devices. Specifies the disk type to use for the root disk passed to . Extra drives added via inherit this disk type unless overridden with an explicit disk type prefix. Takes one of virtio-blk, virtio-scsi, nvme, or scsi-cd. Defaults to virtio-blk. When scsi-cd is specified, the disk is attached as a read-only CD-ROM drive. Controls whether qemu processes discard requests from the VM. This prevents long running VMs from using more disk space than required. This is enabled by default. Grows the image file specified by to the specified size in bytes if it is smaller. Executes no operation if no image file is used or the image file is already as large or larger than requested. The specified size accepts the usual K, M, G suffixes (to the base of 1024). Specified values are rounded up to multiples of 4096. Host Configuration The number of CPUs to start the virtual machine with. Defaults to 1. The amount of memory to start the virtual machine with. Defaults to 2G. If a maximum size is specified after a colon, memory hotplug is enabled with the given upper limit. The number of hotplug slots can optionally be specified after a second colon and defaults to 1. Controls whether to enable KVM acceleration. If not specified or set to , KVM support will be detected automatically. If true, KVM is insisted on. If false, disable KVM. Controls whether to allocate a VSOCK socket for guest. If not specified or set to , VSOCK networking support will be detected automatically. If true, VSOCK is insisted on. If false, VSOCK networking is disabled. Sets the specific CID to use for the guest. Valid CIDs are in the range 3 to 4294967294 (0xFFFF_FFFE). CIDs outside of this range are reserved. By default, vmspawn will attempt to derive a CID for the guest derived from the machine name, falling back to a random CID if this CID is taken. Controls whether to serve a TPM device for guest, via swtpm8. If not specified or set to , vmspawn will detect the presence of swtpm binary automatically. If yes, swtpm support is insisted on. If no, TPM is disabled. Configures where to place TPM state, in case TPM support is enabled (see above). This takes an absolute file system path to a directory to persistently place the state in. If the directory is missing it is created as needed. If set to the special string auto a persistent path is automatically derived from the VM image path or directory path, with the .tpmstate suffix appended. If set to the special string off the TPM state is only maintained transiently and flushed out when the VM shuts down. This mode is not suitable for VMs which lock disk encryption keys to the TPM, as these keys will be lost on every reboot. Defaults to auto. If is specified, auto behaves like off. Takes an absolute path, or a relative path beginning with ./. Specifies the path to an EFI NVRAM template file to copy and use as the initial EFI variable NVRAM state. If not specified, the default NVRAM template from the firmware definition is copied and used. Configures where to place the EFI variable NVRAM state. This takes an absolute file system path to a regular file to persistently place the state in. If the file is missing it is created as needed. If set to the special string auto a persistent path is automatically derived from the VM image path or directory path, with the .efinvramstate suffix appended. If set to the special string off the EFI variable NVRAM state is only maintained transiently and flushed out when the VM shuts down. Defaults to auto. If is specified, auto behaves like off. Configure whether to search for firmware which supports Secure Boot. Takes a boolean or auto. Setting this to yes is equivalent to and setting this to no is equivalent to . Setting this to auto removes secure-boot from both the included and excluded feature lists. Selects which firmware to use in the VM. Takes one of auto, uefi, bios, none, an absolute path, or a relative path beginning with ./. Defaults to auto, which selects UEFI firmware unless specifies a non-PE kernel image, in which case none is selected. uefi loads OVMF firmware (use a path to a JSON firmware definition file to select a specific one). bios skips OVMF loading and lets QEMU use its built-in BIOS (e.g. SeaBIOS on x86). none disables firmware loading entirely and requires to be specified for direct kernel boot. Booting a UKI requires uefi. If the special string list is specified, all discovered firmware definition files are listed. If the special string describe is specified, the UEFI firmware that would be selected (taking into account) is printed and the program exits. If an empty string is specified, the option is reset to its default. Takes a comma-delimited list of firmware feature strings. This option may be specified multiple times, in which case the feature lists are combined. When specified, only firmware definitions that have all the required features will be considered during automatic firmware discovery. Features prefixed with ~ are excluded: firmware that has such a feature will be skipped. If a feature appears in both the included and excluded lists, inclusion takes priority. By default, firmware with the enrolled-keys feature is excluded. If an empty string is passed, both the included and excluded feature lists are reset. If the special string list is specified, lists all available firmware features. Caveat: This feature is experimental, and is likely to be changed (or removed in its current form) in a future version of systemd. Configures whether to run the guest as a confidential VM. Takes one of no or sev-snp. Defaults to no. sev-snp enables AMD SEV-SNP. This requires KVM on an x86_64 host with SNP-capable hardware and firmware. must point to a raw SNP-built OVMF .fd image; the standard pflash + NVRAM split is not supported under SNP, so the firmware is loaded via QEMU's and Secure Boot is unavailable. SMBIOS credentials passed via or are rejected because they are outside the SNP launch measurement. Direct kernel boot via is required so that the kernel, initrd and command line are hashed into the launch measurement (kernel-hashes=on); booting the kernel off the disk image via the firmware would leave it outside the measurement. A vTPM, if attached via , must be treated as untrusted by the guest. Networking Options Create a TAP device to network with the virtual machine. Note: root privileges are required to use TAP networking. Additionally, systemd-networkd8 must be running and correctly set up on the host to provision the host interface. The relevant .network file can be found at /usr/lib/systemd/network/80-vm-vt.network. Use user mode networking. Execution Options Set the linux kernel image to use for direct kernel boot. If a directory type image is used and was omitted, vmspawn will search for boot loader entries according to the UAPI.1 Boot Loader Specification assuming XBOOTLDR to be located at /boot and ESP to be /efi respectively. If no kernel was installed into the image then the image will fail to boot. Set the initrd to use for direct kernel boot. If the supplied is a UAPI.1 Boot Loader Specification Type #2 entry, then this argument is not required. If no initrd was installed into the image then the image will fail to boot. can be specified multiple times and vmspawn will merge them together. Passes the specified string into the VM as an SMBIOS Type #11 vendor string. This is useful to parameterize the invoked VM in various ways. See smbios-type-117 for details. Configures support for notifications from the VM's init process to systemd-vmspawn. If true, systemd-vmspawn will consider the machine as ready only when it has received a READY=1 message from the init process in the VM. If false, systemd-vmspawn will consider the machine as ready immediately after creation. In either case, systemd-vmspawn sends its own readiness notification to its manager after the spawned VM is ready. For more details about notifications see sd_notify3. Defaults to true. (Note that this is unlike the option of the same name to systemd-nspawn1 that defaults to false.) System Identity Options Sets the machine name for this virtual machine. This name may be used to identify this virtual machine during its runtime (for example in tools like machinectl1 and similar). Set the specified UUID for the virtual machine. The init system will initialize /etc/machine-id from this if this file is not set yet. Note that this option takes effect only if /etc/machine-id in the virtual machine is unpopulated. Property Options Make the VM part of the specified slice, instead of the default machine.slice. This applies only if the machine is run in its own scope unit, i.e. if is not used. Set a unit property on the scope unit to register for the machine. This applies only if the machine is run in its own scope unit, i.e. if is not used. Takes unit property assignments in the same format as systemctl set-property. This is useful to set memory limits and similar for the VM. Controls whether the virtual machine is registered with systemd-machined8. Takes a boolean argument or auto, and defaults to auto. This ensures that the virtual machine is accessible via machinectl1. When set to auto, registration is attempted but failures are ignored. User Namespacing Options Controls user namespacing under . If enabled, virtiofsd1 is instructed to map user and group ids (UIDs and GIDs). This involves mapping the private UIDs/GIDs used in the virtual machine (starting with the virtual machine's root user 0 and up) to a range of UIDs/GIDs on the host that are not used for other purposes (usually in the range beyond the host's UID/GID 65536). If one or two colon-separated numbers are specified, user namespacing is turned on. UID_SHIFT specifies the first host UID/GID to map, UID_RANGE is optional and specifies number of host UIDs/GIDs to assign to the virtual machine. If UID_RANGE is omitted, 65536 UIDs/GIDs are assigned. When user namespaces are used, the GID range assigned to each virtual machine is always chosen identical to the UID range. Mount Options Mount a directory from the host into the virtual machine. Takes one of: a path argument — in which case the specified path will be mounted from the host to the same path in the virtual machine, or a colon-separated pair of paths — in which case the first specified path is the source in the host, and the second path is the destination in the virtual machine. If the source path is not absolute, it is resolved relative to the current working directory. The option creates read-only bind mounts. Backslash escapes are interpreted, so \: may be used to embed colons in either path. This option may be specified multiple times for creating multiple independent bind mount points. Takes a disk image or block device on the host and supplies it to the virtual machine as another drive. Optionally, the image format and/or disk type can be specified by prefixing the path with their values separated by colons. The format and disk type prefixes can appear in any order. The format defaults to raw and the disk type defaults to the value of (which itself defaults to virtio-blk). Note that qcow2 is only supported for regular files, not block devices. Acquire a storage volume from a storagectl1 provider and attach it to the virtual machine. PROVIDER is the provider name (typically block or fs). VOLUME is the volume name passed to the provider's Acquire() method. CONFIG selects the guest device type and takes one of virtio-blk, virtio-scsi, nvme, or scsi-cd. If empty or omitted, defaults to virtio-blk. The trailing comma-separated K=V list passes parameters to io.systemd.StorageProvider.Acquire(): template=, create= (one of any, new, open), read-only= (or ro=; takes a boolean or auto), size= / create-size= (size for created volumes), request-as= (one of blk, reg, dir; dir is rejected by vmspawn). Each attached volume is identified by the name PROVIDER:VOLUME. Volumes attached at startup via this option cannot be detached at runtime via machinectl unbind-volume; only volumes added at runtime via machinectl bind-volume are removable. The provider is looked up under /run/systemd/io.systemd.StorageProvider/ for system mode (or $XDG_RUNTIME_DIR/systemd/io.systemd.StorageProvider/ for user mode), matching the runtime scope chosen via / . Binds the home directory of the specified user on the host into the virtual machine. Takes the name of an existing user on the host as argument. May be used multiple times to bind multiple users into the virtual machine. This does two things: The user's home directory is made available from the host into /run/vmhost/home/ using virtiofs. virtiofsd id translation to map the host user's UID/GID to its assigned UID/GID in the virtual machine. JSON user and group records are generated in that describes the mapped user which are passed into the virtual machine using userdb.transient.* credentials. They contain a minimized representation of the host's user record, adjusted to the UID/GID and home directory path assigned to the user in the virtual machine. The nss-systemd8 glibc NSS module will pick up these records from there and make them available in the virtual machine's user/group databases. The combination of the two operations above ensures that it is possible to log into the virtual machine using the same account information as on the host. The user is only mapped transiently, while the virtual machine is running, and the mapping itself does not result in persistent changes to the virtual machine (except maybe for log messages generated at login time, and similar). Note that in particular the UID/GID assignment in the virtual machine is not made persistently. If the user is mapped transiently, it is best to not allow the user to make persistent changes to the virtual machine. If the user leaves files or directories owned by the user, and those UIDs/GIDs are reused during later virtual machine invocations (possibly with a different mapping), those files and directories will be accessible to the "new" user. The user/group record mapping only works if the virtual machine contains systemd 258 or newer, with nss-systemd properly configured in nsswitch.conf. See nss-systemd8 for details. Note that the user record propagated from the host into the virtual machine will contain the UNIX password hash of the user, so that seamless logins in the virtual machine are possible. If the virtual machine is less trusted than the host it is hence important to use a strong UNIX password hash function (e.g. yescrypt or similar, with the $y$ hash prefix). When used with , includes the specified shell in the user records of users bound into the virtual machine. Takes either a boolean or an absolute path. If false (the default), no shell is passed in the user records for users bound into the virtual machine. This causes bound users to the use the virtual machine's default shell. If true, the shells specified by the host user records are included in the user records of all users bound into the virtual machine. If passed an absolute path, sets that path as the shell for user records of all users bound into the virtual machine. Note: This will not check whether the specified shells exist in the virtual machine. This operation is only supported in combination with . When used with , includes the specified group as an auxiliary group in the user records of users bound into the virtual machine. Takes a group name. Note: This will not check whether the specified groups exist in the virtual machine. This operation is only supported in combination with . Logging Options Forward the virtual machine's journal to the host. systemd-journal-remote8 is currently used to receive the guest VM's forwarded journal entries. This option determines where this journal is saved on the host and has the same semantics as / described in systemd-journal-remote8. These options configure the corresponding settings of systemd-journal-remote8 when forwarding journal entries from the VM. See journal-remote.conf5 for the descriptions of these settings. SSH Options By default, an SSH key is generated to allow systemd-vmspawn to open a D-Bus connection to the VM's systemd bus. Setting this to "no" will disable SSH key generation. The generated keys are ephemeral. That is they are valid only for the current invocation of systemd-vmspawn, and are typically not persisted. Configures the type of SSH key to generate, see ssh-keygen1 for more information. By default, ed25519 keys are generated, however rsa keys may also be useful if the VM has a particularly old version of sshd8. Input/Output Options Configures how to set up the console of the VM. Takes one of interactive, read-only, native, gui, 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 native implementation (which means the qemu monitor is available). gui shows the qemu graphical UI. headless runs the VM without any console, which is useful for automated or scripted usage. Configures the transport to use for the VM console. Takes one of virtio or serial. Defaults to virtio. virtio uses a virtio-serial device, which appears as /dev/hvc0 in the VM. serial uses a regular serial port, which appears as /dev/ttyS0 (or /dev/ttyAMA0 on ARM) in the VM. This option only has an effect in , , and modes. Change the terminal background color to the specified ANSI color as long as the VM runs. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such as 40, 41, …, 47, 48;2;…, 48;5;…. See ANSI Escape Code (Wikipedia) for details. Assign an empty string to disable any coloring. This only has an effect in and modes. Credentials Pass a credential to the virtual machine. These two options correspond to the LoadCredential= and SetCredential= settings in unit files. See systemd.exec5 for details about these concepts, as well as the syntax of the option's arguments. In order to embed binary data into the credential data for , use C-style escaping (i.e. \n to embed a newline, or \x00 to embed a NUL byte). Note that the invoking shell might already apply unescaping once, hence this might require double escaping! Credentials are preferably passed to the VM via SMBIOS Type 11 strings or QEMU fw_cfg files. If neither mechanism is available, credentials are passed on the kernel command line using systemd.set_credential_binary= which is not a confidential channel. Do not use this for passing secrets to the VM in that case. Other Examples Run an Arch Linux VM image generated by mkosi $ mkosi -d arch -p systemd -p linux --autologin -o image.raw -f build $ systemd-vmspawn --image=image.raw Import and run a Fedora &fedora_latest_version; Cloud image using importctl $ curl -L \ -O https://download.fedoraproject.org/pub/fedora/linux/releases/&fedora_latest_version;/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-&fedora_latest_version;-&fedora_cloud_release;.x86_64.qcow2 \ -O https://download.fedoraproject.org/pub/fedora/linux/releases/&fedora_latest_version;/Cloud/x86_64/images/Fedora-Cloud-&fedora_latest_version;-&fedora_cloud_release;-x86_64-CHECKSUM \ -O https://fedoraproject.org/fedora.gpg $ gpgv --keyring ./fedora.gpg Fedora-Cloud-&fedora_latest_version;-&fedora_cloud_release;-x86_64-CHECKSUM $ sha256sum -c Fedora-Cloud-&fedora_latest_version;-&fedora_cloud_release;-x86_64-CHECKSUM # importctl import-raw -m Fedora-Cloud-Base-Generic-&fedora_latest_version;-&fedora_cloud_release;.x86_64.qcow2 fedora-&fedora_latest_version;-cloud # systemd-vmspawn -M fedora-&fedora_latest_version;-cloud Build and run systemd's system image and forward the VM's journal to a local file $ mkosi build $ systemd-vmspawn \ -D mkosi.output/system \ --private-users $(grep $(whoami) /etc/subuid | cut -d: -f2) \ --linux mkosi.output/system.efi \ --forward-journal=vm.journal \ enforcing=0 Note: this example also uses a kernel command line argument to ensure SELinux is not started in enforcing mode. SSH into a running VM using <command>systemd-ssh-proxy</command> $ mkosi build $ my_vsock_cid=3735928559 $ systemd-vmspawn \ -D mkosi.output/system \ --private-users $(grep $(whoami) /etc/subuid | cut -d: -f2) \ --linux mkosi.output/system.efi \ --vsock-cid $my_vsock_cid \ enforcing=0 $ ssh root@vsock/$my_vsock_cid -i /run/user/$UID/systemd/vmspawn/machine-*-system-ed25519 Exit status If an error occurred the value errno is propagated to the return code. If EXIT_STATUS is supplied by the running image that is returned. Otherwise, EXIT_SUCCESS is returned. See Also systemd1 mkosi1 machinectl1 importctl1 UAPI.1 Boot Loader Specification