Debian Codegraph @

man/systemd-vmspawn.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % entities SYSTEM "custom-entities.ent" >
5 %entities;
6 ]>
7 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
8
9 <refentry id="systemd-vmspawn" conditional="ENABLE_VMSPAWN"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>systemd-vmspawn</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>systemd-vmspawn</refentrytitle>
19 <manvolnum>1</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>systemd-vmspawn</refname>
24 <refpurpose>Spawn an OS in a virtual machine</refpurpose>
25 </refnamediv>
26
27 <refsynopsisdiv>
28 <cmdsynopsis>
29 <command>systemd-vmspawn</command>
30 <arg choice="opt" rep="repeat">OPTIONS</arg>
31 <arg choice="opt" rep="repeat">ARGS</arg>
32 </cmdsynopsis>
33 </refsynopsisdiv>
34
35 <refsect1>
36 <title>Description</title>
37 <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>
38 <refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>, but
39 launches a full virtual machine instead of using namespaces.</para>
40
41 <para>File descriptors for <filename>/dev/kvm</filename> and <filename>/dev/vhost-vsock</filename> can be
42 passed to <command>systemd-vmspawn</command> via systemd's native socket passing interface (see
43 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
44 details about the precise protocol used and the order in which the file descriptors are passed), these
45 file descriptors must be passed with the names <literal>kvm</literal> and <literal>vhost-vsock</literal>
46 respectively.</para>
47
48 <para>Note: on Ubuntu/Debian derivatives <command>systemd-vmspawn</command> requires the user to be in the
49 <literal>kvm</literal> group to use the VSOCK options.</para>
50 </refsect1>
51
52 <refsect1>
53 <title>Options</title>
54
55 <para>The excess arguments are passed as extra kernel command line arguments using SMBIOS.</para>
56
57 <para>The following options are understood:</para>
58
59 <variablelist>
60
61 <varlistentry>
62 <term><option>-q</option></term>
63 <term><option>--quiet</option></term>
64
65 <listitem><para>Turns off any status output by the tool
66 itself. When this switch is used, the only output from vmspawn
67 will be the console output of the Virtual Machine OS itself.</para>
68
69 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
70 </varlistentry>
71
72 <varlistentry>
73 <term><option>--system</option></term>
74 <term><option>--user</option></term>
75
76 <listitem><para>Specify whether to interact with the user manager or the system manager and whether
77 to register with the user machined instance or the system machined instance. If
78 unspecified, the system manager and machined instance will be used when running as root, otherwise
79 the user manager and machined instance will be used.</para>
80
81 <xi:include href="version-info.xml" xpointer="v260"/></listitem>
82 </varlistentry>
83
84 </variablelist>
85
86 <refsect2>
87 <title>Image Options</title>
88
89 <variablelist>
90 <varlistentry>
91 <term><option>-D</option></term>
92 <term><option>--directory=</option></term>
93
94 <listitem><para>Directory to use as file system root for the virtual machine.</para>
95
96 <para>One of either <option>--directory=</option> or <option>--image=</option> must be specified.
97 If neither are specified <option>--directory=.</option> is assumed.</para>
98
99 <para>Note: If mounting a non-root owned directory you may require <option>--private-users=</option>
100 to map into the user's subuid namespace. An example of how to use <constant>/etc/subuid</constant>
101 for this is given later.</para>
102
103 <xi:include href="version-info.xml" xpointer="v256"/>
104 </listitem>
105 </varlistentry>
106
107 <varlistentry>
108 <term><option>-x</option></term>
109 <term><option>--ephemeral</option></term>
110
111 <listitem><para>If specified, the VM is run with a temporary snapshot of its file system that is removed
112 immediately when the VM terminates. Only works with <option>--image=</option> currently.
113
114 Note that <option>--ephemeral</option> will not work with <option>--extra-drive=</option>.</para>
115
116 <xi:include href="version-info.xml" xpointer="v260"/></listitem>
117 </varlistentry>
118
119 <varlistentry>
120 <term><option>-i</option></term>
121 <term><option>--image=</option></term>
122
123 <listitem><para>Root file system disk image (or device node) for the virtual machine.</para>
124
125 <xi:include href="version-info.xml" xpointer="v255"/>
126 </listitem>
127 </varlistentry>
128
129 <varlistentry>
130 <term><option>--image-format=<replaceable>FORMAT</replaceable></option></term>
131
132 <listitem><para>Specifies the format of the disk image passed to <option>--image=</option>.
133 Takes either <literal>raw</literal> or <literal>qcow2</literal>. Defaults to
134 <literal>raw</literal>. Note that <literal>qcow2</literal> is only supported for regular files,
135 not block devices.</para>
136
137 <xi:include href="version-info.xml" xpointer="v260"/></listitem>
138 </varlistentry>
139
140 <varlistentry>
141 <term><option>--image-disk-type=<replaceable>TYPE</replaceable></option></term>
142
143 <listitem><para>Specifies the disk type to use for the root disk passed to <option>--image=</option>.
144 Extra drives added via <option>--extra-drive=</option> inherit this disk type unless overridden
145 with an explicit disk type prefix. Takes one of <literal>virtio-blk</literal>,
146 <literal>virtio-scsi</literal>, <literal>nvme</literal>, or <literal>scsi-cd</literal>. Defaults to
147 <literal>virtio-blk</literal>. When <literal>scsi-cd</literal> is specified, the disk is attached
148 as a read-only CD-ROM drive.</para>
149
150 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
151 </varlistentry>
152
153 <varlistentry>
154 <term><option>--discard-disk=<replaceable>BOOL</replaceable></option></term>
155
156 <listitem><para>Controls whether qemu processes discard requests from the VM.
157 This prevents long running VMs from using more disk space than required.
158 This is enabled by default.</para>
159
160 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
161 </varlistentry>
162
163 <varlistentry>
164 <term><option>--grow-image=<replaceable>BYTES</replaceable></option></term>
165 <term><option>-G <replaceable>BYTES</replaceable></option></term>
166
167 <listitem><para>Grows the image file specified by <option>--image=</option> to the specified size
168 in bytes if it is smaller. Executes no operation if no image file is used or the image file is
169 already as large or larger than requested. The specified size accepts the usual K, M, G suffixes
170 (to the base of 1024). Specified values are rounded up to multiples of 4096.</para>
171
172 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
173 </varlistentry>
174 </variablelist>
175 </refsect2>
176
177 <refsect2>
178 <title>Host Configuration</title>
179
180 <variablelist>
181 <varlistentry>
182 <term><option>--cpus=<replaceable>CPUS</replaceable></option></term>
183
184 <listitem><para>The number of CPUs to start the virtual machine with.
185 Defaults to 1.</para>
186
187 <xi:include href="version-info.xml" xpointer="v255"/>
188 </listitem>
189 </varlistentry>
190
191 <varlistentry>
192 <term><option>--ram=<replaceable>BYTES</replaceable>[:<replaceable>MAXBYTES</replaceable>[:<replaceable>SLOTS</replaceable>]]</option></term>
193
194 <listitem><para>The amount of memory to start the virtual machine with. Defaults to 2G.
195 If a maximum size is specified after a colon, memory hotplug is enabled with the given
196 upper limit. The number of hotplug slots can optionally be specified after a second colon
197 and defaults to 1.</para>
198
199 <xi:include href="version-info.xml" xpointer="v255"/>
200 </listitem>
201 </varlistentry>
202
203 <varlistentry>
204 <term><option>--kvm=<replaceable>BOOL</replaceable></option></term>
205
206 <listitem><para>Controls whether to enable KVM acceleration. If not specified or set to <option>auto</option>,
207 KVM support will be detected automatically. If true, KVM is insisted on. If false, disable KVM.</para>
208
209 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
210 </varlistentry>
211
212 <varlistentry>
213 <term><option>--vsock=<replaceable>BOOL</replaceable></option></term>
214
215 <listitem><para>Controls whether to allocate a VSOCK socket for guest. If not specified or set to
216 <option>auto</option>, VSOCK networking support will be detected automatically. If true, VSOCK
217 is insisted on. If false, VSOCK networking is disabled.</para>
218
219 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
220 </varlistentry>
221
222 <varlistentry>
223 <term><option>--vsock-cid=<replaceable>CID</replaceable></option></term>
224
225 <listitem>
226 <para>Sets the specific CID to use for the guest.
227 Valid CIDs are in the range <constant>3</constant> to <constant>4294967294</constant> (<constant>0xFFFF_FFFE</constant>).
228 CIDs outside of this range are reserved. By default, vmspawn will attempt to derive a CID for the guest derived from the machine name,
229 falling back to a random CID if this CID is taken.</para>
230
231 <xi:include href="version-info.xml" xpointer="v255"/>
232 </listitem>
233 </varlistentry>
234
235 <varlistentry>
236 <term><option>--tpm=<replaceable>BOOL</replaceable></option></term>
237
238 <listitem>
239 <para>Controls whether to serve a TPM device for guest, via <citerefentry project='debian'>
240 <refentrytitle>swtpm</refentrytitle><manvolnum>8</manvolnum></citerefentry>. If not specified or
241 set to <option>auto</option>, vmspawn will detect the presence of swtpm binary automatically.
242 If yes, swtpm support is insisted on. If no, TPM is disabled.</para>
243
244 <xi:include href="version-info.xml" xpointer="v256"/>
245 </listitem>
246 </varlistentry>
247
248 <varlistentry>
249 <term><option>--tpm-state=<replaceable>PATH</replaceable>|auto|off</option></term>
250
251 <listitem><para>Configures where to place TPM state, in case TPM support is enabled (see
252 <option>--tpm=</option> above). This takes an absolute file system path to a directory to
253 persistently place the state in. If the directory is missing it is created as needed. If set to the
254 special string <literal>auto</literal> a persistent path is automatically derived from the VM image
255 path or directory path, with the <literal>.tpmstate</literal> suffix appended. If set to the
256 special string <literal>off</literal> the TPM state is only maintained transiently and flushed out
257 when the VM shuts down. This mode is not suitable for VMs which lock disk encryption keys to the
258 TPM, as these keys will be lost on every reboot. Defaults to <literal>auto</literal>.</para>
259
260 <para>If <option>--ephemeral</option> is specified, <literal>auto</literal> behaves like
261 <literal>off</literal>.</para>
262
263 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
264 </varlistentry>
265
266 <varlistentry>
267 <term><option>--efi-nvram-template=<replaceable>PATH</replaceable></option></term>
268
269 <listitem><para>Takes an absolute path, or a relative path beginning with
270 <filename>./</filename>. Specifies the path to an EFI NVRAM template file to copy and use as the
271 initial EFI variable NVRAM state. If not specified, the default NVRAM template from the firmware
272 definition is copied and used.</para>
273
274 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
275 </varlistentry>
276
277 <varlistentry>
278 <term><option>--efi-nvram-state=<replaceable>PATH</replaceable>|auto|off</option></term>
279
280 <listitem><para>Configures where to place the EFI variable NVRAM state. This takes an absolute file
281 system path to a regular file to persistently place the state in. If the file is missing it is
282 created as needed. If set to the special string <literal>auto</literal> a persistent path is
283 automatically derived from the VM image path or directory path, with the
284 <literal>.efinvramstate</literal> suffix appended. If set to the special string
285 <literal>off</literal> the EFI variable NVRAM state is only maintained transiently and flushed out
286 when the VM shuts down. Defaults to <literal>auto</literal>.</para>
287
288 <para>If <option>--ephemeral</option> is specified, <literal>auto</literal> behaves like
289 <literal>off</literal>.</para>
290
291 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
292 </varlistentry>
293
294 <varlistentry>
295 <term><option>--secure-boot=<replaceable>BOOL</replaceable></option></term>
296
297 <listitem><para>Configure whether to search for firmware which supports Secure Boot. Takes a
298 boolean or <literal>auto</literal>. Setting this to yes is equivalent to
299 <option>--firmware-features=secure-boot</option> and setting this to no is equivalent to
300 <option>--firmware-features=~secure-boot</option>. Setting this to <literal>auto</literal>
301 removes <literal>secure-boot</literal> from both the included and excluded feature lists.</para>
302
303 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
304 </varlistentry>
305
306 <varlistentry>
307 <term><option>--firmware=<replaceable>PATH</replaceable></option></term>
308
309 <listitem><para>Selects which firmware to use in the VM. Takes one of <literal>auto</literal>,
310 <literal>uefi</literal>, <literal>bios</literal>, <literal>none</literal>, an absolute path, or a
311 relative path beginning with <filename>./</filename>. Defaults to <literal>auto</literal>, which
312 selects UEFI firmware unless <option>--linux=</option> specifies a non-PE kernel image, in which
313 case <literal>none</literal> is selected. <literal>uefi</literal> loads OVMF firmware (use a path
314 to a JSON firmware definition file to select a specific one). <literal>bios</literal> skips OVMF
315 loading and lets QEMU use its built-in BIOS (e.g. SeaBIOS on x86). <literal>none</literal> disables
316 firmware loading entirely and requires <option>--linux=</option> to be specified for direct kernel
317 boot. Booting a UKI requires <literal>uefi</literal>. If the special string <literal>list</literal>
318 is specified, all discovered firmware definition files are listed. If the special string
319 <literal>describe</literal> is specified, the UEFI firmware that would be selected (taking
320 <option>--firmware-features=</option> into account) is printed and the program exits. If an empty
321 string is specified, the option is reset to its default.</para>
322
323 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
324 </varlistentry>
325
326 <varlistentry>
327 <term><option>--firmware-features=<replaceable>FEATURE</replaceable>[,<replaceable>FEATURE</replaceable>...]</option></term>
328
329 <listitem><para>Takes a comma-delimited list of firmware feature strings. This option may be
330 specified multiple times, in which case the feature lists are combined. When specified, only
331 firmware definitions that have all the required features will be considered during automatic
332 firmware discovery. Features prefixed with <literal>~</literal> are excluded: firmware that has
333 such a feature will be skipped. If a feature appears in both the included and excluded lists,
334 inclusion takes priority. By default, firmware with the <literal>enrolled-keys</literal>
335 feature is excluded. If an empty string is passed, both the included and excluded feature lists
336 are reset. If the special string <literal>list</literal> is specified, lists all available
337 firmware features.</para>
338
339 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
340 </varlistentry>
341
342 <varlistentry>
343 <term><option>--coco=</option></term>
344
345 <listitem><para>Caveat: This feature is experimental, and is likely to be changed (or removed in
346 its current form) in a future version of systemd.</para>
347
348 <para>Configures whether to run the guest as a confidential VM. Takes one of
349 <literal>no</literal> or <literal>sev-snp</literal>. Defaults to <literal>no</literal>.</para>
350
351 <para><literal>sev-snp</literal> enables AMD SEV-SNP. This requires KVM on an x86_64 host with
352 SNP-capable hardware and firmware. <option>--firmware=</option> must point to a raw SNP-built
353 OVMF <filename>.fd</filename> image; the standard pflash + NVRAM split is not supported under
354 SNP, so the firmware is loaded via QEMU's <option>-bios</option> and Secure Boot is
355 unavailable. SMBIOS credentials passed via <option>--set-credential=</option> or
356 <option>--load-credential=</option> are rejected because they are outside the SNP launch
357 measurement. Direct kernel boot via <option>--linux=</option> is required so that the
358 kernel, initrd and command line are hashed into the launch measurement
359 (<literal>kernel-hashes=on</literal>); booting the kernel off the disk image via the
360 firmware would leave it outside the measurement. A vTPM, if attached via
361 <option>--tpm=</option>, must be treated as untrusted by the guest.</para>
362
363 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
364 </varlistentry>
365 </variablelist>
366 </refsect2>
367
368 <refsect2>
369 <title>Networking Options</title>
370
371 <variablelist>
372 <varlistentry>
373 <term><option>-n</option></term>
374 <term><option>--network-tap</option></term>
375
376 <listitem>
377 <para>Create a TAP device to network with the virtual machine.</para>
378
379 <para>Note: root privileges are required to use TAP networking.
380 Additionally,
381 <citerefentry><refentrytitle>systemd-networkd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
382 must be running and correctly set up on the host to provision the host interface. The relevant
383 <literal>.network</literal> file can be found at
384 <filename>/usr/lib/systemd/network/80-vm-vt.network</filename>.
385 </para>
386
387 <xi:include href="version-info.xml" xpointer="v255"/>
388 </listitem>
389 </varlistentry>
390
391 <varlistentry>
392 <term><option>--network-user-mode</option></term>
393
394 <listitem><para>Use user mode networking.</para>
395
396 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
397 </varlistentry>
398 </variablelist>
399 </refsect2>
400
401 <refsect2>
402 <title>Execution Options</title>
403
404 <variablelist>
405 <varlistentry>
406 <term><option>--linux=<replaceable>PATH</replaceable></option></term>
407
408 <listitem>
409 <para>Set the linux kernel image to use for direct kernel boot.
410 If a directory type image is used and <option>--linux=</option> was omitted, vmspawn will search for boot loader entries
411 according to the
412 <ulink url="https://uapi-group.org/specifications/specs/boot_loader_specification">UAPI.1 Boot Loader Specification</ulink> assuming
413 XBOOTLDR to be located at /boot and ESP to be /efi respectively.
414 If no kernel was installed into the image then the image will fail to boot.</para>
415
416 <xi:include href="version-info.xml" xpointer="v256"/>
417 </listitem>
418 </varlistentry>
419
420 <varlistentry>
421 <term><option>--initrd=<replaceable>PATH</replaceable></option></term>
422
423 <listitem>
424 <para>Set the initrd to use for direct kernel boot.
425 If the <option>--linux=</option> supplied is a
426 <ulink url="https://uapi-group.org/specifications/specs/boot_loader_specification">UAPI.1 Boot Loader Specification</ulink>
427 Type #2 entry, then this argument is not required.
428 If no initrd was installed into the image then the image will fail to boot.</para>
429
430 <para><option>--initrd=</option> can be specified multiple times and vmspawn will merge them together.</para>
431
432 <xi:include href="version-info.xml" xpointer="v256"/>
433 </listitem>
434 </varlistentry>
435
436 <varlistentry>
437 <term><option>--smbios11=<replaceable>STRING</replaceable></option></term>
438 <term><option>-s <replaceable>STRING</replaceable></option></term>
439
440 <listitem><para>Passes the specified string into the VM as an SMBIOS Type #11 vendor string. This
441 is useful to parameterize the invoked VM in various ways. See
442 <citerefentry><refentrytitle>smbios-type-11</refentrytitle><manvolnum>7</manvolnum></citerefentry>
443 for details.</para>
444
445 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
446 </varlistentry>
447
448 <varlistentry>
449 <term><option>--notify-ready=</option></term>
450
451 <listitem><para>Configures support for notifications from the VM's init process to
452 <command>systemd-vmspawn</command>. If true, <command>systemd-vmspawn</command> will consider the
453 machine as ready only when it has received a <literal>READY=1</literal> message from the init
454 process in the VM. If false, <command>systemd-vmspawn</command> will consider the machine as ready
455 immediately after creation. In either case, <command>systemd-vmspawn</command> sends its own
456 readiness notification to its manager after the spawned VM is ready. For more details about
457 notifications see
458 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
459
460 <para>Defaults to true. (Note that this is unlike the option of the same name to
461 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>
462 that defaults to false.)</para>
463
464 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
465 </varlistentry>
466 </variablelist>
467 </refsect2>
468
469 <refsect2>
470 <title>System Identity Options</title>
471
472 <variablelist>
473 <varlistentry>
474 <term><option>-M</option></term>
475 <term><option>--machine=</option></term>
476
477 <listitem><para>Sets the machine name for this virtual machine. This
478 name may be used to identify this virtual machine during its runtime
479 (for example in tools like
480 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
481 and similar).</para>
482
483 <xi:include href="version-info.xml" xpointer="v255"/>
484 </listitem>
485 </varlistentry>
486
487 <varlistentry>
488 <term><option>--uuid=</option></term>
489
490 <listitem><para>Set the specified UUID for the virtual machine. The
491 init system will initialize
492 <filename>/etc/machine-id</filename> from this if this file is
493 not set yet. Note that this option takes effect only if
494 <filename>/etc/machine-id</filename> in the virtual machine is
495 unpopulated.</para>
496
497 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
498 </varlistentry>
499 </variablelist>
500 </refsect2>
501
502 <refsect2>
503 <title>Property Options</title>
504
505 <variablelist>
506 <varlistentry>
507 <term><option>-S</option></term>
508 <term><option>--slice=</option></term>
509
510 <listitem><para>Make the VM part of the specified slice, instead of the default
511 <filename>machine.slice</filename>. This applies only if the machine is run in its own scope unit,
512 i.e. if <option>--keep-unit</option> is not used.</para>
513
514 <xi:include href="version-info.xml" xpointer="v258"/>
515 </listitem>
516 </varlistentry>
517
518 <varlistentry>
519 <term><option>--property=</option></term>
520
521 <listitem><para>Set a unit property on the scope unit to register for the machine. This applies
522 only if the machine is run in its own scope unit, i.e. if <option>--keep-unit</option> is not
523 used. Takes unit property assignments in the same format as <command>systemctl
524 set-property</command>. This is useful to set memory limits and similar for the VM.</para>
525
526 <xi:include href="version-info.xml" xpointer="v258"/>
527 </listitem>
528 </varlistentry>
529
530 <varlistentry>
531 <term><option>--register=</option></term>
532
533 <listitem><para>Controls whether the virtual machine is registered with
534 <citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>. Takes a
535 boolean argument or <literal>auto</literal>, and defaults to <literal>auto</literal>. This ensures that the
536 virtual machine is accessible via
537 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>. When set to
538 <literal>auto</literal>, registration is attempted but failures are ignored.</para>
539
540 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
541 </varlistentry>
542 </variablelist>
543 </refsect2>
544
545 <refsect2>
546 <title>User Namespacing Options</title>
547
548 <variablelist>
549 <varlistentry>
550 <term><option>--private-users=<replaceable>UID_SHIFT[:UID_RANGE]</replaceable></option></term>
551
552 <listitem><para>Controls user namespacing under <option>--directory=</option>.
553 If enabled,
554 <citerefentry project='url'><refentrytitle url='https://manpages.debian.org/unstable/qemu-system-common/virtiofsd.1.en.html'>virtiofsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
555 is instructed to map user and group ids (UIDs and GIDs).
556 This involves mapping the private UIDs/GIDs used in the virtual machine (starting with the virtual machine's
557 root user 0 and up) to a range of UIDs/GIDs on the host that are not used for other purposes (usually in the
558 range beyond the host's UID/GID 65536).</para>
559
560 <para>If one or two colon-separated numbers are specified, user namespacing is turned on. <replaceable>UID_SHIFT</replaceable>
561 specifies the first host UID/GID to map, <replaceable>UID_RANGE</replaceable> is optional and specifies number of host
562 UIDs/GIDs to assign to the virtual machine. If <replaceable>UID_RANGE</replaceable> is omitted, 65536 UIDs/GIDs are assigned.</para>
563
564 <para>When user namespaces are used, the GID range assigned to each virtual machine is always chosen identical to the
565 UID range.</para>
566
567 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
568 </varlistentry>
569 </variablelist>
570 </refsect2>
571
572 <refsect2>
573 <title>Mount Options</title>
574
575 <variablelist>
576
577 <varlistentry>
578 <term><option>--bind=<replaceable>PATH</replaceable></option></term>
579 <term><option>--bind-ro=<replaceable>PATH</replaceable></option></term>
580
581 <listitem><para>Mount a directory from the host into the virtual machine. Takes one of: a path
582 argument — in which case the specified path will be mounted from the host to the same path in the virtual machine, or
583 a colon-separated pair of paths — in which case the first specified path is the source in the host, and the
584 second path is the destination in the virtual machine. If the source path is not absolute, it is resolved
585 relative to the current working directory. The <option>--bind-ro=</option> option creates read-only bind mounts.
586 Backslash escapes are interpreted, so <literal>\:</literal> may be used to embed colons in either path.
587 This option may be specified multiple times for creating multiple independent bind mount points.</para>
588
589 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
590 </varlistentry>
591
592 <varlistentry>
593 <term><option>--extra-drive=[<replaceable>FORMAT</replaceable>:][<replaceable>DISKTYPE</replaceable>:]<replaceable>PATH</replaceable></option></term>
594
595 <listitem><para>Takes a disk image or block device on the host and supplies it to the virtual
596 machine as another drive. Optionally, the image format and/or disk type can be specified by prefixing
597 the path with their values separated by colons. The format and disk type prefixes can appear in any
598 order. The format defaults to <literal>raw</literal> and the disk type defaults to the value of
599 <option>--image-disk-type=</option> (which itself defaults to <literal>virtio-blk</literal>).
600 Note that <literal>qcow2</literal> is only supported for regular files, not block devices.</para>
601
602 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
603 </varlistentry>
604
605 <varlistentry>
606 <term><option>--bind-volume=<replaceable>PROVIDER</replaceable>:<replaceable>VOLUME</replaceable>[:<replaceable>CONFIG</replaceable>][:<replaceable>K=V</replaceable>,…]</option></term>
607
608 <listitem><para>Acquire a storage volume from a
609 <citerefentry><refentrytitle>storagectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
610 provider and attach it to the virtual machine. <replaceable>PROVIDER</replaceable> is the
611 provider name (typically <literal>block</literal> or <literal>fs</literal>). <replaceable>VOLUME</replaceable>
612 is the volume name passed to the provider's <function>Acquire()</function> method.
613 <replaceable>CONFIG</replaceable> selects the guest device type and takes one of
614 <literal>virtio-blk</literal>, <literal>virtio-scsi</literal>, <literal>nvme</literal>, or
615 <literal>scsi-cd</literal>. If empty or omitted, defaults to <literal>virtio-blk</literal>.</para>
616
617 <para>The trailing comma-separated <replaceable>K=V</replaceable> list passes parameters to
618 <function>io.systemd.StorageProvider.Acquire()</function>: <varname>template=</varname>,
619 <varname>create=</varname> (one of <literal>any</literal>, <literal>new</literal>, <literal>open</literal>),
620 <varname>read-only=</varname> (or <varname>ro=</varname>; takes a boolean or <literal>auto</literal>),
621 <varname>size=</varname> / <varname>create-size=</varname> (size for created volumes),
622 <varname>request-as=</varname> (one of <literal>blk</literal>, <literal>reg</literal>,
623 <literal>dir</literal>; <literal>dir</literal> is rejected by vmspawn).</para>
624
625 <para>Each attached volume is identified by the name <literal><replaceable>PROVIDER</replaceable>:<replaceable>VOLUME</replaceable></literal>.
626 Volumes attached at startup via this option cannot be detached at runtime via
627 <command>machinectl unbind-volume</command>; only volumes added at runtime via
628 <command>machinectl bind-volume</command> are removable.</para>
629
630 <para>The provider is looked up under
631 <filename>/run/systemd/io.systemd.StorageProvider/</filename> for system mode (or
632 <filename>$XDG_RUNTIME_DIR/systemd/io.systemd.StorageProvider/</filename> for user mode), matching
633 the runtime scope chosen via <option>--user</option> / <option>--system</option>.</para>
634
635 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
636 </varlistentry>
637
638 <varlistentry>
639 <term><option>--bind-user=</option></term>
640
641 <listitem><para>Binds the home directory of the specified user on the host into the virtual
642 machine. Takes the name of an existing user on the host as argument. May be used multiple times to
643 bind multiple users into the virtual machine. This does two things:</para>
644
645 <orderedlist>
646 <listitem><para>The user's home directory is made available from the host into
647 <filename>/run/vmhost/home/</filename> using virtiofs. virtiofsd id translation to map the host
648 user's UID/GID to its assigned UID/GID in the virtual machine.</para></listitem>
649
650 <listitem><para>JSON user and group records are generated in that describes the mapped user which
651 are passed into the virtual machine using <literal>userdb.transient.*</literal> credentials.
652 They contain a minimized representation of the host's user record, adjusted to the UID/GID and
653 home directory path assigned to the user in the virtual machine. The
654 <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
655 glibc NSS module will pick up these records from there and make them available in the virtual
656 machine's user/group databases.</para></listitem>
657 </orderedlist>
658
659 <para>The combination of the two operations above ensures that it is possible to log into the
660 virtual machine using the same account information as on the host. The user is only mapped
661 transiently, while the virtual machine is running, and the mapping itself does not result in
662 persistent changes to the virtual machine (except maybe for log messages generated at login time,
663 and similar). Note that in particular the UID/GID assignment in the virtual machine is not made
664 persistently. If the user is mapped transiently, it is best to not allow the user to make
665 persistent changes to the virtual machine. If the user leaves files or directories owned by the
666 user, and those UIDs/GIDs are reused during later virtual machine invocations (possibly with a
667 different <option>--bind-user=</option> mapping), those files and directories will be accessible to
668 the "new" user.</para>
669
670 <para>The user/group record mapping only works if the virtual machine contains systemd 258 or
671 newer, with <command>nss-systemd</command> properly configured in
672 <filename>nsswitch.conf</filename>. See
673 <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
674 details.</para>
675
676 <para>Note that the user record propagated from the host into the virtual machine will contain the
677 UNIX password hash of the user, so that seamless logins in the virtual machine are possible. If the
678 virtual machine is less trusted than the host it is hence important to use a strong UNIX password
679 hash function (e.g. yescrypt or similar, with the <literal>$y$</literal> hash prefix).</para>
680
681 <xi:include href="version-info.xml" xpointer="v259"/></listitem>
682 </varlistentry>
683
684 <varlistentry>
685 <term><option>--bind-user-shell=</option></term>
686
687 <listitem><para>When used with <option>--bind-user=</option>, includes the specified shell in the
688 user records of users bound into the virtual machine. Takes either a boolean or an absolute path.</para>
689
690 <itemizedlist>
691 <listitem><para>If false (the default), no shell is passed in the user records for users bound into
692 the virtual machine. This causes bound users to the use the virtual machine's default shell.</para></listitem>
693
694 <listitem><para>If true, the shells specified by the host user records are included in the user records of all users bound into the virtual machine.</para></listitem>
695
696 <listitem><para>If passed an absolute path, sets that path as the shell for user records of all users bound into the virtual machine.</para></listitem>
697 </itemizedlist>
698
699 <para>Note: This will not check whether the specified shells exist in the virtual machine.</para>
700
701 <para>This operation is only supported in combination with <option>--bind-user=</option>.</para>
702
703 <xi:include href="version-info.xml" xpointer="v259"/></listitem>
704 </varlistentry>
705
706 <varlistentry>
707 <term><option>--bind-user-group=<replaceable>NAME</replaceable></option></term>
708
709 <listitem><para>When used with <option>--bind-user=</option>, includes the specified group as an
710 auxiliary group in the user records of users bound into the virtual machine. Takes a group name.</para>
711
712 <para>Note: This will not check whether the specified groups exist in the virtual machine.</para>
713
714 <para>This operation is only supported in combination with <option>--bind-user=</option>.</para>
715
716 <xi:include href="version-info.xml" xpointer="v259"/></listitem>
717 </varlistentry>
718
719 </variablelist>
720 </refsect2>
721
722 <refsect2>
723 <title>Logging Options</title>
724
725 <variablelist>
726 <varlistentry>
727 <term><option>--forward-journal=<replaceable>FILE|DIR</replaceable></option></term>
728
729 <listitem><para>Forward the virtual machine's journal to the host.
730 <citerefentry><refentrytitle>systemd-journal-remote</refentrytitle><manvolnum>8</manvolnum></citerefentry>
731 is currently used to receive the guest VM's forwarded journal entries. This option determines where
732 this journal is saved on the host and has the same semantics as
733 <option>-o</option>/<option>--output</option> described in
734 <citerefentry><refentrytitle>systemd-journal-remote</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
735
736 <xi:include href="version-info.xml" xpointer="v256"/>
737 </listitem>
738 </varlistentry>
739
740 <varlistentry>
741 <term><option>--forward-journal-max-use=<replaceable>BYTES</replaceable></option></term>
742 <term><option>--forward-journal-keep-free=<replaceable>BYTES</replaceable></option></term>
743 <term><option>--forward-journal-max-file-size=<replaceable>BYTES</replaceable></option></term>
744 <term><option>--forward-journal-max-files=<replaceable>N</replaceable></option></term>
745
746 <listitem><para>These options configure the corresponding settings of
747 <citerefentry><refentrytitle>systemd-journal-remote</refentrytitle><manvolnum>8</manvolnum></citerefentry>
748 when forwarding journal entries from the VM. See
749 <citerefentry><refentrytitle>journal-remote.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
750 for the descriptions of these settings.</para>
751
752 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
753 </varlistentry>
754
755 </variablelist>
756 </refsect2>
757
758 <refsect2>
759 <title>SSH Options</title>
760
761 <variablelist>
762 <varlistentry>
763 <term><option>--pass-ssh-key=<replaceable>BOOL</replaceable></option></term>
764
765 <listitem><para>By default, an SSH key is generated to allow <command>systemd-vmspawn</command> to open
766 a D-Bus connection to the VM's systemd bus. Setting this to "no" will disable SSH key generation.</para>
767
768 <para>The generated keys are ephemeral. That is they are valid only for the current invocation of <command>systemd-vmspawn</command>,
769 and are typically not persisted.</para>
770
771 <xi:include href="version-info.xml" xpointer="v256"/>
772 </listitem>
773 </varlistentry>
774
775 <varlistentry>
776 <term><option>--ssh-key-type=<replaceable>TYPE</replaceable></option></term>
777
778 <listitem><para>Configures the type of SSH key to generate, see
779 <citerefentry project="man-pages"><refentrytitle>ssh-keygen</refentrytitle><manvolnum>1</manvolnum></citerefentry>
780 for more information.</para>
781
782 <para>By default, <literal>ed25519</literal> keys are generated, however <literal>rsa</literal> keys
783 may also be useful if the VM has a particularly old version of
784 <citerefentry project='man-pages'><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
785
786 <xi:include href="version-info.xml" xpointer="v256"/>
787 </listitem>
788 </varlistentry>
789 </variablelist>
790 </refsect2>
791
792 <refsect2>
793 <title>Input/Output Options</title>
794
795 <variablelist>
796 <varlistentry>
797 <term><option>--console=<replaceable>MODE</replaceable></option></term>
798
799 <listitem><para>Configures how to set up the console of the VM. Takes one of
800 <literal>interactive</literal>, <literal>read-only</literal>, <literal>native</literal>,
801 <literal>gui</literal>, <literal>headless</literal>. Defaults to <literal>interactive</literal>.
802 <literal>interactive</literal> provides an interactive terminal interface to the VM.
803 <literal>read-only</literal> is similar, but is strictly read-only, i.e. does not accept any input
804 from the user. <literal>native</literal> also provides a TTY-based interface, but uses qemu native
805 implementation (which means the qemu monitor is available). <literal>gui</literal> shows the qemu
806 graphical UI. <literal>headless</literal> runs the VM without any console, which is useful for
807 automated or scripted usage.</para>
808
809 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
810 </varlistentry>
811
812 <varlistentry>
813 <term><option>--console-transport=<replaceable>TRANSPORT</replaceable></option></term>
814
815 <listitem><para>Configures the transport to use for the VM console. Takes one of
816 <literal>virtio</literal> or <literal>serial</literal>. Defaults to <literal>virtio</literal>.
817 <literal>virtio</literal> uses a virtio-serial device, which appears as
818 <filename>/dev/hvc0</filename> in the VM. <literal>serial</literal> uses a regular serial port,
819 which appears as <filename>/dev/ttyS0</filename> (or <filename>/dev/ttyAMA0</filename> on ARM) in the VM. This option only has an effect in
820 <option>--console=interactive</option>, <option>--console=read-only</option>, and
821 <option>--console=native</option> modes.</para>
822
823 <xi:include href="version-info.xml" xpointer="v261"/></listitem>
824 </varlistentry>
825
826 <varlistentry>
827 <term><option>--background=<replaceable>COLOR</replaceable></option></term>
828
829 <listitem><para>Change the terminal background color to the specified ANSI color as long as the VM
830 runs. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such as
831 <literal>40</literal>, <literal>41</literal>, …, <literal>47</literal>, <literal>48;2;…</literal>,
832 <literal>48;5;…</literal>. See <ulink
833 url="https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">ANSI
834 Escape Code (Wikipedia)</ulink> for details. Assign an empty string to disable any coloring. This
835 only has an effect in <option>--console=interactive</option> and
836 <option>--console=read-only</option> modes.</para>
837
838 <xi:include href="version-info.xml" xpointer="v256"/>
839 </listitem>
840 </varlistentry>
841 </variablelist>
842 </refsect2>
843
844 <refsect2>
845 <title>Credentials</title>
846
847 <variablelist>
848 <varlistentry>
849 <term><option>--load-credential=<replaceable>ID</replaceable>:<replaceable>PATH</replaceable></option></term>
850 <term><option>--set-credential=<replaceable>ID</replaceable>:<replaceable>VALUE</replaceable></option></term>
851
852 <listitem><para>Pass a credential to the virtual machine. These two options correspond to the
853 <varname>LoadCredential=</varname> and <varname>SetCredential=</varname> settings in unit files. See
854 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
855 details about these concepts, as well as the syntax of the option's arguments.</para>
856
857 <para>In order to embed binary data into the credential data for <option>--set-credential=</option>,
858 use C-style escaping (i.e. <literal>\n</literal> to embed a newline, or <literal>\x00</literal> to
859 embed a <constant>NUL</constant> byte). Note that the invoking shell might already apply unescaping
860 once, hence this might require double escaping!</para>
861
862 <para>Credentials are preferably passed to the VM via SMBIOS Type 11 strings or QEMU fw_cfg files.
863 If neither mechanism is available, credentials are passed on the kernel command line using
864 <varname>systemd.set_credential_binary=</varname> which is not a confidential channel. Do not use
865 this for passing secrets to the VM in that case.</para>
866
867 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
868 </varlistentry>
869 </variablelist>
870
871 </refsect2><refsect2>
872 <title>Other</title>
873
874 <variablelist>
875 <xi:include href="standard-options.xml" xpointer="no-pager" />
876 <xi:include href="standard-options.xml" xpointer="help" />
877 <xi:include href="standard-options.xml" xpointer="version" />
878 <xi:include href="standard-options.xml" xpointer="no-ask-password" />
879 </variablelist>
880 </refsect2>
881 </refsect1>
882
883 <xi:include href="common-variables.xml" />
884
885 <refsect1>
886 <title>Examples</title>
887
888 <example>
889 <title>Run an Arch Linux VM image generated by mkosi</title>
890
891 <programlisting>
892 $ mkosi -d arch -p systemd -p linux --autologin -o image.raw -f build
893 $ systemd-vmspawn --image=image.raw
894 </programlisting>
895 </example>
896
897 <example>
898 <title>Import and run a Fedora &fedora_latest_version; Cloud image using importctl</title>
899
900 <programlisting>
901 $ curl -L \
902 -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 \
903 -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 \
904 -O https://fedoraproject.org/fedora.gpg
905 $ gpgv --keyring ./fedora.gpg Fedora-Cloud-&fedora_latest_version;-&fedora_cloud_release;-x86_64-CHECKSUM
906 $ sha256sum -c Fedora-Cloud-&fedora_latest_version;-&fedora_cloud_release;-x86_64-CHECKSUM
907 # importctl import-raw -m Fedora-Cloud-Base-Generic-&fedora_latest_version;-&fedora_cloud_release;.x86_64.qcow2 fedora-&fedora_latest_version;-cloud
908 # systemd-vmspawn -M fedora-&fedora_latest_version;-cloud
909 </programlisting>
910 </example>
911
912 <example>
913 <title>Build and run systemd's system image and forward the VM's journal to a local file</title>
914
915 <programlisting>
916 $ mkosi build
917 $ systemd-vmspawn \
918 -D mkosi.output/system \
919 --private-users $(grep $(whoami) /etc/subuid | cut -d: -f2) \
920 --linux mkosi.output/system.efi \
921 --forward-journal=vm.journal \
922 enforcing=0
923 </programlisting>
924
925 <para>Note: this example also uses a kernel command line argument to ensure SELinux is not started in
926 enforcing mode.</para>
927 </example>
928
929 <example>
930 <title>SSH into a running VM using <command>systemd-ssh-proxy</command></title>
931
932 <programlisting>
933 $ mkosi build
934 $ my_vsock_cid=3735928559
935 $ systemd-vmspawn \
936 -D mkosi.output/system \
937 --private-users $(grep $(whoami) /etc/subuid | cut -d: -f2) \
938 --linux mkosi.output/system.efi \
939 --vsock-cid $my_vsock_cid \
940 enforcing=0
941 $ ssh root@vsock/$my_vsock_cid -i /run/user/$UID/systemd/vmspawn/machine-*-system-ed25519
942 </programlisting>
943 </example>
944 </refsect1>
945
946 <refsect1>
947 <title>Exit status</title>
948
949 <para>If an error occurred the value errno is propagated to the return code.
950 If EXIT_STATUS is supplied by the running image that is returned.
951 Otherwise, EXIT_SUCCESS is returned.</para>
952 </refsect1>
953
954 <refsect1>
955 <title>See Also</title>
956 <para><simplelist type="inline">
957 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
958 <member><citerefentry project='debian'><refentrytitle>mkosi</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
959 <member><citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
960 <member><citerefentry><refentrytitle>importctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
961 <member><ulink url="https://uapi-group.org/specifications/specs/boot_loader_specification">UAPI.1 Boot Loader Specification</ulink></member>
962 </simplelist></para>
963 </refsect1>
964 </refentry>