2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id=
"systemd-vmspawn" conditional=
"ENABLE_VMSPAWN"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
10 <title>systemd-vmspawn
</title>
11 <productname>systemd
</productname>
15 <refentrytitle>systemd-vmspawn
</refentrytitle>
16 <manvolnum>1</manvolnum>
20 <refname>systemd-vmspawn
</refname>
21 <refpurpose>Spawn an OS in a virtual machine
</refpurpose>
26 <command>systemd-vmspawn
</command>
27 <arg choice=
"opt" rep=
"repeat">OPTIONS
</arg>
28 <arg choice=
"opt" rep=
"repeat">ARGS
</arg>
33 <title>Description
</title>
34 <para><command>systemd-vmspawn
</command> may be used to start a virtual machine from an OS image. In many ways it is similar to
<citerefentry>
35 <refentrytitle>systemd-nspawn
</refentrytitle><manvolnum>1</manvolnum></citerefentry>, but
36 launches a full virtual machine instead of using namespaces.
</para>
38 <para>File descriptors for
<filename>/dev/kvm
</filename> and
<filename>/dev/vhost-vsock
</filename> can be
39 passed to
<command>systemd-vmspawn
</command> via systemd's native socket passing interface (see
40 <citerefentry><refentrytitle>sd_listen_fds
</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
41 details about the precise protocol used and the order in which the file descriptors are passed), these
42 file descriptors must be passed with the names
<literal>kvm
</literal> and
<literal>vhost-vsock
</literal>
45 <para>Note: on Ubuntu/Debian derivatives systemd-vmspawn requires the user to be in the
46 <literal>kvm
</literal> group to use the VSOCK options.
</para>
50 <title>Options
</title>
52 <para>The excess arguments are passed as extra kernel command line arguments using SMBIOS.
</para>
54 <para>The following options are understood:
</para>
59 <term><option>-q
</option></term>
60 <term><option>--quiet
</option></term>
62 <listitem><para>Turns off any status output by the tool
63 itself. When this switch is used, the only output from vmspawn
64 will be the console output of the Virtual Machine OS itself.
</para>
66 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
72 <title>Image Options
</title>
75 <term><option>-D
</option></term>
76 <term><option>--directory=
</option></term>
78 <listitem><para>Directory to use as file system root for the virtual machine.
</para>
80 <para>One of either
<option>--directory=
</option> or
<option>--image=
</option> must be specified.
</para>
82 <para>Note: If mounting a non-root owned directory you may require
<option>--private-users=
</option>
83 to map into the user's subuid namespace.
</para>
85 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
91 <term><option>-i
</option></term>
92 <term><option>--image=
</option></term>
94 <listitem><para>Root file system disk image (or device node) for the virtual machine.
</para>
96 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
103 <title>Host Configuration
</title>
107 <term><option>--cpus=
<replaceable>CPUS
</replaceable></option></term>
109 <listitem><para>Configures the number of CPUs to start the virtual machine with.
110 Defaults to
1.
</para>
112 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
117 <term><option>--ram=
<replaceable>BYTES
</replaceable></option></term>
119 <listitem><para>Configures the amount of memory to start the virtual machine with.
120 Defaults to
2G.
</para>
122 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
127 <term><option>--kvm=
<replaceable>BOOL
</replaceable></option></term>
129 <listitem><para>Configures whether to use KVM. If the option is not specified KVM support will be
130 detected automatically. If true, KVM is always used, and if false, KVM is never used.
</para>
132 <xi:include href=
"version-info.xml" xpointer=
"v255"/></listitem>
136 <term><option>--vsock=
<replaceable>BOOL
</replaceable></option></term>
139 <para>Configure whether to use VSOCK networking.
</para>
141 <para>If the option is not specified VSOCK support will be detected automatically. If yes is
142 specified VSOCK is always used, and vice versa if no is set VSOCK are never used.
</para>
143 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
148 <term><option>--vsock-cid=
<replaceable>CID
</replaceable></option></term>
151 <para>Configure vmspawn to use a specific CID for the guest.
</para>
153 <para>If the option is not specified or an empty argument is supplied the guest will be assigned a random CID.
</para>
155 <para>Valid CIDs are in the range
<constant>3</constant> to
<constant>4294967294</constant> (
<constant>0xFFFF_FFFE
</constant>).
156 CIDs outside of this range are reserved.
</para>
158 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
163 <term><option>--tpm=
<replaceable>BOOL
</replaceable></option></term>
166 <para>Configure whether to use VM with a virtual TPM or not.
</para>
168 <para>If the option is not specified vmspawn will detect the presence of
<citerefentry project='debian'
>
169 <refentrytitle>swtpm
</refentrytitle><manvolnum>8</manvolnum></citerefentry> and use it if available.
170 If yes is specified
<citerefentry project='debian'
><refentrytitle>swtpm
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
171 is always used, and vice versa if no is set
<citerefentry project='debian'
><refentrytitle>swtpm
</refentrytitle>
172 <manvolnum>8</manvolnum></citerefentry> is never used.
</para>
174 <para>Note: the virtual TPM used may change in future.
</para>
176 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
181 <term><option>--linux=
<replaceable>PATH
</replaceable></option></term>
184 <para>Set the linux kernel image to use for direct kernel boot.
</para>
186 <para>If no kernel was installed into the image then the image will fail to boot.
</para>
188 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
193 <term><option>--initrd=
<replaceable>PATH
</replaceable></option></term>
196 <para>Set the initrd to use for direct kernel boot.
</para>
198 <para>If the linux kernel supplied is a UKI then this argument is not required.
</para>
200 <para>If the option is specified multiple times vmspawn will merge the initrds together.
</para>
202 <para>If no initrd was installed into the image then the image will fail to boot.
</para>
204 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
209 <term><option>-n
</option></term>
210 <term><option>--network-tap
</option></term>
213 <para>Create a TAP device to network with the virtual machine.
</para>
215 <para>Note: root privileges are required to use TAP networking.
217 <citerefentry><refentrytitle>systemd-networkd
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
218 must be running and correctly set up on the host to provision the host interface. The relevant
219 <literal>.network
</literal> file can be found at
220 <filename>/usr/lib/systemd/network/
80-vm-vt.network
</filename>.
223 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
228 <term><option>--network-user-mode
</option></term>
230 <listitem><para>Use user mode networking.
</para>
232 <xi:include href=
"version-info.xml" xpointer=
"v255"/></listitem>
236 <term><option>--firmware=
<replaceable>PATH
</replaceable></option></term>
238 <listitem><para>Takes an absolute path, or a relative path beginning with
239 <filename>./
</filename>. Specifies a JSON firmware definition file, which allows selecting the
240 firmware to boot in the VM. If not specified a suitable firmware is automatically discovered. If the
241 special string
<literal>list
</literal> is specified lists all discovered firmwares.
</para>
243 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
247 <term><option>--discard-disk=
<replaceable>BOOL
</replaceable></option></term>
249 <listitem><para>Controls whether qemu processes discard requests from the VM.
250 This prevents long running VMs from using more disk space than required.
251 This is enabled by default.
</para>
253 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
257 <term><option>--secure-boot=
<replaceable>BOOL
</replaceable></option></term>
259 <listitem><para>Configure whether to search for firmware which supports Secure Boot.
</para>
261 <para>If the option is not specified the first firmware which is detected will be used.
262 If the option is set to yes then the first firmware with Secure Boot support will be selected.
263 If no is specified then the first firmware without Secure Boot will be selected.
</para>
265 <xi:include href=
"version-info.xml" xpointer=
"v255"/></listitem>
271 <title>System Identity Options
</title>
275 <term><option>-M
</option></term>
276 <term><option>--machine=
</option></term>
278 <listitem><para>Sets the machine name for this virtual machine. This
279 name may be used to identify this virtual machine during its runtime
280 (for example in tools like
281 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
284 <xi:include href=
"version-info.xml" xpointer=
"v255"/>
289 <term><option>--uuid=
</option></term>
291 <listitem><para>Set the specified UUID for the virtual machine. The
292 init system will initialize
293 <filename>/etc/machine-id
</filename> from this if this file is
294 not set yet. Note that this option takes effect only if
295 <filename>/etc/machine-id
</filename> in the virtual machine is
298 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
304 <title>Property Options
</title>
308 <term><option>--register=
</option></term>
310 <listitem><para>Controls whether the virtual machine is registered with
311 <citerefentry><refentrytitle>systemd-machined
</refentrytitle><manvolnum>8</manvolnum></citerefentry>. Takes a
312 boolean argument, which defaults to
<literal>yes
</literal> when running as root, and
<literal>no
</literal> when
313 running as a regular user. This ensures that the virtual machine is accessible via
314 <citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
</para>
316 <para>Note: root privileges are required to use this option as registering with
317 <citerefentry><refentrytitle>systemd-machined
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
318 requires privileged D-Bus method calls.
</para>
320 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
326 <title>User Namespacing Options
</title>
330 <term><option>--private-users=
<replaceable>UID_SHIFT[:UID_RANGE]
</replaceable></option></term>
332 <listitem><para>Controls user namespacing under
<option>--directory=
</option>.
333 If enabled,
<command>virtiofsd
</command> is instructed to map user and group ids (UIDs and GIDs).
334 This involves mapping the private UIDs/GIDs used in the virtual machine (starting with the virtual machine's
335 root user
0 and up) to a range of UIDs/GIDs on the host that are not used for other purposes (usually in the
336 range beyond the host's UID/GID
65536).
</para>
338 <para>If one or two colon-separated numbers are specified, user namespacing is turned on.
<replaceable>UID_SHIFT
</replaceable>
339 specifies the first host UID/GID to map,
<replaceable>UID_RANGE
</replaceable> is optional and specifies number of host
340 UIDs/GIDs to assign to the virtual machine. If
<replaceable>UID_RANGE
</replaceable> is omitted,
65536 UIDs/GIDs are assigned.
</para>
342 <para>When user namespaces are used, the GID range assigned to each virtual machine is always chosen identical to the
345 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
351 <title>Mount Options
</title>
356 <term><option>--bind=
<replaceable>PATH
</replaceable></option></term>
357 <term><option>--bind-ro=
<replaceable>PATH
</replaceable></option></term>
359 <listitem><para>Mount a directory from the host into the virtual machine. Takes one of: a path
360 argument — in which case the specified path will be mounted from the host to the same path in the virtual machine, or
361 a colon-separated pair of paths — in which case the first specified path is the source in the host, and the
362 second path is the destination in the virtual machine. If the source path is not absolute, it is resolved
363 relative to the current working directory. The
<option>--bind-ro=
</option> option creates read-only bind mounts.
364 Backslash escapes are interpreted, so
<literal>\:
</literal> may be used to embed colons in either path.
365 This option may be specified multiple times for creating multiple independent bind mount points.
</para>
367 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
371 <term><option>--extra-drive=
<replaceable>PATH
</replaceable></option></term>
373 <listitem><para>Takes a disk image or block device on the host and supplies it to the virtual machine as another drive.
</para>
375 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
382 <title>Integration Options
</title>
386 <term><option>--forward-journal=
<replaceable>FILE|DIR
</replaceable></option></term>
388 <listitem><para>Forward the virtual machine's journal to the host.
389 <citerefentry><refentrytitle>systemd-journal-remote
</refentrytitle><manvolnum>8</manvolnum></citerefentry>
390 is currently used to receive the guest VM's forwarded journal entries. This option determines where
391 this journal is saved on the host and has the same semantics as
392 <option>-o
</option>/
<option>--output
</option> described in
393 <citerefentry><refentrytitle>systemd-journal-remote
</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
</para>
395 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
400 <term><option>--pass-ssh-key=
<replaceable>BOOL
</replaceable></option></term>
402 <listitem><para>By default an SSH key is generated to allow
<command>systemd-vmspawn
</command> to open
403 a D-Bus connection to the VM's systemd bus. Setting this to
"no" will disable SSH key generation.
</para>
405 <para>The generated keys are ephemeral. That is they are valid only for the current invocation of
<command>systemd-vmspawn
</command>,
406 and are typically not persisted.
</para>
408 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
413 <term><option>--ssh-key-type=
<replaceable>TYPE
</replaceable></option></term>
415 <listitem><para>Configures the type of SSH key to generate, see
416 <citerefentry project=
"man-pages"><refentrytitle>ssh-keygen
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
417 for more information.
</para>
419 <para>By default
<literal>ed25519
</literal> keys are generated, however
<literal>rsa
</literal> keys
420 may also be useful if the VM has a particularly old version of
<command>sshd
</command></para>.
422 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
429 <title>Input/Output Options
</title>
433 <term><option>--console=
<replaceable>MODE
</replaceable></option></term>
435 <listitem><para>Configures how to set up the console of the VM. Takes one of
436 <literal>interactive
</literal>,
<literal>read-only
</literal>,
<literal>native
</literal>,
437 <literal>gui
</literal>. Defaults to
<literal>interactive
</literal>.
<literal>interactive
</literal>
438 provides an interactive terminal interface to the VM.
<literal>read-only
</literal> is similar, but
439 is strictly read-only, i.e. does not accept any input from the user.
<literal>native
</literal> also
440 provides a TTY-based interface, but uses qemu native implementation (which means the qemu monitor
441 is available).
<literal>gui
</literal> shows the qemu graphical UI.
</para>
443 <xi:include href=
"version-info.xml" xpointer=
"v256"/></listitem>
447 <term><option>--background=
<replaceable>COLOR
</replaceable></option></term>
449 <listitem><para>Change the terminal background color to the specified ANSI color as long as the VM
450 runs. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such as
451 <literal>40</literal>,
<literal>41</literal>, …,
<literal>47</literal>,
<literal>48;
2;…
</literal>,
452 <literal>48;
5;…
</literal>. See
<ulink
453 url=
"https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">ANSI
454 Escape Code (Wikipedia)
</ulink> for details. Assign an empty string to disable any coloring. This
455 only has an effect in
<option>--console=interactive
</option> and
456 <option>--console=read-only
</option> modes.
</para>
458 <xi:include href=
"version-info.xml" xpointer=
"v256"/>
465 <title>Credentials
</title>
469 <term><option>--load-credential=
<replaceable>ID
</replaceable>:
<replaceable>PATH
</replaceable></option></term>
470 <term><option>--set-credential=
<replaceable>ID
</replaceable>:
<replaceable>VALUE
</replaceable></option></term>
472 <listitem><para>Pass a credential to the virtual machine. These two options correspond to the
473 <varname>LoadCredential=
</varname> and
<varname>SetCredential=
</varname> settings in unit files. See
474 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
475 details about these concepts, as well as the syntax of the option's arguments.
</para>
477 <para>In order to embed binary data into the credential data for
<option>--set-credential=
</option>,
478 use C-style escaping (i.e.
<literal>\n
</literal> to embed a newline, or
<literal>\x00
</literal> to
479 embed a
<constant>NUL
</constant> byte). Note that the invoking shell might already apply unescaping
480 once, hence this might require double escaping!
</para>
482 <xi:include href=
"version-info.xml" xpointer=
"v255"/></listitem>
486 </refsect2><refsect2>
490 <xi:include href=
"standard-options.xml" xpointer=
"no-pager" />
491 <xi:include href=
"standard-options.xml" xpointer=
"help" />
492 <xi:include href=
"standard-options.xml" xpointer=
"version" />
497 <xi:include href=
"common-variables.xml" />
500 <title>Examples
</title>
503 <title>Run an Arch Linux VM image generated by mkosi
</title>
506 $ mkosi -d arch -p systemd -p linux --autologin -o image.raw -f build
507 $ systemd-vmspawn --image=image.raw
513 <title>Exit status
</title>
515 <para>If an error occurred the value errno is propagated to the return code.
516 If EXIT_STATUS is supplied by the running image that is returned.
517 Otherwise EXIT_SUCCESS is returned.
</para>
521 <title>See Also
</title>
522 <para><simplelist type=
"inline">
523 <member><citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
524 <member><citerefentry project='debian'
><refentrytitle>mkosi
</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
525 <member><citerefentry><refentrytitle>machinectl
</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
526 <member><citerefentry><refentrytitle>importctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>