%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. 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. Root file system disk image (or device node) for the virtual machine. 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 is not specified KVM support will be detected automatically. If true, KVM is always used, and if false, KVM is never used. If is not specified VSOCK networking support will be detected automatically. If true, VSOCK networking is always used, and if false, VSOCK networking is never used. 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. If is not specified vmspawn will detect the presence of swtpm8 and use it if available. If yes is specified swtpm8 is always used, and if no is set swtpm 8 is never used. Note: the virtual TPM used may change in future. 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 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 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. 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. Takes an absolute path, or a relative path beginning with ./. Specifies a JSON firmware definition file, which allows selecting the firmware to boot in the VM. If not specified a suitable firmware is automatically discovered. If the special string list is specified lists all discovered firmwares. 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. Configure whether to search for firmware which supports Secure Boot. If the option is not specified the first firmware which is detected will be used. If the option is set to yes then the first firmware with Secure Boot support will be selected. If no is specified then the first firmware without Secure Boot will be selected. 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 Controls whether the virtual machine is registered with systemd-machined8. Takes a boolean argument, which defaults to yes when running as root, and no when running as a regular user. This ensures that the virtual machine is accessible via machinectl1. Note: root privileges are required to use this option as registering with systemd-machined8 requires privileged D-Bus method calls. 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. Integration 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. 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 sshd. Input/Output Options Configures how to set up the console of the VM. Takes one of interactive, read-only, native, 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 native implementation (which means the qemu monitor is available). gui shows the qemu graphical UI. 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! 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 39 Cloud image using machinectl $ curl -L \ -O https://download.fedoraproject.org/pub/fedora/linux/releases/&fedora_latest_version;/Cloud/x86_64/images/Fedora-Cloud-Base-&fedora_latest_version;-&fedora_cloud_release;.x86_64.raw.xz \ -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 # machinectl import-raw Fedora-Cloud-Base-&fedora_latest_version;-&fedora_cloud_release;.x86_64.raw.xz 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 isn't 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 Boot Loader Specification