]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd-nspawn.xml
88b5758d91b8908d73f63f0f66ff3184b4c1b5b5
[thirdparty/systemd.git] / man / systemd-nspawn.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="systemd-nspawn"
25 xmlns:xi="http://www.w3.org/2001/XInclude">
26
27 <refentryinfo>
28 <title>systemd-nspawn</title>
29 <productname>systemd</productname>
30
31 <authorgroup>
32 <author>
33 <contrib>Developer</contrib>
34 <firstname>Lennart</firstname>
35 <surname>Poettering</surname>
36 <email>lennart@poettering.net</email>
37 </author>
38 </authorgroup>
39 </refentryinfo>
40
41 <refmeta>
42 <refentrytitle>systemd-nspawn</refentrytitle>
43 <manvolnum>1</manvolnum>
44 </refmeta>
45
46 <refnamediv>
47 <refname>systemd-nspawn</refname>
48 <refpurpose>Spawn a namespace container for debugging, testing and building</refpurpose>
49 </refnamediv>
50
51 <refsynopsisdiv>
52 <cmdsynopsis>
53 <command>systemd-nspawn</command>
54 <arg choice="opt" rep="repeat">OPTIONS</arg>
55 <arg choice="opt"><replaceable>COMMAND</replaceable>
56 <arg choice="opt" rep="repeat">ARGS</arg>
57 </arg>
58 </cmdsynopsis>
59 <cmdsynopsis>
60 <command>systemd-nspawn</command>
61 <arg choice="plain">-b</arg>
62 <arg choice="opt" rep="repeat">OPTIONS</arg>
63 <arg choice="opt" rep="repeat">ARGS</arg>
64 </cmdsynopsis>
65 </refsynopsisdiv>
66
67 <refsect1>
68 <title>Description</title>
69
70 <para><command>systemd-nspawn</command> may be used to run a
71 command or OS in a light-weight namespace container. In many ways
72 it is similar to
73 <citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
74 but more powerful since it fully virtualizes the file system
75 hierarchy, as well as the process tree, the various IPC subsystems
76 and the host and domain name.</para>
77
78 <para><command>systemd-nspawn</command> limits access to various
79 kernel interfaces in the container to read-only, such as
80 <filename>/sys</filename>, <filename>/proc/sys</filename> or
81 <filename>/sys/fs/selinux</filename>. Network interfaces and the
82 system clock may not be changed from within the container. Device
83 nodes may not be created. The host system cannot be rebooted and
84 kernel modules may not be loaded from within the container.</para>
85
86 <para>Note that even though these security precautions are taken
87 <command>systemd-nspawn</command> is not suitable for fully secure
88 container setups. Many of the security features may be
89 circumvented and are hence primarily useful to avoid accidental
90 changes to the host system from the container.</para>
91
92 <para>In contrast to
93 <citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry> <command>systemd-nspawn</command>
94 may be used to boot full Linux-based operating systems in a
95 container.</para>
96
97 <para>Use a tool like
98 <citerefentry project='mankier'><refentrytitle>dnf</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
99 <citerefentry project='die-net'><refentrytitle>yum</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
100 <citerefentry project='die-net'><refentrytitle>debootstrap</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
101 or
102 <citerefentry project='archlinux'><refentrytitle>pacman</refentrytitle><manvolnum>8</manvolnum></citerefentry>
103 to set up an OS directory tree suitable as file system hierarchy
104 for <command>systemd-nspawn</command> containers.</para>
105
106 <para>Note that <command>systemd-nspawn</command> will mount file
107 systems private to the container to <filename>/dev</filename>,
108 <filename>/run</filename> and similar. These will not be visible
109 outside of the container, and their contents will be lost when the
110 container exits.</para>
111
112 <para>Note that running two <command>systemd-nspawn</command>
113 containers from the same directory tree will not make processes in
114 them see each other. The PID namespace separation of the two
115 containers is complete and the containers will share very few
116 runtime objects except for the underlying file system. Use
117 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
118 <command>login</command> command to request an additional login
119 prompt in a running container.</para>
120
121 <para><command>systemd-nspawn</command> implements the
122 <ulink
123 url="http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface">Container
124 Interface</ulink> specification.</para>
125
126 <para>As a safety check <command>systemd-nspawn</command> will
127 verify the existence of <filename>/usr/lib/os-release</filename>
128 or <filename>/etc/os-release</filename> in the container tree
129 before starting the container (see
130 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
131 It might be necessary to add this file to the container tree
132 manually if the OS of the container is too old to contain this
133 file out-of-the-box.</para>
134 </refsect1>
135
136 <refsect1>
137 <title>Options</title>
138
139 <para>If option <option>-b</option> is specified, the arguments
140 are used as arguments for the init binary. Otherwise,
141 <replaceable>COMMAND</replaceable> specifies the program to launch
142 in the container, and the remaining arguments are used as
143 arguments for this program. If <option>-b</option> is not used and
144 no arguments are specified, a shell is launched in the
145 container.</para>
146
147 <para>The following options are understood:</para>
148
149 <variablelist>
150 <varlistentry>
151 <term><option>-D</option></term>
152 <term><option>--directory=</option></term>
153
154 <listitem><para>Directory to use as file system root for the
155 container.</para>
156
157 <para>If neither <option>--directory=</option>, nor
158 <option>--image=</option> is specified the directory is
159 determined as <filename>/var/lib/machines/</filename> suffixed
160 by the machine name as specified with
161 <option>--machine=</option>. If neither
162 <option>--directory=</option>, <option>--image=</option>, nor
163 <option>--machine=</option> are specified, the current
164 directory will be used. May not be specified together with
165 <option>--image=</option>.</para></listitem>
166 </varlistentry>
167
168 <varlistentry>
169 <term><option>--template=</option></term>
170
171 <listitem><para>Directory or <literal>btrfs</literal>
172 subvolume to use as template for the container's root
173 directory. If this is specified and the container's root
174 directory (as configured by <option>--directory=</option>)
175 does not yet exist it is created as <literal>btrfs</literal>
176 subvolume and populated from this template tree. Ideally, the
177 specified template path refers to the root of a
178 <literal>btrfs</literal> subvolume, in which case a simple
179 copy-on-write snapshot is taken, and populating the root
180 directory is instant. If the specified template path does not
181 refer to the root of a <literal>btrfs</literal> subvolume (or
182 not even to a <literal>btrfs</literal> file system at all),
183 the tree is copied, which can be substantially more
184 time-consuming. Note that if this option is used the
185 container's root directory (in contrast to the template
186 directory!) must be located on a <literal>btrfs</literal> file
187 system, so that the <literal>btrfs</literal> subvolume may be
188 created. May not be specified together with
189 <option>--image=</option> or
190 <option>--ephemeral</option>.</para>
191
192 <para>Note that this switch leaves host name, machine ID and
193 all other settings that could identify the instance
194 unmodified.</para></listitem>
195 </varlistentry>
196
197 <varlistentry>
198 <term><option>-x</option></term>
199 <term><option>--ephemeral</option></term>
200
201 <listitem><para>If specified, the container is run with a
202 temporary <literal>btrfs</literal> snapshot of its root
203 directory (as configured with <option>--directory=</option>),
204 that is removed immediately when the container terminates.
205 This option is only supported if the root file system is
206 <literal>btrfs</literal>. May not be specified together with
207 <option>--image=</option> or
208 <option>--template=</option>.</para>
209 <para>Note that this switch leaves host name, machine ID and
210 all other settings that could identify the instance
211 unmodified.</para></listitem>
212 </varlistentry>
213
214 <varlistentry>
215 <term><option>-i</option></term>
216 <term><option>--image=</option></term>
217
218 <listitem><para>Disk image to mount the root directory for the
219 container from. Takes a path to a regular file or to a block
220 device node. The file or block device must contain
221 either:</para>
222
223 <itemizedlist>
224 <listitem><para>An MBR partition table with a single
225 partition of type 0x83 that is marked
226 bootable.</para></listitem>
227
228 <listitem><para>A GUID partition table (GPT) with a single
229 partition of type
230 0fc63daf-8483-4772-8e79-3d69d8477de4.</para></listitem>
231
232 <listitem><para>A GUID partition table (GPT) with a marked
233 root partition which is mounted as the root directory of the
234 container. Optionally, GPT images may contain a home and/or
235 a server data partition which are mounted to the appropriate
236 places in the container. All these partitions must be
237 identified by the partition types defined by the <ulink
238 url="http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/">Discoverable
239 Partitions Specification</ulink>.</para></listitem>
240 </itemizedlist>
241
242 <para>Any other partitions, such as foreign partitions, swap
243 partitions or EFI system partitions are not mounted. May not
244 be specified together with <option>--directory=</option>,
245 <option>--template=</option> or
246 <option>--ephemeral</option>.</para></listitem>
247 </varlistentry>
248
249 <varlistentry>
250 <term><option>-b</option></term>
251 <term><option>--boot</option></term>
252
253 <listitem><para>Automatically search for an init binary and
254 invoke it instead of a shell or a user supplied program. If
255 this option is used, arguments specified on the command line
256 are used as arguments for the init binary. This option may not
257 be combined with <option>--share-system</option>.
258 </para></listitem>
259 </varlistentry>
260
261 <varlistentry>
262 <term><option>-u</option></term>
263 <term><option>--user=</option></term>
264
265 <listitem><para>After transitioning into the container, change
266 to the specified user-defined in the container's user
267 database. Like all other systemd-nspawn features, this is not
268 a security feature and provides protection against accidental
269 destructive operations only.</para></listitem>
270 </varlistentry>
271
272 <varlistentry>
273 <term><option>-M</option></term>
274 <term><option>--machine=</option></term>
275
276 <listitem><para>Sets the machine name for this container. This
277 name may be used to identify this container during its runtime
278 (for example in tools like
279 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
280 and similar), and is used to initialize the container's
281 hostname (which the container can choose to override,
282 however). If not specified, the last component of the root
283 directory path of the container is used, possibly suffixed
284 with a random identifier in case <option>--ephemeral</option>
285 mode is selected. If the root directory selected is the host's
286 root directory the host's hostname is used as default
287 instead.</para></listitem>
288 </varlistentry>
289
290 <varlistentry>
291 <term><option>--uuid=</option></term>
292
293 <listitem><para>Set the specified UUID for the container. The
294 init system will initialize
295 <filename>/etc/machine-id</filename> from this if this file is
296 not set yet. </para></listitem>
297 </varlistentry>
298
299 <varlistentry>
300 <term><option>--slice=</option></term>
301
302 <listitem><para>Make the container part of the specified
303 slice, instead of the default
304 <filename>machine.slice</filename>. This is only applies if
305 the machine is run in its own scope unit, i.e. if
306 <option>--keep-unit</option> is not used.</para>
307 </listitem>
308 </varlistentry>
309
310 <varlistentry>
311 <term><option>--property=</option></term>
312
313 <listitem><para>Set a unit property on the scope unit to
314 register for the machine. This only applies if the machine is
315 run in its own scope unit, i.e. if
316 <option>--keep-unit</option> is not used. Takes unit property
317 assignments in the same format as <command>systemctl
318 set-property</command>. This is useful to set memory limits
319 and similar for machines.</para>
320 </listitem>
321 </varlistentry>
322
323 <varlistentry>
324 <term><option>--private-network</option></term>
325
326 <listitem><para>Disconnect networking of the container from
327 the host. This makes all network interfaces unavailable in the
328 container, with the exception of the loopback device and those
329 specified with <option>--network-interface=</option> and
330 configured with <option>--network-veth</option>. If this
331 option is specified, the CAP_NET_ADMIN capability will be
332 added to the set of capabilities the container retains. The
333 latter may be disabled by using
334 <option>--drop-capability=</option>.</para></listitem>
335 </varlistentry>
336
337 <varlistentry>
338 <term><option>--network-interface=</option></term>
339
340 <listitem><para>Assign the specified network interface to the
341 container. This will remove the specified interface from the
342 calling namespace and place it in the container. When the
343 container terminates, it is moved back to the host namespace.
344 Note that <option>--network-interface=</option> implies
345 <option>--private-network</option>. This option may be used
346 more than once to add multiple network interfaces to the
347 container.</para></listitem>
348 </varlistentry>
349
350 <varlistentry>
351 <term><option>--network-macvlan=</option></term>
352
353 <listitem><para>Create a <literal>macvlan</literal> interface
354 of the specified Ethernet network interface and add it to the
355 container. A <literal>macvlan</literal> interface is a virtual
356 interface that adds a second MAC address to an existing
357 physical Ethernet link. The interface in the container will be
358 named after the interface on the host, prefixed with
359 <literal>mv-</literal>. Note that
360 <option>--network-macvlan=</option> implies
361 <option>--private-network</option>. This option may be used
362 more than once to add multiple network interfaces to the
363 container.</para></listitem>
364 </varlistentry>
365
366 <varlistentry>
367 <term><option>--network-ipvlan=</option></term>
368
369 <listitem><para>Create an <literal>ipvlan</literal> interface
370 of the specified Ethernet network interface and add it to the
371 container. An <literal>ipvlan</literal> interface is a virtual
372 interface, similar to a <literal>macvlan</literal> interface,
373 which uses the same MAC address as the underlying interface.
374 The interface in the container will be named after the
375 interface on the host, prefixed with <literal>iv-</literal>.
376 Note that <option>--network-ipvlan=</option> implies
377 <option>--private-network</option>. This option may be used
378 more than once to add multiple network interfaces to the
379 container.</para></listitem>
380 </varlistentry>
381
382 <varlistentry>
383 <term><option>-n</option></term>
384 <term><option>--network-veth</option></term>
385
386 <listitem><para>Create a virtual Ethernet link
387 (<literal>veth</literal>) between host and container. The host
388 side of the Ethernet link will be available as a network
389 interface named after the container's name (as specified with
390 <option>--machine=</option>), prefixed with
391 <literal>ve-</literal>. The container side of the Ethernet
392 link will be named <literal>host0</literal>. Note that
393 <option>--network-veth</option> implies
394 <option>--private-network</option>.</para></listitem>
395 </varlistentry>
396
397 <varlistentry>
398 <term><option>--network-bridge=</option></term>
399
400 <listitem><para>Adds the host side of the Ethernet link
401 created with <option>--network-veth</option> to the specified
402 bridge. Note that <option>--network-bridge=</option> implies
403 <option>--network-veth</option>. If this option is used, the
404 host side of the Ethernet link will use the
405 <literal>vb-</literal> prefix instead of
406 <literal>ve-</literal>.</para></listitem>
407 </varlistentry>
408
409 <varlistentry>
410 <term><option>-p</option></term>
411 <term><option>--port=</option></term>
412
413 <listitem><para>If private networking is enabled, maps an IP
414 port on the host onto an IP port on the container. Takes a
415 protocol specifier (either <literal>tcp</literal> or
416 <literal>udp</literal>), separated by a colon from a host port
417 number in the range 1 to 65535, separated by a colon from a
418 container port number in the range from 1 to 65535. The
419 protocol specifier and its separating colon may be omitted, in
420 which case <literal>tcp</literal> is assumed. The container
421 port number and its colon may be ommitted, in which case the
422 same port as the host port is implied. This option is only
423 supported if private networking is used, such as
424 <option>--network-veth</option> or
425 <option>--network-bridge=</option>.</para></listitem>
426 </varlistentry>
427
428 <varlistentry>
429 <term><option>-Z</option></term>
430 <term><option>--selinux-context=</option></term>
431
432 <listitem><para>Sets the SELinux security context to be used
433 to label processes in the container.</para>
434 </listitem>
435 </varlistentry>
436
437 <varlistentry>
438 <term><option>-L</option></term>
439 <term><option>--selinux-apifs-context=</option></term>
440
441 <listitem><para>Sets the SELinux security context to be used
442 to label files in the virtual API file systems in the
443 container.</para>
444 </listitem>
445 </varlistentry>
446
447 <varlistentry>
448 <term><option>--capability=</option></term>
449
450 <listitem><para>List one or more additional capabilities to
451 grant the container. Takes a comma-separated list of
452 capability names, see
453 <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
454 for more information. Note that the following capabilities
455 will be granted in any way: CAP_CHOWN, CAP_DAC_OVERRIDE,
456 CAP_DAC_READ_SEARCH, CAP_FOWNER, CAP_FSETID, CAP_IPC_OWNER,
457 CAP_KILL, CAP_LEASE, CAP_LINUX_IMMUTABLE,
458 CAP_NET_BIND_SERVICE, CAP_NET_BROADCAST, CAP_NET_RAW,
459 CAP_SETGID, CAP_SETFCAP, CAP_SETPCAP, CAP_SETUID,
460 CAP_SYS_ADMIN, CAP_SYS_CHROOT, CAP_SYS_NICE, CAP_SYS_PTRACE,
461 CAP_SYS_TTY_CONFIG, CAP_SYS_RESOURCE, CAP_SYS_BOOT,
462 CAP_AUDIT_WRITE, CAP_AUDIT_CONTROL. Also CAP_NET_ADMIN is
463 retained if <option>--private-network</option> is specified.
464 If the special value <literal>all</literal> is passed, all
465 capabilities are retained.</para></listitem>
466 </varlistentry>
467
468 <varlistentry>
469 <term><option>--drop-capability=</option></term>
470
471 <listitem><para>Specify one or more additional capabilities to
472 drop for the container. This allows running the container with
473 fewer capabilities than the default (see
474 above).</para></listitem>
475 </varlistentry>
476
477 <varlistentry>
478 <term><option>--kill-signal=</option></term>
479
480 <listitem><para>Specify the process signal to send to the
481 container's PID 1 when nspawn itself receives SIGTERM, in
482 order to trigger an orderly shutdown of the
483 container. Defaults to SIGRTMIN+3 if <option>--boot</option>
484 is used (on systemd-compatible init systems SIGRTMIN+3
485 triggers an orderly shutdown). Takes a signal name like
486 <literal>SIGHUP</literal>, <literal>SIGTERM</literal> or
487 similar as argument.</para></listitem>
488 </varlistentry>
489
490 <varlistentry>
491 <term><option>--link-journal=</option></term>
492
493 <listitem><para>Control whether the container's journal shall
494 be made visible to the host system. If enabled, allows viewing
495 the container's journal files from the host (but not vice
496 versa). Takes one of <literal>no</literal>,
497 <literal>host</literal>, <literal>try-host</literal>,
498 <literal>guest</literal>, <literal>try-guest</literal>,
499 <literal>auto</literal>. If <literal>no</literal>, the journal
500 is not linked. If <literal>host</literal>, the journal files
501 are stored on the host file system (beneath
502 <filename>/var/log/journal/<replaceable>machine-id</replaceable></filename>)
503 and the subdirectory is bind-mounted into the container at the
504 same location. If <literal>guest</literal>, the journal files
505 are stored on the guest file system (beneath
506 <filename>/var/log/journal/<replaceable>machine-id</replaceable></filename>)
507 and the subdirectory is symlinked into the host at the same
508 location. <literal>try-host</literal> and
509 <literal>try-guest</literal> do the same but do not fail if
510 the host does not have persistent journalling enabled. If
511 <literal>auto</literal> (the default), and the right
512 subdirectory of <filename>/var/log/journal</filename> exists,
513 it will be bind mounted into the container. If the
514 subdirectory does not exist, no linking is performed.
515 Effectively, booting a container once with
516 <literal>guest</literal> or <literal>host</literal> will link
517 the journal persistently if further on the default of
518 <literal>auto</literal> is used.</para></listitem>
519 </varlistentry>
520
521 <varlistentry>
522 <term><option>-j</option></term>
523
524 <listitem><para>Equivalent to
525 <option>--link-journal=try-guest</option>.</para></listitem>
526 </varlistentry>
527
528 <varlistentry>
529 <term><option>--read-only</option></term>
530
531 <listitem><para>Mount the root file system read-only for the
532 container.</para></listitem>
533 </varlistentry>
534
535 <varlistentry>
536 <term><option>--bind=</option></term>
537 <term><option>--bind-ro=</option></term>
538
539 <listitem><para>Bind mount a file or directory from the host
540 into the container. Either takes a path argument -- in which
541 case the specified path will be mounted from the host to the
542 same path in the container --, or a colon-separated pair of
543 paths -- in which case the first specified path is the source
544 in the host, and the second path is the destination in the
545 container. This option may be specified multiple times for
546 creating multiple independent bind mount points. The
547 <option>--bind-ro=</option> option creates read-only bind
548 mounts.</para></listitem>
549 </varlistentry>
550
551 <varlistentry>
552 <term><option>--tmpfs=</option></term>
553
554 <listitem><para>Mount a tmpfs file system into the container.
555 Takes a single absolute path argument that specifies where to
556 mount the tmpfs instance to (in which case the directory
557 access mode will be chosen as 0755, owned by root/root), or
558 optionally a colon-separated pair of path and mount option
559 string, that is used for mounting (in which case the kernel
560 default for access mode and owner will be chosen, unless
561 otherwise specified). This option is particularly useful for
562 mounting directories such as <filename>/var</filename> as
563 tmpfs, to allow state-less systems, in particular when
564 combined with <option>--read-only</option>.</para></listitem>
565 </varlistentry>
566
567 <varlistentry>
568 <term><option>--setenv=</option></term>
569
570 <listitem><para>Specifies an environment variable assignment
571 to pass to the init process in the container, in the format
572 <literal>NAME=VALUE</literal>. This may be used to override
573 the default variables or to set additional variables. This
574 parameter may be used more than once.</para></listitem>
575 </varlistentry>
576
577 <varlistentry>
578 <term><option>--share-system</option></term>
579
580 <listitem><para>Allows the container to share certain system
581 facilities with the host. More specifically, this turns off
582 PID namespacing, UTS namespacing and IPC namespacing, and thus
583 allows the guest to see and interact more easily with
584 processes outside of the container. Note that using this
585 option makes it impossible to start up a full Operating System
586 in the container, as an init system cannot operate in this
587 mode. It is only useful to run specific programs or
588 applications this way, without involving an init system in the
589 container. This option implies <option>--register=no</option>.
590 This option may not be combined with
591 <option>--boot</option>.</para></listitem>
592 </varlistentry>
593
594 <varlistentry>
595 <term><option>--register=</option></term>
596
597 <listitem><para>Controls whether the container is registered
598 with
599 <citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
600 Takes a boolean argument, defaults to <literal>yes</literal>.
601 This option should be enabled when the container runs a full
602 Operating System (more specifically: an init system), and is
603 useful to ensure that the container is accessible via
604 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
605 and shown by tools such as
606 <citerefentry project='man-pages'><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
607 If the container does not run an init system, it is
608 recommended to set this option to <literal>no</literal>. Note
609 that <option>--share-system</option> implies
610 <option>--register=no</option>. </para></listitem>
611 </varlistentry>
612
613 <varlistentry>
614 <term><option>--keep-unit</option></term>
615
616 <listitem><para>Instead of creating a transient scope unit to
617 run the container in, simply register the service or scope
618 unit <command>systemd-nspawn</command> has been invoked in
619 with
620 <citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
621 This has no effect if <option>--register=no</option> is used.
622 This switch should be used if
623 <command>systemd-nspawn</command> is invoked from within a
624 service unit, and the service unit's sole purpose is to run a
625 single <command>systemd-nspawn</command> container. This
626 option is not available if run from a user
627 session.</para></listitem>
628 </varlistentry>
629
630 <varlistentry>
631 <term><option>--personality=</option></term>
632
633 <listitem><para>Control the architecture ("personality")
634 reported by
635 <citerefentry project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry>
636 in the container. Currently, only <literal>x86</literal> and
637 <literal>x86-64</literal> are supported. This is useful when
638 running a 32-bit container on a 64-bit host. If this setting
639 is not used, the personality reported in the container is the
640 same as the one reported on the host.</para></listitem>
641 </varlistentry>
642
643 <varlistentry>
644 <term><option>-q</option></term>
645 <term><option>--quiet</option></term>
646
647 <listitem><para>Turns off any status output by the tool
648 itself. When this switch is used, the only output from nspawn
649 will be the console output of the container OS
650 itself.</para></listitem>
651 </varlistentry>
652
653 <varlistentry>
654 <term><option>--volatile</option><replaceable>=MODE</replaceable></term>
655
656 <listitem><para>Boots the container in volatile mode. When no
657 mode parameter is passed or when mode is specified as
658 <literal>yes</literal> full volatile mode is enabled. This
659 means the root directory is mounted as mostly unpopulated
660 <literal>tmpfs</literal> instance, and
661 <filename>/usr</filename> from the OS tree is mounted into it,
662 read-only (the system thus starts up with read-only OS
663 resources, but pristine state and configuration, any changes
664 to the either are lost on shutdown). When the mode parameter
665 is specified as <literal>state</literal> the OS tree is
666 mounted read-only, but <filename>/var</filename> is mounted as
667 <literal>tmpfs</literal> instance into it (the system thus
668 starts up with read-only OS resources and configuration, but
669 pristine state, any changes to the latter are lost on
670 shutdown). When the mode parameter is specified as
671 <literal>no</literal> (the default) the whole OS tree is made
672 available writable.</para>
673
674 <para>Note that setting this to <literal>yes</literal> or
675 <literal>state</literal> will only work correctly with
676 operating systems in the container that can boot up with only
677 <filename>/usr</filename> mounted, and are able to populate
678 <filename>/var</filename> automatically, as
679 needed.</para></listitem>
680 </varlistentry>
681
682 <xi:include href="standard-options.xml" xpointer="help" />
683 <xi:include href="standard-options.xml" xpointer="version" />
684 </variablelist>
685
686 </refsect1>
687
688 <refsect1>
689 <title>Examples</title>
690
691 <example>
692 <title>Download a Fedora image and start a shell in it</title>
693
694 <programlisting># machinectl pull-raw --verify=no http://ftp.halifax.rwth-aachen.de/fedora/linux/releases/21/Cloud/Images/x86_64/Fedora-Cloud-Base-20141203-21.x86_64.raw.xz
695 # systemd-nspawn -M Fedora-Cloud-Base-20141203-21</programlisting>
696
697 <para>This downloads an image using
698 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
699 and opens a shell in it.</para>
700 </example>
701
702 <example>
703 <title>Build and boot a minimal Fedora distribution in a container</title>
704
705 <programlisting># dnf -y --releasever=21 --nogpg --installroot=/srv/mycontainer --disablerepo='*' --enablerepo=fedora install systemd passwd dnf fedora-release vim-minimal
706 # systemd-nspawn -bD /srv/mycontainer</programlisting>
707
708 <para>This installs a minimal Fedora distribution into the
709 directory <filename noindex='true'>/srv/mycontainer/</filename>
710 and then boots an OS in a namespace container in it.</para>
711 </example>
712
713 <example>
714 <title>Spawn a shell in a container of a minimal Debian unstable distribution</title>
715
716 <programlisting># debootstrap --arch=amd64 unstable ~/debian-tree/
717 # systemd-nspawn -D ~/debian-tree/</programlisting>
718
719 <para>This installs a minimal Debian unstable distribution into
720 the directory <filename>~/debian-tree/</filename> and then
721 spawns a shell in a namespace container in it.</para>
722 </example>
723
724 <example>
725 <title>Boot a minimal Arch Linux distribution in a container</title>
726
727 <programlisting># pacstrap -c -d ~/arch-tree/ base
728 # systemd-nspawn -bD ~/arch-tree/</programlisting>
729
730 <para>This installs a minimal Arch Linux distribution into the
731 directory <filename>~/arch-tree/</filename> and then boots an OS
732 in a namespace container in it.</para>
733 </example>
734
735 <example>
736 <title>Boot into an ephemeral <literal>btrfs</literal> snapshot of the host system</title>
737
738 <programlisting># systemd-nspawn -D / -xb</programlisting>
739
740 <para>This runs a copy of the host system in a
741 <literal>btrfs</literal> snapshot which is removed immediately
742 when the container exits. All file system changes made during
743 runtime will be lost on shutdown, hence.</para>
744 </example>
745
746 <example>
747 <title>Run a container with SELinux sandbox security contexts</title>
748
749 <programlisting># chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 -R /srv/container
750 # systemd-nspawn -L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 -Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 -D /srv/container /bin/sh</programlisting>
751 </example>
752 </refsect1>
753
754 <refsect1>
755 <title>Exit status</title>
756
757 <para>The exit code of the program executed in the container is
758 returned.</para>
759 </refsect1>
760
761 <refsect1>
762 <title>See Also</title>
763 <para>
764 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
765 <citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
766 <citerefentry project='mankier'><refentrytitle>dnf</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
767 <citerefentry project='die-net'><refentrytitle>yum</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
768 <citerefentry project='die-net'><refentrytitle>debootstrap</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
769 <citerefentry project='archlinux'><refentrytitle>pacman</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
770 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
771 <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
772 <citerefentry project='man-pages'><refentrytitle>btrfs</refentrytitle><manvolnum>8</manvolnum></citerefentry>
773 </para>
774 </refsect1>
775
776 </refentry>