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(8).
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, $PAGER
Note: if $SYSTEMD_PAGERSECURE is not set, $SYSTEMD_PAGER and $PAGER can only be used to disable the pager (with "cat" or ""), and are otherwise 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
This option takes a boolean argument. When set to true, the "secure mode" of the pager is enabled. In "secure mode", LESSSECURE=1 will be set when invoking the pager, which instructs the pager to disable commands that open or create new files or start new subprocesses. Currently only less(1) is known to understand this variable and implement "secure mode".
When set to false, no limitation is placed on the pager. Setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited environment may allow the user to invoke arbitrary commands.
When $SYSTEMD_PAGERSECURE is not set, systemd tools attempt to automatically figure out if "secure mode" should be enabled and whether the pager supports it. "Secure mode" is enabled if the effective UID is not the same as the owner of the login session, see geteuid(2) and sd_pid_get_owner_uid(3), or when running under sudo(8) or similar tools ($SUDO_UID is set [3]). In those cases, SYSTEMD_PAGERSECURE=1 will be set and pagers which are not known to implement "secure mode" will not be used at all. Note that this autodetection only covers the most common mechanisms to elevate privileges and is intended as convenience. It is recommended to explicitly set $SYSTEMD_PAGERSECURE or disable the pager.
Note that if the $SYSTEMD_PAGER or $PAGER variables are to be honoured, other than to disable the pager, $SYSTEMD_PAGERSECURE must be set too.
$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 42 Cloud image using machinectl
$ curl -L \ -O https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-42-1.1.x86_64.raw.xz \ -O https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-42-1.1-x86_64-CHECKSUM \ -O https://fedoraproject.org/fedora.gpg $ gpgv --keyring ./fedora.gpg Fedora-Cloud-42-1.1-x86_64-CHECKSUM $ sha256sum -c Fedora-Cloud-42-1.1-x86_64-CHECKSUM # machinectl import-raw Fedora-Cloud-Base-42-1.1.x86_64.raw.xz fedora-42-cloud # systemd-vmspawn -M fedora-42-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 is not 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)
- 3.
- It is recommended for other tools to set and check $SUDO_UID as appropriate, treating it is a common interface.
systemd 257.7 |