]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-vmspawn.xml
Merge pull request #31317 from fbuihuu/update-tests-for-suse
[thirdparty/systemd.git] / man / systemd-vmspawn.xml
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 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="systemd-vmspawn" conditional="ENABLE_VMSPAWN"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>systemd-vmspawn</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>systemd-vmspawn</refentrytitle>
16 <manvolnum>1</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>systemd-vmspawn</refname>
21 <refpurpose>Spawn an OS in a virtual machine.</refpurpose>
22 </refnamediv>
23
24 <refsynopsisdiv>
25 <cmdsynopsis>
26 <command>systemd-vmspawn</command>
27 <arg choice="opt" rep="repeat">OPTIONS</arg>
28 <arg choice="opt" rep="repeat">ARGS</arg>
29 </cmdsynopsis>
30 </refsynopsisdiv>
31
32 <refsect1>
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 project='man-pages'><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>, but it
36 launches a full virtual machine instead of using namespaces.</para>
37
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 fds must be passed with the names <literal>kvm</literal> and <literal>vhost-vsock</literal> respectively.</para>
43
44 <para>Note: on Ubuntu/Debian derivatives systemd-vmspawn requires the user to be in the <literal>kvm</literal> group to use the VSock options.</para>
45 </refsect1>
46
47 <refsect1>
48 <title>Options</title>
49
50 <para>The excess arguments are passed as extra kernel command line arguments using SMBIOS.</para>
51
52 <para>The following options are understood:</para>
53
54 <variablelist>
55
56 <varlistentry>
57 <term><option>-q</option></term>
58 <term><option>--quiet</option></term>
59
60 <listitem><para>Turns off any status output by the tool
61 itself. When this switch is used, the only output from vmspawn
62 will be the console output of the Virtual Machine OS itself.</para>
63
64 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
65 </varlistentry>
66
67 </variablelist>
68
69 <refsect2>
70 <title>Image Options</title>
71
72 <varlistentry>
73 <term><option>-D</option></term>
74 <term><option>--directory=</option></term>
75
76 <listitem><para>Directory to use as file system root for the virtual machine.</para>
77
78 <para>One of either <option>--directory=</option> or <option>--image=</option> must be specified.</para>
79 <para>Note: If mounting a non-root owned directory you may require <option>--private-users=</option>
80 to map into the user's subuid namespace.</para>
81
82 <xi:include href="version-info.xml" xpointer="v256"/>
83 </listitem>
84 </varlistentry>
85
86 <variablelist>
87 <varlistentry>
88 <term><option>-i</option></term>
89 <term><option>--image=</option></term>
90
91 <listitem><para>Root file system disk image (or device node) for the virtual machine.</para>
92
93 <xi:include href="version-info.xml" xpointer="v255"/>
94 </listitem>
95 </varlistentry>
96 </variablelist>
97 </refsect2>
98
99 <refsect2>
100 <title>Host Configuration</title>
101
102 <variablelist>
103 <varlistentry>
104 <term><option>--qemu-smp=</option><replaceable>SMP</replaceable></term>
105
106 <listitem><para>Configures the number of CPUs to start the virtual machine with.
107 Defaults to 1.</para>
108
109 <xi:include href="version-info.xml" xpointer="v255"/>
110 </listitem>
111 </varlistentry>
112
113 <varlistentry>
114 <term><option>--qemu-mem=</option><replaceable>MEM</replaceable></term>
115
116 <listitem><para>Configures the amount of memory to start the virtual machine with.
117 Defaults to 2G.</para>
118
119 <xi:include href="version-info.xml" xpointer="v255"/>
120 </listitem>
121 </varlistentry>
122
123 <varlistentry>
124 <term><option>--qemu-kvm=</option><replaceable>BOOL</replaceable></term>
125
126 <listitem><para>Configures whether to use KVM. If the option is not specified KVM support will be
127 detected automatically. If true, KVM is always used, and if false, KVM is never used.</para>
128
129 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
130 </varlistentry>
131
132 <varlistentry>
133 <term><option>--qemu-vsock=</option><replaceable>BOOL</replaceable></term>
134
135 <listitem>
136 <para>Configure whether to use VSock networking.</para>
137 <para>If the option is not specified VSock support will be detected automatically.
138 If yes is specified VSocks are always used, and vice versa if no is set VSocks are never used.</para>
139 <xi:include href="version-info.xml" xpointer="v255"/>
140 </listitem>
141 </varlistentry>
142
143 <varlistentry>
144 <term><option>--vsock-cid=</option><replaceable>CID</replaceable></term>
145
146 <listitem>
147 <para>Configure vmspawn to use a specific CID for the guest.</para>
148 <para>If the option is not specified or an empty argument is supplied the guest will be assigned a random CID.</para>
149 <para>Valid CIDs are in the range <constant>3</constant> to <constant>4294967294</constant> (<constant>0xFFFF_FFFE</constant>).
150 CIDs outside of this range are reserved.</para>
151 <xi:include href="version-info.xml" xpointer="v255"/>
152 </listitem>
153 </varlistentry>
154
155 <varlistentry>
156 <term><option>--tpm=</option><replaceable>BOOL</replaceable></term>
157
158 <listitem>
159 <para>Configure whether to use qemu with a virtual TPM or not.</para>
160 <para>If the option is not specified vmspawn will detect the presence of <citerefentry project='man-pages'>
161 <refentrytitle>swtpm</refentrytitle><manvolnum>8</manvolnum></citerefentry> and use it if available.
162 If yes is specified <citerefentry project='man-pages'><refentrytitle>swtpm</refentrytitle><manvolnum>8</manvolnum></citerefentry>
163 is always used, and vice versa if no is set <citerefentry project='man-pages'><refentrytitle>swtpm</refentrytitle>
164 <manvolnum>8</manvolnum></citerefentry> is never used.</para>
165 <para>Note: the virtual TPM used may change in future.</para>
166 <xi:include href="version-info.xml" xpointer="v256"/>
167 </listitem>
168 </varlistentry>
169
170 <varlistentry>
171 <term><option>--linux=</option><replaceable>PATH</replaceable></term>
172
173 <listitem>
174 <para>Set the linux kernel image to use for direct kernel boot.</para>
175 <para>If no kernel was installed into the image then the image will fail to boot.</para>
176 <xi:include href="version-info.xml" xpointer="v256"/>
177 </listitem>
178 </varlistentry>
179
180 <varlistentry>
181 <term><option>--initrd=</option><replaceable>PATH</replaceable></term>
182
183 <listitem>
184 <para>Set the initrd to use for direct kernel boot.</para>
185 <para>If the linux kernel supplied is a UKI then this argument is not required.</para>
186 <para>If the option is specified multiple times vmspawn will merge the initrds together.</para>
187 <para>If no initrd was installed into the image then the image will fail to boot.</para>
188 <xi:include href="version-info.xml" xpointer="v256"/>
189 </listitem>
190 </varlistentry>
191
192 <varlistentry>
193 <term><option>--qemu-gui</option></term>
194
195 <listitem><para>Start QEMU in graphical mode.</para>
196
197 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
198 </varlistentry>
199
200 <varlistentry>
201 <term><option>-n</option></term>
202 <term><option>--network-tap</option></term>
203
204 <listitem>
205 <para>Create a TAP device to network with the virtual machine.</para>
206 <para>
207 Note: root privileges are required to use TAP networking.
208 Additionally requires a correctly setup
209 <citerefentry><refentrytitle>systemd-networkd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
210 to be running on the host to ensure the host interface is correctly configured.
211 The relevant <literal>.network</literal> file can be found at <filename>/usr/lib/systemd/network/80-vm-vt.network</filename>.
212 </para>
213 <xi:include href="version-info.xml" xpointer="v255"/>
214 </listitem>
215 </varlistentry>
216
217 <varlistentry>
218 <term><option>--network-user-mode</option></term>
219
220 <listitem><para>Use user mode networking with QEMU.</para>
221
222 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
223 </varlistentry>
224
225 <varlistentry>
226 <term><option>--firmware=</option><replaceable>PATH</replaceable></term>
227
228 <listitem><para>Takes an absolute path, or a relative path beginning with
229 <filename>./</filename>. Specifies a JSON firmware definition file, which allows selecting the
230 firmware to boot in the VM. If not specified a suitable firmware is automatically discovered. If the
231 special string <literal>list</literal> is specified lists all discovered firmwares.</para>
232
233 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
234 </varlistentry>
235
236 <varlistentry>
237 <term><option>--secure-boot=</option><replaceable>BOOL</replaceable></term>
238
239 <listitem><para>Configure whether to search for firmware which supports Secure Boot.</para>
240 <para>If the option is not specified the first firmware which is detected will be used.
241 If the option is set to yes then the first firmware with Secure Boot support will be selected.
242 If no is specified then the first firmware without Secure Boot will be selected.</para>
243
244 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
245 </varlistentry>
246 </variablelist>
247 </refsect2>
248
249 <refsect2>
250 <title>System Identity Options</title>
251
252 <variablelist>
253 <varlistentry>
254 <term><option>-M</option></term>
255 <term><option>--machine=</option></term>
256
257 <listitem><para>Sets the machine name for this virtual machine. This
258 name may be used to identify this virtual machine during its runtime
259 (for example in tools like
260 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
261 and similar).</para>
262 <xi:include href="version-info.xml" xpointer="v255"/>
263 </listitem>
264 </varlistentry>
265 </variablelist>
266 </refsect2>
267
268 <refsect2>
269 <title>User Namespacing Options</title>
270
271 <variablelist>
272 <varlistentry>
273 <term><option>--private-users=</option><replaceable>UID_SHIFT[:UID_RANGE]</replaceable></term>
274
275 <listitem><para>Controls user namespacing under <option>--directory=</option>.
276 If enabled, <citerefentry project='man-pages'><refentrytitle>virtiofsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
277 is instructed to map user and group ids (UIDs and GIDs). This involves mapping the private UIDs/GIDs used in the virtual machine
278 (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
279 purposes (usually in the range beyond the host's UID/GID 65536).</para>
280
281 <para>If one or two colon-separated numbers are specified, user namespacing is turned on. <replaceable>UID_SHIFT</replaceable>
282 specifies the first host UID/GID to map, <replaceable>UID_RANGE</replaceable> is optional and specifies number of host
283 UIDs/GIDs to assign to the virtual machine. If <replaceable>UID_RANGE</replaceable> is omitted, 65536 UIDs/GIDs are assigned.</para>
284
285 <para>When user namespaces are used, the GID range assigned to each virtual machine is always chosen identical to the
286 UID range.</para>
287
288 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
289 </varlistentry>
290 </variablelist>
291 </refsect2>
292
293 <refsect2>
294 <title>Mount Options</title>
295
296 <variablelist>
297
298 <varlistentry>
299 <term><option>--bind=</option><replaceable>PATH</replaceable></term>
300 <term><option>--bind-ro=</option><replaceable>PATH</replaceable></term>
301
302 <listitem><para>Mount a directory from the host into the virtual machine. Takes one of: a path
303 argument — in which case the specified path will be mounted from the host to the same path in the virtual machine, or
304 a colon-separated pair of paths — in which case the first specified path is the source in the host, and the
305 second path is the destination in the virtual machine. If the source path is not absolute, it is resolved
306 relative to the current working directory. The <option>--bind-ro=</option> option creates read-only bind mounts.
307 Backslash escapes are interpreted, so <literal>\:</literal> may be used to embed colons in either path.
308 This option may be specified multiple times for creating multiple independent bind mount points.</para>
309
310 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
311 </varlistentry>
312 </variablelist>
313 </refsect2>
314
315 <refsect2>
316 <title>Credentials</title>
317
318 <variablelist>
319 <varlistentry>
320 <term><option>--load-credential=</option><replaceable>ID</replaceable>:<replaceable>PATH</replaceable></term>
321 <term><option>--set-credential=</option><replaceable>ID</replaceable>:<replaceable>VALUE</replaceable></term>
322
323 <listitem><para>Pass a credential to the virtual machine. These two options correspond to the
324 <varname>LoadCredential=</varname> and <varname>SetCredential=</varname> settings in unit files. See
325 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
326 details about these concepts, as well as the syntax of the option's arguments.</para>
327
328 <para>In order to embed binary data into the credential data for <option>--set-credential=</option>,
329 use C-style escaping (i.e. <literal>\n</literal> to embed a newline, or <literal>\x00</literal> to
330 embed a <constant>NUL</constant> byte). Note that the invoking shell might already apply unescaping
331 once, hence this might require double escaping!.</para>
332
333 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
334 </varlistentry>
335 </variablelist>
336
337 </refsect2><refsect2>
338 <title>Other</title>
339
340 <variablelist>
341 <xi:include href="standard-options.xml" xpointer="no-pager" />
342 <xi:include href="standard-options.xml" xpointer="help" />
343 <xi:include href="standard-options.xml" xpointer="version" />
344 </variablelist>
345 </refsect2>
346 </refsect1>
347
348 <xi:include href="common-variables.xml" />
349
350 <refsect1>
351 <title>Examples</title>
352
353 <example>
354 <title>Run an Arch Linux VM image generated by mkosi</title>
355
356 <programlisting>
357 $ mkosi -d arch -p systemd -p linux --autologin -o image.raw -f build
358 $ systemd-vmspawn --image=image.raw
359 </programlisting>
360 </example>
361 </refsect1>
362
363 <refsect1>
364 <title>Exit status</title>
365
366 <para>If an error occurred the value errno is propagated to the return code.
367 If EXIT_STATUS is supplied by the running image that is returned.
368 Otherwise EXIT_SUCCESS is returned.</para>
369 </refsect1>
370
371 <refsect1>
372 <title>See Also</title>
373 <para><simplelist type="inline">
374 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
375 <member><citerefentry><refentrytitle>mkosi</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
376 </simplelist></para>
377 </refsect1>
378 </refentry>