1SYSTEMD-NSPAWN(1)               systemd-nspawn               SYSTEMD-NSPAWN(1)
2
3
4

NAME

6       systemd-nspawn - Spawn a command or OS in a light-weight container
7

SYNOPSIS

9       systemd-nspawn [OPTIONS...] [COMMAND [ARGS...]]
10
11       systemd-nspawn --boot [OPTIONS...] [ARGS...]
12

DESCRIPTION

14       systemd-nspawn may be used to run a command or OS in a light-weight
15       namespace container. In many ways it is similar to chroot(1), but more
16       powerful since it fully virtualizes the file system hierarchy, as well
17       as the process tree, the various IPC subsystems and the host and domain
18       name.
19
20       systemd-nspawn may be invoked on any directory tree containing an
21       operating system tree, using the --directory= command line option. By
22       using the --machine= option an OS tree is automatically searched for in
23       a couple of locations, most importantly in /var/lib/machines, the
24       suggested directory to place OS container images installed on the
25       system.
26
27       In contrast to chroot(1) systemd-nspawn may be used to boot full
28       Linux-based operating systems in a container.
29
30       systemd-nspawn limits access to various kernel interfaces in the
31       container to read-only, such as /sys, /proc/sys or /sys/fs/selinux. The
32       host's network interfaces and the system clock may not be changed from
33       within the container. Device nodes may not be created. The host system
34       cannot be rebooted and kernel modules may not be loaded from within the
35       container.
36
37       Use a tool like dnf(8), debootstrap(8), or pacman(8) to set up an OS
38       directory tree suitable as file system hierarchy for systemd-nspawn
39       containers. See the Examples section below for details on suitable
40       invocation of these commands.
41
42       As a safety check systemd-nspawn will verify the existence of
43       /usr/lib/os-release or /etc/os-release in the container tree before
44       starting the container (see os-release(5)). It might be necessary to
45       add this file to the container tree manually if the OS of the container
46       is too old to contain this file out-of-the-box.
47
48       systemd-nspawn may be invoked directly from the interactive command
49       line or run as system service in the background. In this mode each
50       container instance runs as its own service instance; a default template
51       unit file systemd-nspawn@.service is provided to make this easy, taking
52       the container name as instance identifier. Note that different default
53       options apply when systemd-nspawn is invoked by the template unit file
54       than interactively on the command line. Most importantly the template
55       unit file makes use of the --boot which is not the default in case
56       systemd-nspawn is invoked from the interactive command line. Further
57       differences with the defaults are documented along with the various
58       supported options below.
59
60       The machinectl(1) tool may be used to execute a number of operations on
61       containers. In particular it provides easy-to-use commands to run
62       containers as system services using the systemd-nspawn@.service
63       template unit file.
64
65       Along with each container a settings file with the .nspawn suffix may
66       exist, containing additional settings to apply when running the
67       container. See systemd.nspawn(5) for details. Settings files override
68       the default options used by the systemd-nspawn@.service template unit
69       file, making it usually unnecessary to alter this template file
70       directly.
71
72       Note that systemd-nspawn will mount file systems private to the
73       container to /dev, /run and similar. These will not be visible outside
74       of the container, and their contents will be lost when the container
75       exits.
76
77       Note that running two systemd-nspawn containers from the same directory
78       tree will not make processes in them see each other. The PID namespace
79       separation of the two containers is complete and the containers will
80       share very few runtime objects except for the underlying file system.
81       Use machinectl(1)'s login or shell commands to request an additional
82       login session in a running container.
83
84       systemd-nspawn implements the Container Interface[1] specification.
85
86       While running, containers invoked with systemd-nspawn are registered
87       with the systemd-machined(8) service that keeps track of running
88       containers, and provides programming interfaces to interact with them.
89

OPTIONS

91       If option -b is specified, the arguments are used as arguments for the
92       init program. Otherwise, COMMAND specifies the program to launch in the
93       container, and the remaining arguments are used as arguments for this
94       program. If --boot is not used and no arguments are specified, a shell
95       is launched in the container.
96
97       The following options are understood:
98
99       -q, --quiet
100           Turns off any status output by the tool itself. When this switch is
101           used, the only output from nspawn will be the console output of the
102           container OS itself.
103
104       --settings=MODE
105           Controls whether systemd-nspawn shall search for and use additional
106           per-container settings from .nspawn files. Takes a boolean or the
107           special values override or trusted.
108
109           If enabled (the default), a settings file named after the machine
110           (as specified with the --machine= setting, or derived from the
111           directory or image file name) with the suffix .nspawn is searched
112           in /etc/systemd/nspawn/ and /run/systemd/nspawn/. If it is found
113           there, its settings are read and used. If it is not found there, it
114           is subsequently searched in the same directory as the image file or
115           in the immediate parent of the root directory of the container. In
116           this case, if the file is found, its settings will be also read and
117           used, but potentially unsafe settings are ignored. Note that in
118           both these cases, settings on the command line take precedence over
119           the corresponding settings from loaded .nspawn files, if both are
120           specified. Unsafe settings are considered all settings that elevate
121           the container's privileges or grant access to additional resources
122           such as files or directories of the host. For details about the
123           format and contents of .nspawn files, consult systemd.nspawn(5).
124
125           If this option is set to override, the file is searched, read and
126           used the same way, however, the order of precedence is reversed:
127           settings read from the .nspawn file will take precedence over the
128           corresponding command line options, if both are specified.
129
130           If this option is set to trusted, the file is searched, read and
131           used the same way, but regardless of being found in
132           /etc/systemd/nspawn/, /run/systemd/nspawn/ or next to the image
133           file or container root directory, all settings will take effect,
134           however, command line arguments still take precedence over
135           corresponding settings.
136
137           If disabled, no .nspawn file is read and no settings except the
138           ones on the command line are in effect.
139
140   Image Options
141       -D, --directory=
142           Directory to use as file system root for the container.
143
144           If neither --directory=, nor --image= is specified the directory is
145           determined by searching for a directory named the same as the
146           machine name specified with --machine=. See machinectl(1) section
147           "Files and Directories" for the precise search path.
148
149           If neither --directory=, --image=, nor --machine= are specified,
150           the current directory will be used. May not be specified together
151           with --image=.
152
153       --template=
154           Directory or "btrfs" subvolume to use as template for the
155           container's root directory. If this is specified and the
156           container's root directory (as configured by --directory=) does not
157           yet exist it is created as "btrfs" snapshot (if supported) or plain
158           directory (otherwise) and populated from this template tree.
159           Ideally, the specified template path refers to the root of a
160           "btrfs" subvolume, in which case a simple copy-on-write snapshot is
161           taken, and populating the root directory is instant. If the
162           specified template path does not refer to the root of a "btrfs"
163           subvolume (or not even to a "btrfs" file system at all), the tree
164           is copied (though possibly in a 'reflink' copy-on-write scheme — if
165           the file system supports that), which can be substantially more
166           time-consuming. Note that the snapshot taken is of the specified
167           directory or subvolume, including all subdirectories and subvolumes
168           below it, but excluding any sub-mounts. May not be specified
169           together with --image= or --ephemeral.
170
171           Note that this switch leaves host name, machine ID and all other
172           settings that could identify the instance unmodified.
173
174       -x, --ephemeral
175           If specified, the container is run with a temporary snapshot of its
176           file system that is removed immediately when the container
177           terminates. May not be specified together with --template=.
178
179           Note that this switch leaves host name, machine ID and all other
180           settings that could identify the instance unmodified. Please note
181           that — as with --template= — taking the temporary snapshot is more
182           efficient on file systems that support subvolume snapshots or
183           'reflinks' natively ("btrfs" or new "xfs") than on more traditional
184           file systems that do not ("ext4"). Note that the snapshot taken is
185           of the specified directory or subvolume, including all
186           subdirectories and subvolumes below it, but excluding any
187           sub-mounts.
188
189           With this option no modifications of the container image are
190           retained. Use --volatile= (described below) for other mechanisms to
191           restrict persistency of container images during runtime.
192
193       -i, --image=
194           Disk image to mount the root directory for the container from.
195           Takes a path to a regular file or to a block device node. The file
196           or block device must contain either:
197
198           ·   An MBR partition table with a single partition of type 0x83
199               that is marked bootable.
200
201           ·   A GUID partition table (GPT) with a single partition of type
202               0fc63daf-8483-4772-8e79-3d69d8477de4.
203
204           ·   A GUID partition table (GPT) with a marked root partition which
205               is mounted as the root directory of the container. Optionally,
206               GPT images may contain a home and/or a server data partition
207               which are mounted to the appropriate places in the container.
208               All these partitions must be identified by the partition types
209               defined by the Discoverable Partitions Specification[2].
210
211           ·   No partition table, and a single file system spanning the whole
212               image.
213
214           On GPT images, if an EFI System Partition (ESP) is discovered, it
215           is automatically mounted to /efi (or /boot as fallback) in case a
216           directory by this name exists and is empty.
217
218           Partitions encrypted with LUKS are automatically decrypted. Also,
219           on GPT images dm-verity data integrity hash partitions are set up
220           if the root hash for them is specified using the --root-hash=
221           option.
222
223           Any other partitions, such as foreign partitions or swap partitions
224           are not mounted. May not be specified together with --directory=,
225           --template=.
226
227       --oci-bundle=
228           Takes the path to an OCI runtime bundle to invoke, as specified in
229           the OCI Runtime Specification[3]. In this case no .nspawn file is
230           loaded, and the root directory and various settings are read from
231           the OCI runtime JSON data (but data passed on the command line
232           takes precedence).
233
234       --read-only
235           Mount the container's root file system (and any other file systems
236           container in the container image) read-only. This has no effect on
237           additional mounts made with --bind=, --tmpfs= and similar options.
238           This mode is implied if the container image file or directory is
239           marked read-only itself. It is also implied if --volatile= is used.
240           In this case the container image on disk is strictly read-only,
241           while changes are permitted but kept non-persistently in memory
242           only. For further details, see below.
243
244       --volatile, --volatile=MODE
245           Boots the container in volatile mode. When no mode parameter is
246           passed or when mode is specified as yes, full volatile mode is
247           enabled. This means the root directory is mounted as a mostly
248           unpopulated "tmpfs" instance, and /usr/ from the OS tree is mounted
249           into it in read-only mode (the system thus starts up with read-only
250           OS image, but pristine state and configuration, any changes are
251           lost on shutdown). When the mode parameter is specified as state,
252           the OS tree is mounted read-only, but /var/ is mounted as a
253           writable "tmpfs" instance into it (the system thus starts up with
254           read-only OS resources and configuration, but pristine state, and
255           any changes to the latter are lost on shutdown). When the mode
256           parameter is specified as overlay the read-only root file system is
257           combined with a writable tmpfs instance through "overlayfs", so
258           that it appears at it normally would, but any changes are applied
259           to the temporary file system only and lost when the container is
260           terminated. When the mode parameter is specified as no (the
261           default), the whole OS tree is made available writable (unless
262           --read-only is specified, see above).
263
264           Note that if one of the volatile modes is chosen, its effect is
265           limited to the root file system (or /var/ in case of state), and
266           any other mounts placed in the hierarchy are unaffected —
267           regardless if they are established automatically (e.g. the EFI
268           system partition that might be mounted to /efi/ or /boot/) or
269           explicitly (e.g. through an additional command line option such as
270           --bind=, see below). This means, even if --volatile=overlay is used
271           changes to /efi/ or /boot/ are prohibited in case such a partition
272           exists in the container image operated on, and even if
273           --volatile=state is used the hypothetical file /etc/foobar is
274           potentially writable if --bind=/etc/foobar if used to mount it from
275           outside the read-only container /etc directory.
276
277           The --ephemeral option is closely related to this setting, and
278           provides similar behaviour by making a temporary, ephemeral copy of
279           the whole OS image and executing that. For further details, see
280           above.
281
282           The --tmpfs= and --overlay= options provide similar functionality,
283           but for specific sub-directories of the OS image only. For details,
284           see below.
285
286           This option provides similar functionality for containers as the
287           "systemd.volatile=" kernel command line switch provides for host
288           systems. See kernel-command-line(7) for details.
289
290           Note that setting this option to yes or state will only work
291           correctly with operating systems in the container that can boot up
292           with only /usr/ mounted, and are able to automatically populate
293           /var/ (and /etc/ in case of "--volatile=yes"). Specifically, this
294           means that operating systems that follow the historic split of
295           /bin/ and /lib/ (and related directories) from /usr/ (i.e. where
296           the former are not symlinks into the latter) are not supported by
297           "--volatile=yes" as container payload. The overlay option does not
298           require any particular preparations in the OS, but do note that
299           "overlayfs" behaviour differs from regular file systems in a number
300           of ways, and hence compatibility is limited.
301
302       --root-hash=
303           Takes a data integrity (dm-verity) root hash specified in
304           hexadecimal. This option enables data integrity checks using
305           dm-verity, if the used image contains the appropriate integrity
306           data (see above). The specified hash must match the root hash of
307           integrity data, and is usually at least 256 bits (and hence 64
308           formatted hexadecimal characters) long (in case of SHA256 for
309           example). If this option is not specified, but the image file
310           carries the "user.verity.roothash" extended file attribute (see
311           xattr(7)), then the root hash is read from it, also as formatted
312           hexadecimal characters. If the extended file attribute is not found
313           (or is not supported by the underlying file system), but a file
314           with the .roothash suffix is found next to the image file, bearing
315           otherwise the same name, the root hash is read from it and
316           automatically used, also as formatted hexadecimal characters.
317
318       --pivot-root=
319           Pivot the specified directory to / inside the container, and either
320           unmount the container's old root, or pivot it to another specified
321           directory. Takes one of: a path argument — in which case the
322           specified path will be pivoted to / and the old root will be
323           unmounted; or a colon-separated pair of new root path and pivot
324           destination for the old root. The new root path will be pivoted to
325           /, and the old / will be pivoted to the other directory. Both paths
326           must be absolute, and are resolved in the container's file system
327           namespace.
328
329           This is for containers which have several bootable directories in
330           them; for example, several OSTree[4] deployments. It emulates the
331           behavior of the boot loader and initial RAM disk which normally
332           select which directory to mount as the root and start the
333           container's PID 1 in.
334
335   Execution Options
336       -a, --as-pid2
337           Invoke the shell or specified program as process ID (PID) 2 instead
338           of PID 1 (init). By default, if neither this option nor --boot is
339           used, the selected program is run as the process with PID 1, a mode
340           only suitable for programs that are aware of the special semantics
341           that the process with PID 1 has on UNIX. For example, it needs to
342           reap all processes reparented to it, and should implement sysvinit
343           compatible signal handling (specifically: it needs to reboot on
344           SIGINT, reexecute on SIGTERM, reload configuration on SIGHUP, and
345           so on). With --as-pid2 a minimal stub init process is run as PID 1
346           and the selected program is executed as PID 2 (and hence does not
347           need to implement any special semantics). The stub init process
348           will reap processes as necessary and react appropriately to
349           signals. It is recommended to use this mode to invoke arbitrary
350           commands in containers, unless they have been modified to run
351           correctly as PID 1. Or in other words: this switch should be used
352           for pretty much all commands, except when the command refers to an
353           init or shell implementation, as these are generally capable of
354           running correctly as PID 1. This option may not be combined with
355           --boot.
356
357       -b, --boot
358           Automatically search for an init program and invoke it as PID 1,
359           instead of a shell or a user supplied program. If this option is
360           used, arguments specified on the command line are used as arguments
361           for the init program. This option may not be combined with
362           --as-pid2.
363
364           The following table explains the different modes of invocation and
365           relationship to --as-pid2 (see above):
366
367           Table 1. Invocation Mode
368           ┌──────────────────────┬────────────────────────────┐
369Switch                Explanation                
370           ├──────────────────────┼────────────────────────────┤
371           │Neither --as-pid2 nor │ The passed parameters are  │
372--boot specified      │ interpreted as the command │
373           │                      │ line, which is executed as │
374           │                      │ PID 1 in the container.    │
375           ├──────────────────────┼────────────────────────────┤
376--as-pid2 specified   │ The passed parameters are  │
377           │                      │ interpreted as the command │
378           │                      │ line, which is executed as │
379           │                      │ PID 2 in the container. A  │
380           │                      │ stub init process is run   │
381           │                      │ as PID 1.                  │
382           ├──────────────────────┼────────────────────────────┤
383--boot specified      │ An init program is         │
384           │                      │ automatically searched for │
385           │                      │ and run as PID 1 in the    │
386           │                      │ container. The passed      │
387           │                      │ parameters are used as     │
388           │                      │ invocation parameters for  │
389           │                      │ this process.              │
390           └──────────────────────┴────────────────────────────┘
391           Note that --boot is the default mode of operation if the
392           systemd-nspawn@.service template unit file is used.
393
394       --chdir=
395           Change to the specified working directory before invoking the
396           process in the container. Expects an absolute path in the
397           container's file system namespace.
398
399       -E NAME=VALUE, --setenv=NAME=VALUE
400           Specifies an environment variable assignment to pass to the init
401           process in the container, in the format "NAME=VALUE". This may be
402           used to override the default variables or to set additional
403           variables. This parameter may be used more than once.
404
405       -u, --user=
406           After transitioning into the container, change to the specified
407           user-defined in the container's user database. Like all other
408           systemd-nspawn features, this is not a security feature and
409           provides protection against accidental destructive operations only.
410
411       --kill-signal=
412           Specify the process signal to send to the container's PID 1 when
413           nspawn itself receives SIGTERM, in order to trigger an orderly
414           shutdown of the container. Defaults to SIGRTMIN+3 if --boot is used
415           (on systemd-compatible init systems SIGRTMIN+3 triggers an orderly
416           shutdown). If --boot is not used and this option is not specified
417           the container's processes are terminated abruptly via SIGKILL. For
418           a list of valid signals, see signal(7).
419
420       --notify-ready=
421           Configures support for notifications from the container's init
422           process.  --notify-ready= takes a boolean (no and yes). With option
423           no systemd-nspawn notifies systemd with a "READY=1" message when
424           the init process is created. With option yes systemd-nspawn waits
425           for the "READY=1" message from the init process in the container
426           before sending its own to systemd. For more details about
427           notifications see sd_notify(3)).
428
429   System Identity Options
430       -M, --machine=
431           Sets the machine name for this container. This name may be used to
432           identify this container during its runtime (for example in tools
433           like machinectl(1) and similar), and is used to initialize the
434           container's hostname (which the container can choose to override,
435           however). If not specified, the last component of the root
436           directory path of the container is used, possibly suffixed with a
437           random identifier in case --ephemeral mode is selected. If the root
438           directory selected is the host's root directory the host's hostname
439           is used as default instead.
440
441       --hostname=
442           Controls the hostname to set within the container, if different
443           from the machine name. Expects a valid hostname as argument. If
444           this option is used, the kernel hostname of the container will be
445           set to this value, otherwise it will be initialized to the machine
446           name as controlled by the --machine= option described above. The
447           machine name is used for various aspect of identification of the
448           container from the outside, the kernel hostname configurable with
449           this option is useful for the container to identify itself from the
450           inside. It is usually a good idea to keep both forms of
451           identification synchronized, in order to avoid confusion. It is
452           hence recommended to avoid usage of this option, and use --machine=
453           exclusively. Note that regardless whether the container's hostname
454           is initialized from the name set with --hostname= or the one set
455           with --machine=, the container can later override its kernel
456           hostname freely on its own as well.
457
458       --uuid=
459           Set the specified UUID for the container. The init system will
460           initialize /etc/machine-id from this if this file is not set yet.
461           Note that this option takes effect only if /etc/machine-id in the
462           container is unpopulated.
463
464   Property Options
465       -S, --slice=
466           Make the container part of the specified slice, instead of the
467           default machine.slice. This applies only if the machine is run in
468           its own scope unit, i.e. if --keep-unit isn't used.
469
470       --property=
471           Set a unit property on the scope unit to register for the machine.
472           This applies only if the machine is run in its own scope unit, i.e.
473           if --keep-unit isn't used. Takes unit property assignments in the
474           same format as systemctl set-property. This is useful to set memory
475           limits and similar for container.
476
477       --register=
478           Controls whether the container is registered with systemd-
479           machined(8). Takes a boolean argument, which defaults to "yes".
480           This option should be enabled when the container runs a full
481           Operating System (more specifically: a system and service manager
482           as PID 1), and is useful to ensure that the container is accessible
483           via machinectl(1) and shown by tools such as ps(1). If the
484           container does not run a service manager, it is recommended to set
485           this option to "no".
486
487       --keep-unit
488           Instead of creating a transient scope unit to run the container in,
489           simply use the service or scope unit systemd-nspawn has been
490           invoked in. If --register=yes is set this unit is registered with
491           systemd-machined(8). This switch should be used if systemd-nspawn
492           is invoked from within a service unit, and the service unit's sole
493           purpose is to run a single systemd-nspawn container. This option is
494           not available if run from a user session.
495
496           Note that passing --keep-unit disables the effect of --slice= and
497           --property=. Use --keep-unit and --register=no in combination to
498           disable any kind of unit allocation or registration with
499           systemd-machined.
500
501   User Namespacing Options
502       --private-users=
503           Controls user namespacing. If enabled, the container will run with
504           its own private set of UNIX user and group ids (UIDs and GIDs).
505           This involves mapping the private UIDs/GIDs used in the container
506           (starting with the container's root user 0 and up) to a range of
507           UIDs/GIDs on the host that are not used for other purposes (usually
508           in the range beyond the host's UID/GID 65536). The parameter may be
509           specified as follows:
510
511            1. If one or two colon-separated numbers are specified, user
512               namespacing is turned on. The first parameter specifies the
513               first host UID/GID to assign to the container, the second
514               parameter specifies the number of host UIDs/GIDs to assign to
515               the container. If the second parameter is omitted, 65536
516               UIDs/GIDs are assigned.
517
518            2. If the parameter is omitted, or true, user namespacing is
519               turned on. The UID/GID range to use is determined automatically
520               from the file ownership of the root directory of the
521               container's directory tree. To use this option, make sure to
522               prepare the directory tree in advance, and ensure that all
523               files and directories in it are owned by UIDs/GIDs in the range
524               you'd like to use. Also, make sure that used file ACLs
525               exclusively reference UIDs/GIDs in the appropriate range. If
526               this mode is used the number of UIDs/GIDs assigned to the
527               container for use is 65536, and the UID/GID of the root
528               directory must be a multiple of 65536.
529
530            3. If the parameter is false, user namespacing is turned off. This
531               is the default.
532
533            4. The special value "pick" turns on user namespacing. In this
534               case the UID/GID range is automatically chosen. As first step,
535               the file owner of the root directory of the container's
536               directory tree is read, and it is checked that it is currently
537               not used by the system otherwise (in particular, that no other
538               container is using it). If this check is successful, the
539               UID/GID range determined this way is used, similar to the
540               behavior if "yes" is specified. If the check is not successful
541               (and thus the UID/GID range indicated in the root directory's
542               file owner is already used elsewhere) a new – currently unused
543               – UID/GID range of 65536 UIDs/GIDs is randomly chosen between
544               the host UID/GIDs of 524288 and 1878982656, always starting at
545               a multiple of 65536. This setting implies --private-users-chown
546               (see below), which has the effect that the files and
547               directories in the container's directory tree will be owned by
548               the appropriate users of the range picked. Using this option
549               makes user namespace behavior fully automatic. Note that the
550               first invocation of a previously unused container image might
551               result in picking a new UID/GID range for it, and thus in the
552               (possibly expensive) file ownership adjustment operation.
553               However, subsequent invocations of the container will be cheap
554               (unless of course the picked UID/GID range is assigned to a
555               different use by then).
556
557           It is recommended to assign at least 65536 UIDs/GIDs to each
558           container, so that the usable UID/GID range in the container covers
559           16 bit. For best security, do not assign overlapping UID/GID ranges
560           to multiple containers. It is hence a good idea to use the upper 16
561           bit of the host 32-bit UIDs/GIDs as container identifier, while the
562           lower 16 bit encode the container UID/GID used. This is in fact the
563           behavior enforced by the --private-users=pick option.
564
565           When user namespaces are used, the GID range assigned to each
566           container is always chosen identical to the UID range.
567
568           In most cases, using --private-users=pick is the recommended option
569           as it enhances container security massively and operates fully
570           automatically in most cases.
571
572           Note that the picked UID/GID range is not written to /etc/passwd or
573           /etc/group. In fact, the allocation of the range is not stored
574           persistently anywhere, except in the file ownership of the files
575           and directories of the container.
576
577           Note that when user namespacing is used file ownership on disk
578           reflects this, and all of the container's files and directories are
579           owned by the container's effective user and group IDs. This means
580           that copying files from and to the container image requires
581           correction of the numeric UID/GID values, according to the UID/GID
582           shift applied.
583
584       --private-users-chown
585           If specified, all files and directories in the container's
586           directory tree will be adjusted so that they are owned by the
587           appropriate UIDs/GIDs selected for the container (see above). This
588           operation is potentially expensive, as it involves iterating
589           through the full directory tree of the container. Besides actual
590           file ownership, file ACLs are adjusted as well.
591
592           This option is implied if --private-users=pick is used. This option
593           has no effect if user namespacing is not used.
594
595       -U
596           If the kernel supports the user namespaces feature, equivalent to
597           --private-users=pick --private-users-chown, otherwise equivalent to
598           --private-users=no.
599
600           Note that -U is the default if the systemd-nspawn@.service template
601           unit file is used.
602
603           Note: it is possible to undo the effect of --private-users-chown
604           (or -U) on the file system by redoing the operation with the first
605           UID of 0:
606
607               systemd-nspawn ... --private-users=0 --private-users-chown
608
609   Networking Options
610       --private-network
611           Disconnect networking of the container from the host. This makes
612           all network interfaces unavailable in the container, with the
613           exception of the loopback device and those specified with
614           --network-interface= and configured with --network-veth. If this
615           option is specified, the CAP_NET_ADMIN capability will be added to
616           the set of capabilities the container retains. The latter may be
617           disabled by using --drop-capability=. If this option is not
618           specified (or implied by one of the options listed below), the
619           container will have full access to the host network.
620
621       --network-interface=
622           Assign the specified network interface to the container. This will
623           remove the specified interface from the calling namespace and place
624           it in the container. When the container terminates, it is moved
625           back to the host namespace. Note that --network-interface= implies
626           --private-network. This option may be used more than once to add
627           multiple network interfaces to the container.
628
629       --network-macvlan=
630           Create a "macvlan" interface of the specified Ethernet network
631           interface and add it to the container. A "macvlan" interface is a
632           virtual interface that adds a second MAC address to an existing
633           physical Ethernet link. The interface in the container will be
634           named after the interface on the host, prefixed with "mv-". Note
635           that --network-macvlan= implies --private-network. This option may
636           be used more than once to add multiple network interfaces to the
637           container.
638
639       --network-ipvlan=
640           Create an "ipvlan" interface of the specified Ethernet network
641           interface and add it to the container. An "ipvlan" interface is a
642           virtual interface, similar to a "macvlan" interface, which uses the
643           same MAC address as the underlying interface. The interface in the
644           container will be named after the interface on the host, prefixed
645           with "iv-". Note that --network-ipvlan= implies --private-network.
646           This option may be used more than once to add multiple network
647           interfaces to the container.
648
649       -n, --network-veth
650           Create a virtual Ethernet link ("veth") between host and container.
651           The host side of the Ethernet link will be available as a network
652           interface named after the container's name (as specified with
653           --machine=), prefixed with "ve-". The container side of the
654           Ethernet link will be named "host0". The --network-veth option
655           implies --private-network.
656
657           Note that systemd-networkd.service(8) includes by default a network
658           file /usr/lib/systemd/network/80-container-ve.network matching the
659           host-side interfaces created this way, which contains settings to
660           enable automatic address provisioning on the created virtual link
661           via DHCP, as well as automatic IP routing onto the host's external
662           network interfaces. It also contains
663           /usr/lib/systemd/network/80-container-host0.network matching the
664           container-side interface created this way, containing settings to
665           enable client side address assignment via DHCP. In case
666           systemd-networkd is running on both the host and inside the
667           container, automatic IP communication from the container to the
668           host is thus available, with further connectivity to the external
669           network.
670
671           Note that --network-veth is the default if the
672           systemd-nspawn@.service template unit file is used.
673
674           Note that on Linux network interface names may have a length of 15
675           characters at maximum, while container names may have a length up
676           to 64 characters. As this option derives the host-side interface
677           name from the container name the name is possibly truncated. Thus,
678           care needs to be taken to ensure that interface names remain unique
679           in this case, or even better container names are generally not
680           chosen longer than 12 characters, to avoid the truncation.
681           Alternatively, the --network-veth-extra= option may be used, which
682           allows free configuration of the host-side interface name
683           independently of the container name — but might require a bit more
684           additional configuration in case bridging in a fashion similar to
685           --network-bridge= is desired.
686
687       --network-veth-extra=
688           Adds an additional virtual Ethernet link between host and
689           container. Takes a colon-separated pair of host interface name and
690           container interface name. The latter may be omitted in which case
691           the container and host sides will be assigned the same name. This
692           switch is independent of --network-veth, and — in contrast — may be
693           used multiple times, and allows configuration of the network
694           interface names. Note that --network-bridge= has no effect on
695           interfaces created with --network-veth-extra=.
696
697       --network-bridge=
698           Adds the host side of the Ethernet link created with --network-veth
699           to the specified Ethernet bridge interface. Expects a valid network
700           interface name of a bridge device as argument. Note that
701           --network-bridge= implies --network-veth. If this option is used,
702           the host side of the Ethernet link will use the "vb-" prefix
703           instead of "ve-". Regardless of the used naming prefix the same
704           network interface name length limits imposed by Linux apply, along
705           with the complications this creates (for details see above).
706
707       --network-zone=
708           Creates a virtual Ethernet link ("veth") to the container and adds
709           it to an automatically managed Ethernet bridge interface. The
710           bridge interface is named after the passed argument, prefixed with
711           "vz-". The bridge interface is automatically created when the first
712           container configured for its name is started, and is automatically
713           removed when the last container configured for its name exits.
714           Hence, each bridge interface configured this way exists only as
715           long as there's at least one container referencing it running. This
716           option is very similar to --network-bridge=, besides this automatic
717           creation/removal of the bridge device.
718
719           This setting makes it easy to place multiple related containers on
720           a common, virtual Ethernet-based broadcast domain, here called a
721           "zone". Each container may only be part of one zone, but each zone
722           may contain any number of containers. Each zone is referenced by
723           its name. Names may be chosen freely (as long as they form valid
724           network interface names when prefixed with "vz-"), and it is
725           sufficient to pass the same name to the --network-zone= switch of
726           the various concurrently running containers to join them in one
727           zone.
728
729           Note that systemd-networkd.service(8) includes by default a network
730           file /usr/lib/systemd/network/80-container-vz.network matching the
731           bridge interfaces created this way, which contains settings to
732           enable automatic address provisioning on the created virtual
733           network via DHCP, as well as automatic IP routing onto the host's
734           external network interfaces. Using --network-zone= is hence in most
735           cases fully automatic and sufficient to connect multiple local
736           containers in a joined broadcast domain to the host, with further
737           connectivity to the external network.
738
739       --network-namespace-path=
740           Takes the path to a file representing a kernel network namespace
741           that the container shall run in. The specified path should refer to
742           a (possibly bind-mounted) network namespace file, as exposed by the
743           kernel below /proc/$PID/ns/net. This makes the container enter the
744           given network namespace. One of the typical use cases is to give a
745           network namespace under /run/netns created by ip-netns(8), for
746           example, --network-namespace-path=/run/netns/foo. Note that this
747           option cannot be used together with other network-related options,
748           such as --private-network or --network-interface=.
749
750       -p, --port=
751           If private networking is enabled, maps an IP port on the host onto
752           an IP port on the container. Takes a protocol specifier (either
753           "tcp" or "udp"), separated by a colon from a host port number in
754           the range 1 to 65535, separated by a colon from a container port
755           number in the range from 1 to 65535. The protocol specifier and its
756           separating colon may be omitted, in which case "tcp" is assumed.
757           The container port number and its colon may be omitted, in which
758           case the same port as the host port is implied. This option is only
759           supported if private networking is used, such as with
760           --network-veth, --network-zone= --network-bridge=.
761
762   Security Options
763       --capability=
764           List one or more additional capabilities to grant the container.
765           Takes a comma-separated list of capability names, see
766           capabilities(7) for more information. Note that the following
767           capabilities will be granted in any way: CAP_AUDIT_CONTROL,
768           CAP_AUDIT_WRITE, CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH,
769           CAP_FOWNER, CAP_FSETID, CAP_IPC_OWNER, CAP_KILL, CAP_LEASE,
770           CAP_LINUX_IMMUTABLE, CAP_MKNOD, CAP_NET_BIND_SERVICE,
771           CAP_NET_BROADCAST, CAP_NET_RAW, CAP_SETFCAP, CAP_SETGID,
772           CAP_SETPCAP, CAP_SETUID, CAP_SYS_ADMIN, CAP_SYS_BOOT,
773           CAP_SYS_CHROOT, CAP_SYS_NICE, CAP_SYS_PTRACE, CAP_SYS_RESOURCE,
774           CAP_SYS_TTY_CONFIG. Also CAP_NET_ADMIN is retained if
775           --private-network is specified. If the special value "all" is
776           passed, all capabilities are retained.
777
778       --drop-capability=
779           Specify one or more additional capabilities to drop for the
780           container. This allows running the container with fewer
781           capabilities than the default (see above).
782
783       --no-new-privileges=
784           Takes a boolean argument. Specifies the value of the
785           PR_SET_NO_NEW_PRIVS flag for the container payload. Defaults to
786           off. When turned on the payload code of the container cannot
787           acquire new privileges, i.e. the "setuid" file bit as well as file
788           system capabilities will not have an effect anymore. See prctl(2)
789           for details about this flag.
790
791       --system-call-filter=
792           Alter the system call filter applied to containers. Takes a
793           space-separated list of system call names or group names (the
794           latter prefixed with "@", as listed by the syscall-filter command
795           of systemd-analyze(1)). Passed system calls will be permitted. The
796           list may optionally be prefixed by "~", in which case all listed
797           system calls are prohibited. If this command line option is used
798           multiple times the configured lists are combined. If both a
799           positive and a negative list (that is one system call list without
800           and one with the "~" prefix) are configured, the negative list
801           takes precedence over the positive list. Note that systemd-nspawn
802           always implements a system call whitelist (as opposed to a
803           blacklist), and this command line option hence adds or removes
804           entries from the default whitelist, depending on the "~" prefix.
805           Note that the applied system call filter is also altered implicitly
806           if additional capabilities are passed using the --capabilities=.
807
808       -Z, --selinux-context=
809           Sets the SELinux security context to be used to label processes in
810           the container.
811
812       -L, --selinux-apifs-context=
813           Sets the SELinux security context to be used to label files in the
814           virtual API file systems in the container.
815
816   Resource Options
817       --rlimit=
818           Sets the specified POSIX resource limit for the container payload.
819           Expects an assignment of the form "LIMIT=SOFT:HARD" or
820           "LIMIT=VALUE", where LIMIT should refer to a resource limit type,
821           such as RLIMIT_NOFILE or RLIMIT_NICE. The SOFT and HARD fields
822           should refer to the numeric soft and hard resource limit values. If
823           the second form is used, VALUE may specify a value that is used
824           both as soft and hard limit. In place of a numeric value the
825           special string "infinity" may be used to turn off resource limiting
826           for the specific type of resource. This command line option may be
827           used multiple times to control limits on multiple limit types. If
828           used multiple times for the same limit type, the last use wins. For
829           details about resource limits see setrlimit(2). By default resource
830           limits for the container's init process (PID 1) are set to the same
831           values the Linux kernel originally passed to the host init system.
832           Note that some resource limits are enforced on resources counted
833           per user, in particular RLIMIT_NPROC. This means that unless user
834           namespacing is deployed (i.e.  --private-users= is used, see
835           above), any limits set will be applied to the resource usage of the
836           same user on all local containers as well as the host. This means
837           particular care needs to be taken with these limits as they might
838           be triggered by possibly less trusted code. Example:
839           "--rlimit=RLIMIT_NOFILE=8192:16384".
840
841       --oom-score-adjust=
842           Changes the OOM ("Out Of Memory") score adjustment value for the
843           container payload. This controls /proc/self/oom_score_adj which
844           influences the preference with which this container is terminated
845           when memory becomes scarce. For details see proc(5). Takes an
846           integer in the range -1000...1000.
847
848       --cpu-affinity=
849           Controls the CPU affinity of the container payload. Takes a comma
850           separated list of CPU numbers or number ranges (the latter's start
851           and end value separated by dashes). See sched_setaffinity(2) for
852           details.
853
854       --personality=
855           Control the architecture ("personality") reported by uname(2) in
856           the container. Currently, only "x86" and "x86-64" are supported.
857           This is useful when running a 32-bit container on a 64-bit host. If
858           this setting is not used, the personality reported in the container
859           is the same as the one reported on the host.
860
861   Integration Options
862       --resolv-conf=
863           Configures how /etc/resolv.conf inside of the container (i.e. DNS
864           configuration synchronization from host to container) shall be
865           handled. Takes one of "off", "copy-host", "copy-static",
866           "bind-host", "bind-static", "delete" or "auto". If set to "off" the
867           /etc/resolv.conf file in the container is left as it is included in
868           the image, and neither modified nor bind mounted over. If set to
869           "copy-host", the /etc/resolv.conf file from the host is copied into
870           the container. Similar, if "bind-host" is used, the file is bind
871           mounted from the host into the container. If set to "copy-static"
872           the static resolv.conf file supplied with systemd-
873           resolved.service(8) is copied into the container, and
874           correspondingly "bind-static" bind mounts it there. If set to
875           "delete" the /etc/resolv.conf file in the container is deleted if
876           it exists. Finally, if set to "auto" the file is left as it is if
877           private networking is turned on (see --private-network). Otherwise,
878           if systemd-resolved.service is connectible its static resolv.conf
879           file is used, and if not the host's /etc/resolv.conf file is used.
880           In the latter cases the file is copied if the image is writable,
881           and bind mounted otherwise. It's recommended to use "copy" if the
882           container shall be able to make changes to the DNS configuration on
883           its own, deviating from the host's settings. Otherwise "bind" is
884           preferable, as it means direct changes to /etc/resolv.conf in the
885           container are not allowed, as it is a read-only bind mount (but
886           note that if the container has enough privileges, it might simply
887           go ahead and unmount the bind mount anyway). Note that both if the
888           file is bind mounted and if it is copied no further propagation of
889           configuration is generally done after the one-time early
890           initialization (this is because the file is usually updated through
891           copying and renaming). Defaults to "auto".
892
893       --timezone=
894           Configures how /etc/localtime inside of the container (i.e. local
895           timezone synchronization from host to container) shall be handled.
896           Takes one of "off", "copy", "bind", "symlink", "delete" or "auto".
897           If set to "off" the /etc/localtime file in the container is left as
898           it is included in the image, and neither modified nor bind mounted
899           over. If set to "copy" the /etc/localtime file of the host is
900           copied into the container. Similar, if "bind" is used, it is bind
901           mounted from the host into the container. If set to "symlink" a
902           symlink from /etc/localtime in the container is created pointing to
903           the matching the timezone file of the container that matches the
904           timezone setting on the host. If set to "delete" the file in the
905           container is deleted, should it exist. If set to "auto" and the
906           /etc/localtime file of the host is a symlink, then "symlink" mode
907           is used, and "copy" otherwise, except if the image is read-only in
908           which case "bind" is used instead. Defaults to "auto".
909
910       --link-journal=
911           Control whether the container's journal shall be made visible to
912           the host system. If enabled, allows viewing the container's journal
913           files from the host (but not vice versa). Takes one of "no",
914           "host", "try-host", "guest", "try-guest", "auto". If "no", the
915           journal is not linked. If "host", the journal files are stored on
916           the host file system (beneath /var/log/journal/machine-id) and the
917           subdirectory is bind-mounted into the container at the same
918           location. If "guest", the journal files are stored on the guest
919           file system (beneath /var/log/journal/machine-id) and the
920           subdirectory is symlinked into the host at the same location.
921           "try-host" and "try-guest" do the same but do not fail if the host
922           does not have persistent journaling enabled. If "auto" (the
923           default), and the right subdirectory of /var/log/journal exists, it
924           will be bind mounted into the container. If the subdirectory does
925           not exist, no linking is performed. Effectively, booting a
926           container once with "guest" or "host" will link the journal
927           persistently if further on the default of "auto" is used.
928
929           Note that --link-journal=try-guest is the default if the
930           systemd-nspawn@.service template unit file is used.
931
932       -j
933           Equivalent to --link-journal=try-guest.
934
935   Mount Options
936       --bind=, --bind-ro=
937           Bind mount a file or directory from the host into the container.
938           Takes one of: a path argument — in which case the specified path
939           will be mounted from the host to the same path in the container, or
940           a colon-separated pair of paths — in which case the first specified
941           path is the source in the host, and the second path is the
942           destination in the container, or a colon-separated triple of source
943           path, destination path and mount options. The source path may
944           optionally be prefixed with a "+" character. If so, the source path
945           is taken relative to the image's root directory. This permits
946           setting up bind mounts within the container image. The source path
947           may be specified as empty string, in which case a temporary
948           directory below the host's /var/tmp directory is used. It is
949           automatically removed when the container is shut down. Mount
950           options are comma-separated and currently, only rbind and norbind
951           are allowed, controlling whether to create a recursive or a regular
952           bind mount. Defaults to "rbind". Backslash escapes are interpreted,
953           so "\:" may be used to embed colons in either path. This option may
954           be specified multiple times for creating multiple independent bind
955           mount points. The --bind-ro= option creates read-only bind mounts.
956
957           Note that when this option is used in combination with
958           --private-users, the resulting mount points will be owned by the
959           nobody user. That's because the mount and its files and directories
960           continue to be owned by the relevant host users and groups, which
961           do not exist in the container, and thus show up under the wildcard
962           UID 65534 (nobody). If such bind mounts are created, it is
963           recommended to make them read-only, using --bind-ro=.
964
965       --inaccessible=
966           Make the specified path inaccessible in the container. This
967           over-mounts the specified path (which must exist in the container)
968           with a file node of the same type that is empty and has the most
969           restrictive access mode supported. This is an effective way to mask
970           files, directories and other file system objects from the container
971           payload. This option may be used more than once in case all
972           specified paths are masked.
973
974       --tmpfs=
975           Mount a tmpfs file system into the container. Takes a single
976           absolute path argument that specifies where to mount the tmpfs
977           instance to (in which case the directory access mode will be chosen
978           as 0755, owned by root/root), or optionally a colon-separated pair
979           of path and mount option string that is used for mounting (in which
980           case the kernel default for access mode and owner will be chosen,
981           unless otherwise specified). Backslash escapes are interpreted in
982           the path, so "\:" may be used to embed colons in the path.
983
984           Note that this option cannot be used to replace the root file
985           system of the container with a temporary file system. However, the
986           --volatile= option described below provides similar functionality,
987           with a focus on implementing stateless operating system images.
988
989       --overlay=, --overlay-ro=
990           Combine multiple directory trees into one overlay file system and
991           mount it into the container. Takes a list of colon-separated paths
992           to the directory trees to combine and the destination mount point.
993
994           Backslash escapes are interpreted in the paths, so "\:" may be used
995           to embed colons in the paths.
996
997           If three or more paths are specified, then the last specified path
998           is the destination mount point in the container, all paths
999           specified before refer to directory trees on the host and are
1000           combined in the specified order into one overlay file system. The
1001           left-most path is hence the lowest directory tree, the
1002           second-to-last path the highest directory tree in the stacking
1003           order. If --overlay-ro= is used instead of --overlay=, a read-only
1004           overlay file system is created. If a writable overlay file system
1005           is created, all changes made to it are written to the highest
1006           directory tree in the stacking order, i.e. the second-to-last
1007           specified.
1008
1009           If only two paths are specified, then the second specified path is
1010           used both as the top-level directory tree in the stacking order as
1011           seen from the host, as well as the mount point for the overlay file
1012           system in the container. At least two paths have to be specified.
1013
1014           The source paths may optionally be prefixed with "+" character. If
1015           so they are taken relative to the image's root directory. The
1016           uppermost source path may also be specified as empty string, in
1017           which case a temporary directory below the host's /var/tmp is used.
1018           The directory is removed automatically when the container is shut
1019           down. This behaviour is useful in order to make read-only container
1020           directories writable while the container is running. For example,
1021           use the "--overlay=+/var::/var" option in order to automatically
1022           overlay a writable temporary directory on a read-only /var
1023           directory.
1024
1025           For details about overlay file systems, see overlayfs.txt[5]. Note
1026           that the semantics of overlay file systems are substantially
1027           different from normal file systems, in particular regarding
1028           reported device and inode information. Device and inode information
1029           may change for a file while it is being written to, and processes
1030           might see out-of-date versions of files at times. Note that this
1031           switch automatically derives the "workdir=" mount option for the
1032           overlay file system from the top-level directory tree, making it a
1033           sibling of it. It is hence essential that the top-level directory
1034           tree is not a mount point itself (since the working directory must
1035           be on the same file system as the top-most directory tree). Also
1036           note that the "lowerdir=" mount option receives the paths to stack
1037           in the opposite order of this switch.
1038
1039           Note that this option cannot be used to replace the root file
1040           system of the container with an overlay file system. However, the
1041           --volatile= option described above provides similar functionality,
1042           with a focus on implementing stateless operating system images.
1043
1044   Input/Output Options
1045       --console=MODE
1046           Configures how to set up standard input, output and error output
1047           for the container payload, as well as the /dev/console device for
1048           the container. Takes one of interactive, read-only, passive or
1049           pipe. If interactive a pseudo-TTY is allocated and made available
1050           as /dev/console in the container. It is then bi-directionally
1051           connected to the standard input and output passed to
1052           systemd-nspawn.  read-only is similar but only the output of the
1053           container is propagated and no input from the caller is read. In
1054           passive mode a pseudo TTY is allocated, but it is not connected
1055           anywhere. Finally, in pipe mode no pseudo TTY is allocated, but the
1056           passed standard input, output and error output file descriptors are
1057           passed on — as they are — to the container payload. In this mode
1058           /dev/console will not exist in the container. Note that in this
1059           mode the container payload generally cannot be a full init system
1060           as init systems tend to require /dev/console to be available. On
1061           the other hand, in this mode container invocations can be used
1062           within shell pipelines. This is because intermediary pseudo TTYs do
1063           not permit independent bidirectional propagation of the end-of-file
1064           (EOF) condition, which is necessary for shell pipelines to work
1065           correctly.
1066
1067           Note that the pipe mode should be used carefully, as passing
1068           arbitrary file descriptors to less trusted container payloads might
1069           open up unwanted interfaces for access by the container payload.
1070           For example, if a passed file descriptor refers to a TTY of some
1071           form, APIs such as TIOCSTI may be used to synthesize input that
1072           might be used for escaping the container. Hence pipe mode should
1073           only be used if the payload is sufficiently trusted or when the
1074           standard input/output/error output file descriptors are known safe,
1075           for example pipes. Defaults to interactive if systemd-nspawn is
1076           invoked from a terminal, and read-only otherwise.
1077
1078       --pipe, -P
1079           Equivalent to --console=pipe.
1080
1081       --no-pager
1082           Do not pipe output into a pager.
1083
1084       -h, --help
1085           Print a short help text and exit.
1086
1087       --version
1088           Print a short version string and exit.
1089

ENVIRONMENT

1091       $SYSTEMD_PAGER
1092           Pager to use when --no-pager is not given; overrides $PAGER. If
1093           neither $SYSTEMD_PAGER nor $PAGER are set, a set of well-known
1094           pager implementations are tried in turn, including less(1) and
1095           more(1), until one is found. If no pager implementation is
1096           discovered no pager is invoked. Setting this environment variable
1097           to an empty string or the value "cat" is equivalent to passing
1098           --no-pager.
1099
1100       $SYSTEMD_LESS
1101           Override the options passed to less (by default "FRSXMK").
1102
1103           Users might want to change two options in particular:
1104
1105           K
1106               This option instructs the pager to exit immediately when Ctrl+C
1107               is pressed. To allow less to handle Ctrl+C itself to switch
1108               back to the pager command prompt, unset this option.
1109
1110               If the value of $SYSTEMD_LESS does not include "K", and the
1111               pager that is invoked is less, Ctrl+C will be ignored by the
1112               executable, and needs to be handled by the pager.
1113
1114           X
1115               This option instructs the pager to not send termcap
1116               initialization and deinitialization strings to the terminal. It
1117               is set by default to allow command output to remain visible in
1118               the terminal even after the pager exits. Nevertheless, this
1119               prevents some pager functionality from working, in particular
1120               paged output cannot be scrolled with the mouse.
1121
1122           See less(1) for more discussion.
1123
1124       $SYSTEMD_LESSCHARSET
1125           Override the charset passed to less (by default "utf-8", if the
1126           invoking terminal is determined to be UTF-8 compatible).
1127
1128       $SYSTEMD_COLORS
1129           The value must be a boolean. Controls whether colorized output
1130           should be generated. This can be specified to override the decision
1131           that systemd makes based on $TERM and what the console is connected
1132           to.
1133
1134       $SYSTEMD_URLIFY
1135           The value must be a boolean. Controls whether clickable links
1136           should be generated in the output for terminal emulators supporting
1137           this. This can be specified to override the decision that systemd
1138           makes based on $TERM and other conditions.
1139

EXAMPLES

1141       Example 1. Download a Fedora image and start a shell in it
1142
1143           # machinectl pull-raw --verify=no \
1144                 https://download.fedoraproject.org/pub/fedora/linux/releases/30/Cloud/x86_64/images/Fedora-Cloud-Base-30-1.2.x86_64.raw.xz \
1145                 Fedora-Cloud-Base-30-1.2.x86-64
1146           # systemd-nspawn -M Fedora-Cloud-Base-30-1.2.x86-64
1147
1148       This downloads an image using machinectl(1) and opens a shell in it.
1149
1150       Example 2. Build and boot a minimal Fedora distribution in a container
1151
1152           # dnf -y --releasever=30 --installroot=/var/lib/machines/f30 \
1153                 --disablerepo='*' --enablerepo=fedora --enablerepo=updates install \
1154                 systemd passwd dnf fedora-release vim-minimal
1155           # systemd-nspawn -bD /var/lib/machines/f30
1156
1157       This installs a minimal Fedora distribution into the directory
1158       /var/lib/machines/f30 and then boots an OS in a namespace container in
1159       it. Because the installation is located underneath the standard
1160       /var/lib/machines/ directory, it is also possible to start the machine
1161       using systemd-nspawn -M f30.
1162
1163       Example 3. Spawn a shell in a container of a minimal Debian unstable
1164       distribution
1165
1166           # debootstrap unstable ~/debian-tree/
1167           # systemd-nspawn -D ~/debian-tree/
1168
1169       This installs a minimal Debian unstable distribution into the directory
1170       ~/debian-tree/ and then spawns a shell in a namespace container in it.
1171
1172       debootstrap supports Debian[7], Ubuntu[8], and Tanglu[9] out of the
1173       box, so the same command can be used to install any of those. For other
1174       distributions from the Debian family, a mirror has to be specified, see
1175       debootstrap(8).
1176
1177       Example 4. Boot a minimal Arch Linux distribution in a container
1178
1179           # pacstrap -c ~/arch-tree/ base
1180           # systemd-nspawn -bD ~/arch-tree/
1181
1182       This installs a minimal Arch Linux distribution into the directory
1183       ~/arch-tree/ and then boots an OS in a namespace container in it.
1184
1185       Example 5. Install the OpenSUSE Tumbleweed rolling distribution
1186
1187           # zypper --root=/var/lib/machines/tumbleweed ar -c \
1188                 https://download.opensuse.org/tumbleweed/repo/oss tumbleweed
1189           # zypper --root=/var/lib/machines/tumbleweed refresh
1190           # zypper --root=/var/lib/machines/tumbleweed install --no-recommends \
1191                 systemd shadow zypper openSUSE-release vim
1192           # systemd-nspawn -M tumbleweed passwd root
1193           # systemd-nspawn -M tumbleweed -b
1194
1195       Example 6. Boot into an ephemeral snapshot of the host system
1196
1197           # systemd-nspawn -D / -xb
1198
1199       This runs a copy of the host system in a snapshot which is removed
1200       immediately when the container exits. All file system changes made
1201       during runtime will be lost on shutdown, hence.
1202
1203       Example 7. Run a container with SELinux sandbox security contexts
1204
1205           # chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 -R /srv/container
1206           # systemd-nspawn -L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \
1207                 -Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 -D /srv/container /bin/sh
1208
1209       Example 8. Run a container with an OSTree deployment
1210
1211           # systemd-nspawn -b -i ~/image.raw \
1212                 --pivot-root=/ostree/deploy/$OS/deploy/$CHECKSUM:/sysroot \
1213                 --bind=+/sysroot/ostree/deploy/$OS/var:/var
1214

EXIT STATUS

1216       The exit code of the program executed in the container is returned.
1217

SEE ALSO

1219       systemd(1), systemd.nspawn(5), chroot(1), dnf(8), debootstrap(8),
1220       pacman(8), zypper(8), systemd.slice(5), machinectl(1), btrfs(8)
1221

NOTES

1223        1. Container Interface
1224           https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface
1225
1226        2. Discoverable Partitions Specification
1227           https://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
1228
1229        3. OCI Runtime Specification
1230           https://github.com/opencontainers/runtime-spec/blob/master/spec.md
1231
1232        4. OSTree
1233           https://ostree.readthedocs.io/en/latest/
1234
1235        5. overlayfs.txt
1236           https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt
1237
1238        6. Fedora
1239           https://getfedora.org
1240
1241        7. Debian
1242           https://www.debian.org
1243
1244        8. Ubuntu
1245           https://www.ubuntu.com
1246
1247        9. Tanglu
1248           https://www.tanglu.org
1249
1250       10. Arch Linux
1251           https://www.archlinux.org
1252
1253       11. OpenSUSE Tumbleweed
1254           https://software.opensuse.org/distributions/tumbleweed
1255
1256
1257
1258systemd 243                                                  SYSTEMD-NSPAWN(1)
Impressum