table of contents
SYSTEMD-VMSPAWN(1) | systemd-vmspawn | SYSTEMD-VMSPAWN(1) |
NAME¶
systemd-vmspawn - Spawn an OS in a virtual machine
SYNOPSIS¶
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-nspawn(1), 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_fds(3) 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:
-q, --quiet
Added in version 256.
Image Options¶
-D, --directory=
One of either --directory= or --image= must be specified. If neither are specified --directory=. is assumed.
Note: If mounting a non-root owned directory you may require --private-users= to map into the user's subuid namespace. An example of how to use /etc/subuid for this is given later.
Added in version 256.
-i, --image=
Added in version 255.
Host Configuration¶
--cpus=CPUS
Added in version 255.
--ram=BYTES
Added in version 255.
--kvm=BOOL
Added in version 255.
--vsock=BOOL
Added in version 255.
--vsock-cid=CID
Added in version 255.
--tpm=BOOL
Note: the virtual TPM used may change in future.
Added in version 256.
--linux=PATH
Added in version 256.
--initrd=PATH
--initrd= can be specified multiple times and vmspawn will merge them together.
Added in version 256.
-n, --network-tap
Note: root privileges are required to use TAP networking. Additionally, systemd-networkd(8) 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.
Added in version 255.
--network-user-mode
Added in version 255.
--firmware=PATH
Added in version 256.
--discard-disk=BOOL
Added in version 256.
--secure-boot=BOOL
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.
Added in version 255.
System Identity Options¶
-M, --machine=
Added in version 255.
--uuid=
Added in version 256.
Property Options¶
--register=
Note: root privileges are required to use this option as registering with systemd-machined(8) requires privileged D-Bus method calls.
Added in version 256.
User Namespacing Options¶
--private-users=UID_SHIFT[:UID_RANGE]
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.
Added in version 256.
Mount Options¶
--bind=PATH, --bind-ro=PATH
Added in version 256.
--extra-drive=PATH
Added in version 256.
Integration Options¶
--forward-journal=FILE|DIR
Added in version 256.
--pass-ssh-key=BOOL
The generated keys are ephemeral. That is they are valid only for the current invocation of systemd-vmspawn, and are typically not persisted.
Added in version 256.
--ssh-key-type=TYPE
By default "ed25519" keys are generated, however "rsa" keys may also be useful if the VM has a particularly old version of sshd.
Added in version 256.
Input/Output Options¶
--console=MODE
Added in version 256.
--background=COLOR
Added in version 256.
Credentials¶
--load-credential=ID:PATH, --set-credential=ID:VALUE
In order to embed binary data into the credential data for --set-credential=, 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!
Added in version 255.
Other¶
--no-pager
-h, --help
--version
ENVIRONMENT¶
$SYSTEMD_LOG_LEVEL
$SYSTEMD_LOG_COLOR
This setting is only useful when messages are written directly to the terminal, because journalctl(1) and other tools that display logs will color messages based on the log level on their own.
$SYSTEMD_LOG_TIME
This setting is only useful when messages are written directly to the terminal or a file, because journalctl(1) and other tools that display logs will attach timestamps based on the entry metadata on their own.
$SYSTEMD_LOG_LOCATION
Note that the log location is often attached as metadata to journal entries anyway. Including it directly in the message text can nevertheless be convenient when debugging programs.
$SYSTEMD_LOG_TID
Note that the this information is attached as metadata to journal entries anyway. Including it directly in the message text can nevertheless be convenient when debugging programs.
$SYSTEMD_LOG_TARGET
$SYSTEMD_LOG_RATELIMIT_KMSG
$SYSTEMD_PAGER
Note: if $SYSTEMD_PAGERSECURE is not set, $SYSTEMD_PAGER (as well as $PAGER) will be silently ignored.
$SYSTEMD_LESS
Users might want to change two options in particular:
K
If the value of $SYSTEMD_LESS does not include "K", and the pager that is invoked is less, Ctrl+C will be ignored by the executable, and needs to be handled by the pager.
X
Note that setting the regular $LESS environment variable has no effect for less invocations by systemd tools.
See less(1) for more discussion.
$SYSTEMD_LESSCHARSET
Note that setting the regular $LESSCHARSET environment variable has no effect for less invocations by systemd tools.
$SYSTEMD_PAGERSECURE
Note: when commands are invoked with elevated privileges, for example under sudo(8) or pkexec(1), care must be taken to ensure that unintended interactive features are not enabled. "Secure" mode for the pager may be enabled automatically as describe above. Setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited environment allows the user to invoke arbitrary commands. Note that if the $SYSTEMD_PAGER or $PAGER variables are to be honoured, $SYSTEMD_PAGERSECURE must be set too. It might be reasonable to completely disable the pager using --no-pager instead.
$SYSTEMD_COLORS
$SYSTEMD_URLIFY
EXAMPLES¶
Example 1. 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
Example 2. Import and run a Fedora 39 Cloud image using machinectl
$ curl -L \
-O https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-40-1.10.x86_64.raw.xz \
-O https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-40-1.10-x86_64-CHECKSUM \
-O https://fedoraproject.org/fedora.gpg $ gpgv --keyring ./fedora.gpg Fedora-Cloud-40-1.10-x86_64-CHECKSUM $ sha256sum -c Fedora-Cloud-40-1.10-x86_64-CHECKSUM # machinectl import-raw Fedora-Cloud-Base-40-1.10.x86_64.raw.xz fedora-40-cloud # systemd-vmspawn -M fedora-40-cloud
Example 3. 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.
Example 4. SSH into a running VM using systemd-ssh-proxy
$ 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¶
systemd(1), mkosi(1), machinectl(1), importctl(1), Boot Loader Specification[1]
NOTES¶
- 1.
- Boot Loader Specification
- 2.
- ANSI Escape Code (Wikipedia)
systemd 256.7 |