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/.
32       The host's network interfaces and the system clock may not be changed
33       from within the container. Device nodes may not be created. The host
34       system cannot be rebooted and kernel modules may not be loaded from
35       within the 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       booting a container (see os-release(5)). It might be necessary to add
45       this file to the container tree manually if the OS of the container is
46       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 option which is not the default in
56       case systemd-nspawn is invoked from the interactive command line.
57       Further differences with the defaults are documented along with the
58       various 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
74       outside of the container, and their contents will be lost when the
75       container 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       Rather use machinectl(1)'s login or shell commands to request an
82       additional 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 --boot is specified, the arguments are used as arguments for
92       the init program. Otherwise, COMMAND specifies the program to launch in
93       the container, and the remaining arguments are used as arguments for
94       this program. If --boot is not used and no arguments are specified, a
95       shell 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 hostname, 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 hostname, 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           Single file system images (i.e. file systems without a surrounding
224           partition table) can be opened using dm-verity if the integrity
225           data is passed using the --root-hash= and --verity-data= (and
226           optionally --root-hash-sig=) options.
227
228           Any other partitions, such as foreign partitions or swap partitions
229           are not mounted. May not be specified together with --directory=,
230           --template=.
231
232       --oci-bundle=
233           Takes the path to an OCI runtime bundle to invoke, as specified in
234           the OCI Runtime Specification[3]. In this case no .nspawn file is
235           loaded, and the root directory and various settings are read from
236           the OCI runtime JSON data (but data passed on the command line
237           takes precedence).
238
239       --read-only
240           Mount the container's root file system (and any other file systems
241           container in the container image) read-only. This has no effect on
242           additional mounts made with --bind=, --tmpfs= and similar options.
243           This mode is implied if the container image file or directory is
244           marked read-only itself. It is also implied if --volatile= is used.
245           In this case the container image on disk is strictly read-only,
246           while changes are permitted but kept non-persistently in memory
247           only. For further details, see below.
248
249       --volatile, --volatile=MODE
250           Boots the container in volatile mode. When no mode parameter is
251           passed or when mode is specified as yes, full volatile mode is
252           enabled. This means the root directory is mounted as a mostly
253           unpopulated "tmpfs" instance, and /usr/ from the OS tree is mounted
254           into it in read-only mode (the system thus starts up with read-only
255           OS image, but pristine state and configuration, any changes are
256           lost on shutdown). When the mode parameter is specified as state,
257           the OS tree is mounted read-only, but /var/ is mounted as a
258           writable "tmpfs" instance into it (the system thus starts up with
259           read-only OS resources and configuration, but pristine state, and
260           any changes to the latter are lost on shutdown). When the mode
261           parameter is specified as overlay the read-only root file system is
262           combined with a writable tmpfs instance through "overlayfs", so
263           that it appears at it normally would, but any changes are applied
264           to the temporary file system only and lost when the container is
265           terminated. When the mode parameter is specified as no (the
266           default), the whole OS tree is made available writable (unless
267           --read-only is specified, see above).
268
269           Note that if one of the volatile modes is chosen, its effect is
270           limited to the root file system (or /var/ in case of state), and
271           any other mounts placed in the hierarchy are unaffected —
272           regardless if they are established automatically (e.g. the EFI
273           system partition that might be mounted to /efi/ or /boot/) or
274           explicitly (e.g. through an additional command line option such as
275           --bind=, see below). This means, even if --volatile=overlay is used
276           changes to /efi/ or /boot/ are prohibited in case such a partition
277           exists in the container image operated on, and even if
278           --volatile=state is used the hypothetical file /etc/foobar is
279           potentially writable if --bind=/etc/foobar if used to mount it from
280           outside the read-only container /etc/ directory.
281
282           The --ephemeral option is closely related to this setting, and
283           provides similar behaviour by making a temporary, ephemeral copy of
284           the whole OS image and executing that. For further details, see
285           above.
286
287           The --tmpfs= and --overlay= options provide similar functionality,
288           but for specific sub-directories of the OS image only. For details,
289           see below.
290
291           This option provides similar functionality for containers as the
292           "systemd.volatile=" kernel command line switch provides for host
293           systems. See kernel-command-line(7) for details.
294
295           Note that setting this option to yes or state will only work
296           correctly with operating systems in the container that can boot up
297           with only /usr/ mounted, and are able to automatically populate
298           /var/ (and /etc/ in case of "--volatile=yes"). Specifically, this
299           means that operating systems that follow the historic split of
300           /bin/ and /lib/ (and related directories) from /usr/ (i.e. where
301           the former are not symlinks into the latter) are not supported by
302           "--volatile=yes" as container payload. The overlay option does not
303           require any particular preparations in the OS, but do note that
304           "overlayfs" behaviour differs from regular file systems in a number
305           of ways, and hence compatibility is limited.
306
307       --root-hash=
308           Takes a data integrity (dm-verity) root hash specified in
309           hexadecimal. This option enables data integrity checks using
310           dm-verity, if the used image contains the appropriate integrity
311           data (see above). The specified hash must match the root hash of
312           integrity data, and is usually at least 256 bits (and hence 64
313           formatted hexadecimal characters) long (in case of SHA256 for
314           example). If this option is not specified, but the image file
315           carries the "user.verity.roothash" extended file attribute (see
316           xattr(7)), then the root hash is read from it, also as formatted
317           hexadecimal characters. If the extended file attribute is not found
318           (or is not supported by the underlying file system), but a file
319           with the .roothash suffix is found next to the image file, bearing
320           otherwise the same name (except if the image has the .raw suffix,
321           in which case the root hash file must not have it in its name), the
322           root hash is read from it and automatically used, also as formatted
323           hexadecimal characters.
324
325           Note that this configures the root hash for the root file system.
326           Disk images may also contain separate file systems for the /usr/
327           hierarchy, which may be Verity protected as well. The root hash for
328           this protection may be configured via the "user.verity.usrhash"
329           extended file attribute or via a .usrhash file adjacent to the disk
330           image, following the same format and logic as for the root hash for
331           the root file system described here. Note that there's currently no
332           switch to configure the root hash for the /usr/ from the command
333           line.
334
335           Also see the RootHash= option in systemd.exec(5).
336
337       --root-hash-sig=
338           Takes a PKCS7 signature of the --root-hash= option. The semantics
339           are the same as for the RootHashSignature= option, see
340           systemd.exec(5).
341
342       --verity-data=
343           Takes the path to a data integrity (dm-verity) file. This option
344           enables data integrity checks using dm-verity, if a root-hash is
345           passed and if the used image itself does not contain the integrity
346           data. The integrity data must be matched by the root hash. If this
347           option is not specified, but a file with the .verity suffix is
348           found next to the image file, bearing otherwise the same name
349           (except if the image has the .raw suffix, in which case the verity
350           data file must not have it in its name), the verity data is read
351           from it and automatically used.
352
353       --pivot-root=
354           Pivot the specified directory to / inside the container, and either
355           unmount the container's old root, or pivot it to another specified
356           directory. Takes one of: a path argument — in which case the
357           specified path will be pivoted to / and the old root will be
358           unmounted; or a colon-separated pair of new root path and pivot
359           destination for the old root. The new root path will be pivoted to
360           /, and the old / will be pivoted to the other directory. Both paths
361           must be absolute, and are resolved in the container's file system
362           namespace.
363
364           This is for containers which have several bootable directories in
365           them; for example, several OSTree[4] deployments. It emulates the
366           behavior of the boot loader and the initrd which normally select
367           which directory to mount as the root and start the container's PID
368           1 in.
369
370   Execution Options
371       -a, --as-pid2
372           Invoke the shell or specified program as process ID (PID) 2 instead
373           of PID 1 (init). By default, if neither this option nor --boot is
374           used, the selected program is run as the process with PID 1, a mode
375           only suitable for programs that are aware of the special semantics
376           that the process with PID 1 has on UNIX. For example, it needs to
377           reap all processes reparented to it, and should implement sysvinit
378           compatible signal handling (specifically: it needs to reboot on
379           SIGINT, reexecute on SIGTERM, reload configuration on SIGHUP, and
380           so on). With --as-pid2 a minimal stub init process is run as PID 1
381           and the selected program is executed as PID 2 (and hence does not
382           need to implement any special semantics). The stub init process
383           will reap processes as necessary and react appropriately to
384           signals. It is recommended to use this mode to invoke arbitrary
385           commands in containers, unless they have been modified to run
386           correctly as PID 1. Or in other words: this switch should be used
387           for pretty much all commands, except when the command refers to an
388           init or shell implementation, as these are generally capable of
389           running correctly as PID 1. This option may not be combined with
390           --boot.
391
392       -b, --boot
393           Automatically search for an init program and invoke it as PID 1,
394           instead of a shell or a user supplied program. If this option is
395           used, arguments specified on the command line are used as arguments
396           for the init program. This option may not be combined with
397           --as-pid2.
398
399           The following table explains the different modes of invocation and
400           relationship to --as-pid2 (see above):
401
402           Table 1. Invocation Mode
403           ┌──────────────────────┬────────────────────────────┐
404Switch                Explanation                
405           ├──────────────────────┼────────────────────────────┤
406           │Neither --as-pid2 nor │ The passed parameters are  │
407--boot specified      │ interpreted as the command │
408           │                      │ line, which is executed as │
409           │                      │ PID 1 in the container.    │
410           ├──────────────────────┼────────────────────────────┤
411--as-pid2 specified   │ The passed parameters are  │
412           │                      │ interpreted as the command │
413           │                      │ line, which is executed as │
414           │                      │ PID 2 in the container. A  │
415           │                      │ stub init process is run   │
416           │                      │ as PID 1.                  │
417           ├──────────────────────┼────────────────────────────┤
418--boot specified      │ An init program is         │
419           │                      │ automatically searched for │
420           │                      │ and run as PID 1 in the    │
421           │                      │ container. The passed      │
422           │                      │ parameters are used as     │
423           │                      │ invocation parameters for  │
424           │                      │ this process.              │
425           └──────────────────────┴────────────────────────────┘
426           Note that --boot is the default mode of operation if the
427           systemd-nspawn@.service template unit file is used.
428
429       --chdir=
430           Change to the specified working directory before invoking the
431           process in the container. Expects an absolute path in the
432           container's file system namespace.
433
434       -E NAME[=VALUE], --setenv=NAME[=VALUE]
435           Specifies an environment variable to pass to the init process in
436           the container. This may be used to override the default variables
437           or to set additional variables. It may be used more than once to
438           set multiple variables. When "=" and VALUE are omitted, the value
439           of the variable with the same name in the program environment will
440           be used.
441
442       -u, --user=
443           After transitioning into the container, change to the specified
444           user defined in the container's user database. Like all other
445           systemd-nspawn features, this is not a security feature and
446           provides protection against accidental destructive operations only.
447
448       --kill-signal=
449           Specify the process signal to send to the container's PID 1 when
450           nspawn itself receives SIGTERM, in order to trigger an orderly
451           shutdown of the container. Defaults to SIGRTMIN+3 if --boot is used
452           (on systemd-compatible init systems SIGRTMIN+3 triggers an orderly
453           shutdown). If --boot is not used and this option is not specified
454           the container's processes are terminated abruptly via SIGKILL. For
455           a list of valid signals, see signal(7).
456
457       --notify-ready=
458           Configures support for notifications from the container's init
459           process.  --notify-ready= takes a boolean (no and yes). With option
460           no systemd-nspawn notifies systemd with a "READY=1" message when
461           the init process is created. With option yes systemd-nspawn waits
462           for the "READY=1" message from the init process in the container
463           before sending its own to systemd. For more details about
464           notifications see sd_notify(3).
465
466       --suppress-sync=
467           Expects a boolean argument. If true, turns off any form of on-disk
468           file system synchronization for the container payload. This means
469           all system calls such as sync(2), fsync(), syncfs(), ... will
470           execute no operation, and the O_SYNC/O_DSYNC flags to open(2) and
471           related calls will be made unavailable. This is potentially
472           dangerous, as assumed data integrity guarantees to the container
473           payload are not actually enforced (i.e. data assumed to have been
474           written to disk might be lost if the system is shut down
475           abnormally). However, this can dramatically improve container
476           runtime performance – as long as these guarantees are not required
477           or desirable, for example because any data written by the container
478           is of temporary, redundant nature, or just an intermediary artifact
479           that will be further processed and finalized by a later step in a
480           pipeline. Defaults to false.
481
482   System Identity Options
483       -M, --machine=
484           Sets the machine name for this container. This name may be used to
485           identify this container during its runtime (for example in tools
486           like machinectl(1) and similar), and is used to initialize the
487           container's hostname (which the container can choose to override,
488           however). If not specified, the last component of the root
489           directory path of the container is used, possibly suffixed with a
490           random identifier in case --ephemeral mode is selected. If the root
491           directory selected is the host's root directory the host's hostname
492           is used as default instead.
493
494       --hostname=
495           Controls the hostname to set within the container, if different
496           from the machine name. Expects a valid hostname as argument. If
497           this option is used, the kernel hostname of the container will be
498           set to this value, otherwise it will be initialized to the machine
499           name as controlled by the --machine= option described above. The
500           machine name is used for various aspect of identification of the
501           container from the outside, the kernel hostname configurable with
502           this option is useful for the container to identify itself from the
503           inside. It is usually a good idea to keep both forms of
504           identification synchronized, in order to avoid confusion. It is
505           hence recommended to avoid usage of this option, and use --machine=
506           exclusively. Note that regardless whether the container's hostname
507           is initialized from the name set with --hostname= or the one set
508           with --machine=, the container can later override its kernel
509           hostname freely on its own as well.
510
511       --uuid=
512           Set the specified UUID for the container. The init system will
513           initialize /etc/machine-id from this if this file is not set yet.
514           Note that this option takes effect only if /etc/machine-id in the
515           container is unpopulated.
516
517   Property Options
518       -S, --slice=
519           Make the container part of the specified slice, instead of the
520           default machine.slice. This applies only if the machine is run in
521           its own scope unit, i.e. if --keep-unit isn't used.
522
523       --property=
524           Set a unit property on the scope unit to register for the machine.
525           This applies only if the machine is run in its own scope unit, i.e.
526           if --keep-unit isn't used. Takes unit property assignments in the
527           same format as systemctl set-property. This is useful to set memory
528           limits and similar for the container.
529
530       --register=
531           Controls whether the container is registered with systemd-
532           machined(8). Takes a boolean argument, which defaults to "yes".
533           This option should be enabled when the container runs a full
534           Operating System (more specifically: a system and service manager
535           as PID 1), and is useful to ensure that the container is accessible
536           via machinectl(1) and shown by tools such as ps(1). If the
537           container does not run a service manager, it is recommended to set
538           this option to "no".
539
540       --keep-unit
541           Instead of creating a transient scope unit to run the container in,
542           simply use the service or scope unit systemd-nspawn has been
543           invoked in. If --register=yes is set this unit is registered with
544           systemd-machined(8). This switch should be used if systemd-nspawn
545           is invoked from within a service unit, and the service unit's sole
546           purpose is to run a single systemd-nspawn container. This option is
547           not available if run from a user session.
548
549           Note that passing --keep-unit disables the effect of --slice= and
550           --property=. Use --keep-unit and --register=no in combination to
551           disable any kind of unit allocation or registration with
552           systemd-machined.
553
554   User Namespacing Options
555       --private-users=
556           Controls user namespacing. If enabled, the container will run with
557           its own private set of UNIX user and group ids (UIDs and GIDs).
558           This involves mapping the private UIDs/GIDs used in the container
559           (starting with the container's root user 0 and up) to a range of
560           UIDs/GIDs on the host that are not used for other purposes (usually
561           in the range beyond the host's UID/GID 65536). The parameter may be
562           specified as follows:
563
564            1. If one or two colon-separated numbers are specified, user
565               namespacing is turned on. The first parameter specifies the
566               first host UID/GID to assign to the container, the second
567               parameter specifies the number of host UIDs/GIDs to assign to
568               the container. If the second parameter is omitted, 65536
569               UIDs/GIDs are assigned.
570
571            2. If the parameter is "yes", user namespacing is turned on. The
572               UID/GID range to use is determined automatically from the file
573               ownership of the root directory of the container's directory
574               tree. To use this option, make sure to prepare the directory
575               tree in advance, and ensure that all files and directories in
576               it are owned by UIDs/GIDs in the range you'd like to use. Also,
577               make sure that used file ACLs exclusively reference UIDs/GIDs
578               in the appropriate range. In this mode, the number of UIDs/GIDs
579               assigned to the container is 65536, and the owner UID/GID of
580               the root directory must be a multiple of 65536.
581
582            3. If the parameter is "no", user namespacing is turned off. This
583               is the default.
584
585            4. If the parameter is "identity", user namespacing is employed
586               with an identity mapping for the first 65536 UIDs/GIDs. This is
587               mostly equivalent to --private-users=0:65536. While it does not
588               provide UID/GID isolation, since all host and container
589               UIDs/GIDs are chosen identically it does provide process
590               capability isolation, and hence is often a good choice if
591               proper user namespacing with distinct UID maps is not
592               appropriate.
593
594            5. The special value "pick" turns on user namespacing. In this
595               case the UID/GID range is automatically chosen. As first step,
596               the file owner UID/GID of the root directory of the container's
597               directory tree is read, and it is checked that no other
598               container is currently using it. If this check is successful,
599               the UID/GID range determined this way is used, similarly to the
600               behavior if "yes" is specified. If the check is not successful
601               (and thus the UID/GID range indicated in the root directory's
602               file owner is already used elsewhere) a new – currently unused
603               – UID/GID range of 65536 UIDs/GIDs is randomly chosen between
604               the host UID/GIDs of 524288 and 1878982656, always starting at
605               a multiple of 65536, and, if possible, consistently hashed from
606               the machine name. This setting implies
607               --private-users-ownership=auto (see below), which possibly has
608               the effect that the files and directories in the container's
609               directory tree will be owned by the appropriate users of the
610               range picked. Using this option makes user namespace behavior
611               fully automatic. Note that the first invocation of a previously
612               unused container image might result in picking a new UID/GID
613               range for it, and thus in the (possibly expensive) file
614               ownership adjustment operation. However, subsequent invocations
615               of the container will be cheap (unless of course the picked
616               UID/GID range is assigned to a different use by then).
617
618           It is recommended to assign at least 65536 UIDs/GIDs to each
619           container, so that the usable UID/GID range in the container covers
620           16 bit. For best security, do not assign overlapping UID/GID ranges
621           to multiple containers. It is hence a good idea to use the upper 16
622           bit of the host 32-bit UIDs/GIDs as container identifier, while the
623           lower 16 bit encode the container UID/GID used. This is in fact the
624           behavior enforced by the --private-users=pick option.
625
626           When user namespaces are used, the GID range assigned to each
627           container is always chosen identical to the UID range.
628
629           In most cases, using --private-users=pick is the recommended option
630           as it enhances container security massively and operates fully
631           automatically in most cases.
632
633           Note that the picked UID/GID range is not written to /etc/passwd or
634           /etc/group. In fact, the allocation of the range is not stored
635           persistently anywhere, except in the file ownership of the files
636           and directories of the container.
637
638           Note that when user namespacing is used file ownership on disk
639           reflects this, and all of the container's files and directories are
640           owned by the container's effective user and group IDs. This means
641           that copying files from and to the container image requires
642           correction of the numeric UID/GID values, according to the UID/GID
643           shift applied.
644
645       --private-users-ownership=
646           Controls how to adjust the container image's UIDs and GIDs to match
647           the UID/GID range chosen with --private-users=, see above. Takes
648           one of "off" (to leave the image as is), "chown" (to recursively
649           chown() the container's directory tree as needed), "map" (in order
650           to use transparent ID mapping mounts) or "auto" for automatically
651           using "map" where available and "chown" where not.
652
653           If "chown" is selected, all files and directories in the
654           container's directory tree will be adjusted so that they are owned
655           by the appropriate UIDs/GIDs selected for the container (see
656           above). This operation is potentially expensive, as it involves
657           iterating through the full directory tree of the container. Besides
658           actual file ownership, file ACLs are adjusted as well.
659
660           Typically "map" is the best choice, since it transparently maps
661           UIDs/GIDs in memory as needed without modifying the image, and
662           without requiring an expensive recursive adjustment operation.
663           However, it is not available for all file systems, currently.
664
665           The --private-users-ownership=auto option is implied if
666           --private-users=pick is used. This option has no effect if user
667           namespacing is not used.
668
669       -U
670           If the kernel supports the user namespaces feature, equivalent to
671           --private-users=pick --private-users-ownership=auto, otherwise
672           equivalent to --private-users=no.
673
674           Note that -U is the default if the systemd-nspawn@.service template
675           unit file is used.
676
677           Note: it is possible to undo the effect of
678           --private-users-ownership=chown (or -U) on the file system by
679           redoing the operation with the first UID of 0:
680
681               systemd-nspawn ... --private-users=0 --private-users-ownership=chown
682
683   Networking Options
684       --private-network
685           Disconnect networking of the container from the host. This makes
686           all network interfaces unavailable in the container, with the
687           exception of the loopback device and those specified with
688           --network-interface= and configured with --network-veth. If this
689           option is specified, the CAP_NET_ADMIN capability will be added to
690           the set of capabilities the container retains. The latter may be
691           disabled by using --drop-capability=. If this option is not
692           specified (or implied by one of the options listed below), the
693           container will have full access to the host network.
694
695       --network-interface=
696           Assign the specified network interface to the container. This will
697           remove the specified interface from the calling namespace and place
698           it in the container. When the container terminates, it is moved
699           back to the calling namespace. Note that --network-interface=
700           implies --private-network. This option may be used more than once
701           to add multiple network interfaces to the container.
702
703           Note that any network interface specified this way must already
704           exist at the time the container is started. If the container shall
705           be started automatically at boot via a systemd-nspawn@.service unit
706           file instance, it might hence make sense to add a unit file drop-in
707           to the service instance (e.g.
708           /etc/systemd/system/systemd-nspawn@foobar.service.d/50-network.conf)
709           with contents like the following:
710
711               [Unit]
712               Wants=sys-subsystem-net-devices-ens1.device
713               After=sys-subsystem-net-devices-ens1.device
714
715           This will make sure that activation of the container service will
716           be delayed until the "ens1" network interface has shown up. This is
717           required since hardware probing is fully asynchronous, and network
718           interfaces might be discovered only later during the boot process,
719           after the container would normally be started without these
720           explicit dependencies.
721
722       --network-macvlan=
723           Create a "macvlan" interface of the specified Ethernet network
724           interface and add it to the container. A "macvlan" interface is a
725           virtual interface that adds a second MAC address to an existing
726           physical Ethernet link. The interface in the container will be
727           named after the interface on the host, prefixed with "mv-". Note
728           that --network-macvlan= implies --private-network. This option may
729           be used more than once to add multiple network interfaces to the
730           container.
731
732           As with --network-interface=, the underlying Ethernet network
733           interface must already exist at the time the container is started,
734           and thus similar unit file drop-ins as described above might be
735           useful.
736
737       --network-ipvlan=
738           Create an "ipvlan" interface of the specified Ethernet network
739           interface and add it to the container. An "ipvlan" interface is a
740           virtual interface, similar to a "macvlan" interface, which uses the
741           same MAC address as the underlying interface. The interface in the
742           container will be named after the interface on the host, prefixed
743           with "iv-". Note that --network-ipvlan= implies --private-network.
744           This option may be used more than once to add multiple network
745           interfaces to the container.
746
747           As with --network-interface=, the underlying Ethernet network
748           interface must already exist at the time the container is started,
749           and thus similar unit file drop-ins as described above might be
750           useful.
751
752       -n, --network-veth
753           Create a virtual Ethernet link ("veth") between host and container.
754           The host side of the Ethernet link will be available as a network
755           interface named after the container's name (as specified with
756           --machine=), prefixed with "ve-". The container side of the
757           Ethernet link will be named "host0". The --network-veth option
758           implies --private-network.
759
760           Note that systemd-networkd.service(8) includes by default a network
761           file /usr/lib/systemd/network/80-container-ve.network matching the
762           host-side interfaces created this way, which contains settings to
763           enable automatic address provisioning on the created virtual link
764           via DHCP, as well as automatic IP routing onto the host's external
765           network interfaces. It also contains
766           /usr/lib/systemd/network/80-container-host0.network matching the
767           container-side interface created this way, containing settings to
768           enable client side address assignment via DHCP. In case
769           systemd-networkd is running on both the host and inside the
770           container, automatic IP communication from the container to the
771           host is thus available, with further connectivity to the external
772           network.
773
774           Note that --network-veth is the default if the
775           systemd-nspawn@.service template unit file is used.
776
777           Note that on Linux network interface names may have a length of 15
778           characters at maximum, while container names may have a length up
779           to 64 characters. As this option derives the host-side interface
780           name from the container name the name is possibly truncated. Thus,
781           care needs to be taken to ensure that interface names remain unique
782           in this case, or even better container names are generally not
783           chosen longer than 12 characters, to avoid the truncation. If the
784           name is truncated, systemd-nspawn will automatically append a
785           4-digit hash value to the name to reduce the chance of collisions.
786           However, the hash algorithm is not collision-free. (See
787           systemd.net-naming-scheme(7) for details on older naming algorithms
788           for this interface). Alternatively, the --network-veth-extra=
789           option may be used, which allows free configuration of the
790           host-side interface name independently of the container name — but
791           might require a bit more additional configuration in case bridging
792           in a fashion similar to --network-bridge= is desired.
793
794       --network-veth-extra=
795           Adds an additional virtual Ethernet link between host and
796           container. Takes a colon-separated pair of host interface name and
797           container interface name. The latter may be omitted in which case
798           the container and host sides will be assigned the same name. This
799           switch is independent of --network-veth, and — in contrast — may be
800           used multiple times, and allows configuration of the network
801           interface names. Note that --network-bridge= has no effect on
802           interfaces created with --network-veth-extra=.
803
804       --network-bridge=
805           Adds the host side of the Ethernet link created with --network-veth
806           to the specified Ethernet bridge interface. Expects a valid network
807           interface name of a bridge device as argument. Note that
808           --network-bridge= implies --network-veth. If this option is used,
809           the host side of the Ethernet link will use the "vb-" prefix
810           instead of "ve-". Regardless of the used naming prefix the same
811           network interface name length limits imposed by Linux apply, along
812           with the complications this creates (for details see above).
813
814           As with --network-interface=, the underlying bridge network
815           interface must already exist at the time the container is started,
816           and thus similar unit file drop-ins as described above might be
817           useful.
818
819       --network-zone=
820           Creates a virtual Ethernet link ("veth") to the container and adds
821           it to an automatically managed Ethernet bridge interface. The
822           bridge interface is named after the passed argument, prefixed with
823           "vz-". The bridge interface is automatically created when the first
824           container configured for its name is started, and is automatically
825           removed when the last container configured for its name exits.
826           Hence, each bridge interface configured this way exists only as
827           long as there's at least one container referencing it running. This
828           option is very similar to --network-bridge=, besides this automatic
829           creation/removal of the bridge device.
830
831           This setting makes it easy to place multiple related containers on
832           a common, virtual Ethernet-based broadcast domain, here called a
833           "zone". Each container may only be part of one zone, but each zone
834           may contain any number of containers. Each zone is referenced by
835           its name. Names may be chosen freely (as long as they form valid
836           network interface names when prefixed with "vz-"), and it is
837           sufficient to pass the same name to the --network-zone= switch of
838           the various concurrently running containers to join them in one
839           zone.
840
841           Note that systemd-networkd.service(8) includes by default a network
842           file /usr/lib/systemd/network/80-container-vz.network matching the
843           bridge interfaces created this way, which contains settings to
844           enable automatic address provisioning on the created virtual
845           network via DHCP, as well as automatic IP routing onto the host's
846           external network interfaces. Using --network-zone= is hence in most
847           cases fully automatic and sufficient to connect multiple local
848           containers in a joined broadcast domain to the host, with further
849           connectivity to the external network.
850
851       --network-namespace-path=
852           Takes the path to a file representing a kernel network namespace
853           that the container shall run in. The specified path should refer to
854           a (possibly bind-mounted) network namespace file, as exposed by the
855           kernel below /proc/$PID/ns/net. This makes the container enter the
856           given network namespace. One of the typical use cases is to give a
857           network namespace under /run/netns created by ip-netns(8), for
858           example, --network-namespace-path=/run/netns/foo. Note that this
859           option cannot be used together with other network-related options,
860           such as --private-network or --network-interface=.
861
862       -p, --port=
863           If private networking is enabled, maps an IP port on the host onto
864           an IP port on the container. Takes a protocol specifier (either
865           "tcp" or "udp"), separated by a colon from a host port number in
866           the range 1 to 65535, separated by a colon from a container port
867           number in the range from 1 to 65535. The protocol specifier and its
868           separating colon may be omitted, in which case "tcp" is assumed.
869           The container port number and its colon may be omitted, in which
870           case the same port as the host port is implied. This option is only
871           supported if private networking is used, such as with
872           --network-veth, --network-zone= --network-bridge=.
873
874   Security Options
875       --capability=
876           List one or more additional capabilities to grant the container.
877           Takes a comma-separated list of capability names, see
878           capabilities(7) for more information. Note that the following
879           capabilities will be granted in any way: CAP_AUDIT_CONTROL,
880           CAP_AUDIT_WRITE, CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH,
881           CAP_FOWNER, CAP_FSETID, CAP_IPC_OWNER, CAP_KILL, CAP_LEASE,
882           CAP_LINUX_IMMUTABLE, CAP_MKNOD, CAP_NET_BIND_SERVICE,
883           CAP_NET_BROADCAST, CAP_NET_RAW, CAP_SETFCAP, CAP_SETGID,
884           CAP_SETPCAP, CAP_SETUID, CAP_SYS_ADMIN, CAP_SYS_BOOT,
885           CAP_SYS_CHROOT, CAP_SYS_NICE, CAP_SYS_PTRACE, CAP_SYS_RESOURCE,
886           CAP_SYS_TTY_CONFIG. Also CAP_NET_ADMIN is retained if
887           --private-network is specified. If the special value "all" is
888           passed, all capabilities are retained.
889
890           If the special value of "help" is passed, the program will print
891           known capability names and exit.
892
893           This option sets the bounding set of capabilities which also limits
894           the ambient capabilities as given with the --ambient-capability=.
895
896       --drop-capability=
897           Specify one or more additional capabilities to drop for the
898           container. This allows running the container with fewer
899           capabilities than the default (see above).
900
901           If the special value of "help" is passed, the program will print
902           known capability names and exit.
903
904           This option sets the bounding set of capabilities which also limits
905           the ambient capabilities as given with the --ambient-capability=.
906
907       --ambient-capability=
908           Specify one or more additional capabilities to pass in the
909           inheritable and ambient set to the program started within the
910           container. The value "all" is not supported for this setting.
911
912           All capabilities specified here must be in the set allowed with the
913           --capability= and --drop-capability= options. Otherwise, an error
914           message will be shown.
915
916           This option cannot be combined with the boot mode of the container
917           (as requested via --boot).
918
919           If the special value of "help" is passed, the program will print
920           known capability names and exit.
921
922       --no-new-privileges=
923           Takes a boolean argument. Specifies the value of the
924           PR_SET_NO_NEW_PRIVS flag for the container payload. Defaults to
925           off. When turned on the payload code of the container cannot
926           acquire new privileges, i.e. the "setuid" file bit as well as file
927           system capabilities will not have an effect anymore. See prctl(2)
928           for details about this flag.
929
930       --system-call-filter=
931           Alter the system call filter applied to containers. Takes a
932           space-separated list of system call names or group names (the
933           latter prefixed with "@", as listed by the syscall-filter command
934           of systemd-analyze(1)). Passed system calls will be permitted. The
935           list may optionally be prefixed by "~", in which case all listed
936           system calls are prohibited. If this command line option is used
937           multiple times the configured lists are combined. If both a
938           positive and a negative list (that is one system call list without
939           and one with the "~" prefix) are configured, the negative list
940           takes precedence over the positive list. Note that systemd-nspawn
941           always implements a system call allow list (as opposed to a deny
942           list!), and this command line option hence adds or removes entries
943           from the default allow list, depending on the "~" prefix. Note that
944           the applied system call filter is also altered implicitly if
945           additional capabilities are passed using the --capabilities=.
946
947       -Z, --selinux-context=
948           Sets the SELinux security context to be used to label processes in
949           the container.
950
951       -L, --selinux-apifs-context=
952           Sets the SELinux security context to be used to label files in the
953           virtual API file systems in the container.
954
955   Resource Options
956       --rlimit=
957           Sets the specified POSIX resource limit for the container payload.
958           Expects an assignment of the form "LIMIT=SOFT:HARD" or
959           "LIMIT=VALUE", where LIMIT should refer to a resource limit type,
960           such as RLIMIT_NOFILE or RLIMIT_NICE. The SOFT and HARD fields
961           should refer to the numeric soft and hard resource limit values. If
962           the second form is used, VALUE may specify a value that is used
963           both as soft and hard limit. In place of a numeric value the
964           special string "infinity" may be used to turn off resource limiting
965           for the specific type of resource. This command line option may be
966           used multiple times to control limits on multiple limit types. If
967           used multiple times for the same limit type, the last use wins. For
968           details about resource limits see setrlimit(2). By default resource
969           limits for the container's init process (PID 1) are set to the same
970           values the Linux kernel originally passed to the host init system.
971           Note that some resource limits are enforced on resources counted
972           per user, in particular RLIMIT_NPROC. This means that unless user
973           namespacing is deployed (i.e.  --private-users= is used, see
974           above), any limits set will be applied to the resource usage of the
975           same user on all local containers as well as the host. This means
976           particular care needs to be taken with these limits as they might
977           be triggered by possibly less trusted code. Example:
978           "--rlimit=RLIMIT_NOFILE=8192:16384".
979
980       --oom-score-adjust=
981           Changes the OOM ("Out Of Memory") score adjustment value for the
982           container payload. This controls /proc/self/oom_score_adj which
983           influences the preference with which this container is terminated
984           when memory becomes scarce. For details see proc(5). Takes an
985           integer in the range -1000...1000.
986
987       --cpu-affinity=
988           Controls the CPU affinity of the container payload. Takes a comma
989           separated list of CPU numbers or number ranges (the latter's start
990           and end value separated by dashes). See sched_setaffinity(2) for
991           details.
992
993       --personality=
994           Control the architecture ("personality") reported by uname(2) in
995           the container. Currently, only "x86" and "x86-64" are supported.
996           This is useful when running a 32-bit container on a 64-bit host. If
997           this setting is not used, the personality reported in the container
998           is the same as the one reported on the host.
999
1000   Integration Options
1001       --resolv-conf=
1002           Configures how /etc/resolv.conf inside of the container shall be
1003           handled (i.e. DNS configuration synchronization from host to
1004           container). Takes one of "off", "copy-host", "copy-static",
1005           "copy-uplink", "copy-stub", "replace-host", "replace-static",
1006           "replace-uplink", "replace-stub", "bind-host", "bind-static",
1007           "bind-uplink", "bind-stub", "delete" or "auto".
1008
1009           If set to "off" the /etc/resolv.conf file in the container is left
1010           as it is included in the image, and neither modified nor bind
1011           mounted over.
1012
1013           If set to "copy-host", the /etc/resolv.conf file from the host is
1014           copied into the container, unless the file exists already and is
1015           not a regular file (e.g. a symlink). Similarly, if "replace-host"
1016           is used the file is copied, replacing any existing inode, including
1017           symlinks. Similarly, if "bind-host" is used, the file is bind
1018           mounted from the host into the container.
1019
1020           If set to "copy-static", "replace-static" or "bind-static" the
1021           static resolv.conf file supplied with systemd-resolved.service(8)
1022           (specifically: /usr/lib/systemd/resolv.conf) is copied or bind
1023           mounted into the container.
1024
1025           If set to "copy-uplink", "replace-uplink" or "bind-uplink" the
1026           uplink resolv.conf file managed by systemd-resolved.service
1027           (specifically: /run/systemd/resolve/resolv.conf) is copied or bind
1028           mounted into the container.
1029
1030           If set to "copy-stub", "replace-stub" or "bind-stub" the stub
1031           resolv.conf file managed by systemd-resolved.service (specifically:
1032           /run/systemd/resolve/stub-resolv.conf) is copied or bind mounted
1033           into the container.
1034
1035           If set to "delete" the /etc/resolv.conf file in the container is
1036           deleted if it exists.
1037
1038           Finally, if set to "auto" the file is left as it is if private
1039           networking is turned on (see --private-network). Otherwise, if
1040           systemd-resolved.service is running its stub resolv.conf file is
1041           used, and if not the host's /etc/resolv.conf file. In the latter
1042           cases the file is copied if the image is writable, and bind mounted
1043           otherwise.
1044
1045           It's recommended to use "copy-..."  or "replace-..."  if the
1046           container shall be able to make changes to the DNS configuration on
1047           its own, deviating from the host's settings. Otherwise "bind" is
1048           preferable, as it means direct changes to /etc/resolv.conf in the
1049           container are not allowed, as it is a read-only bind mount (but
1050           note that if the container has enough privileges, it might simply
1051           go ahead and unmount the bind mount anyway). Note that both if the
1052           file is bind mounted and if it is copied no further propagation of
1053           configuration is generally done after the one-time early
1054           initialization (this is because the file is usually updated through
1055           copying and renaming). Defaults to "auto".
1056
1057       --timezone=
1058           Configures how /etc/localtime inside of the container (i.e. local
1059           timezone synchronization from host to container) shall be handled.
1060           Takes one of "off", "copy", "bind", "symlink", "delete" or "auto".
1061           If set to "off" the /etc/localtime file in the container is left as
1062           it is included in the image, and neither modified nor bind mounted
1063           over. If set to "copy" the /etc/localtime file of the host is
1064           copied into the container. Similarly, if "bind" is used, the file
1065           is bind mounted from the host into the container. If set to
1066           "symlink", a symlink is created pointing from /etc/localtime in the
1067           container to the timezone file in the container that matches the
1068           timezone setting on the host. If set to "delete", the file in the
1069           container is deleted, should it exist. If set to "auto" and the
1070           /etc/localtime file of the host is a symlink, then "symlink" mode
1071           is used, and "copy" otherwise, except if the image is read-only in
1072           which case "bind" is used instead. Defaults to "auto".
1073
1074       --link-journal=
1075           Control whether the container's journal shall be made visible to
1076           the host system. If enabled, allows viewing the container's journal
1077           files from the host (but not vice versa). Takes one of "no",
1078           "host", "try-host", "guest", "try-guest", "auto". If "no", the
1079           journal is not linked. If "host", the journal files are stored on
1080           the host file system (beneath /var/log/journal/machine-id) and the
1081           subdirectory is bind-mounted into the container at the same
1082           location. If "guest", the journal files are stored on the guest
1083           file system (beneath /var/log/journal/machine-id) and the
1084           subdirectory is symlinked into the host at the same location.
1085           "try-host" and "try-guest" do the same but do not fail if the host
1086           does not have persistent journaling enabled. If "auto" (the
1087           default), and the right subdirectory of /var/log/journal exists, it
1088           will be bind mounted into the container. If the subdirectory does
1089           not exist, no linking is performed. Effectively, booting a
1090           container once with "guest" or "host" will link the journal
1091           persistently if further on the default of "auto" is used.
1092
1093           Note that --link-journal=try-guest is the default if the
1094           systemd-nspawn@.service template unit file is used.
1095
1096       -j
1097           Equivalent to --link-journal=try-guest.
1098
1099   Mount Options
1100       --bind=, --bind-ro=
1101           Bind mount a file or directory from the host into the container.
1102           Takes one of: a path argument — in which case the specified path
1103           will be mounted from the host to the same path in the container, or
1104           a colon-separated pair of paths — in which case the first specified
1105           path is the source in the host, and the second path is the
1106           destination in the container, or a colon-separated triple of source
1107           path, destination path and mount options. The source path may
1108           optionally be prefixed with a "+" character. If so, the source path
1109           is taken relative to the image's root directory. This permits
1110           setting up bind mounts within the container image. The source path
1111           may be specified as empty string, in which case a temporary
1112           directory below the host's /var/tmp/ directory is used. It is
1113           automatically removed when the container is shut down. If the
1114           source path is not absolute, it is resolved relative to the current
1115           working directory. The --bind-ro= option creates read-only bind
1116           mounts. Backslash escapes are interpreted, so "\:" may be used to
1117           embed colons in either path. This option may be specified multiple
1118           times for creating multiple independent bind mount points.
1119
1120           Mount options are comma-separated.  rbind and norbind control
1121           whether to create a recursive or a regular bind mount. Defaults to
1122           "rbind".  noidmap, idmap, and rootidmap control ID mapping.
1123
1124           Using idmap or rootidmap requires support by the source filesystem
1125           for user/group ID mapped mounts. Defaults to "noidmap". With x
1126           being the container's UID range offset, y being the length of the
1127           container's UID range, and p being the owner UID of the bind mount
1128           source inode on the host:
1129
1130           •   If noidmap is used, any user z in the range 0 ... y seen from
1131               inside of the container is mapped to x + z in the x ... x + y
1132               range on the host. Other host users are mapped to nobody inside
1133               the container.
1134
1135           •   If idmap is used, any user z in the UID range 0 ... y as seen
1136               from inside the container is mapped to the same z in the same 0
1137               ... y range on the host. Other host users are mapped to nobody
1138               inside the container.
1139
1140           •   If rootidmap is used, the user 0 seen from inside of the
1141               container is mapped to p on the host. Other host users are
1142               mapped to nobody inside the container.
1143
1144           Whichever ID mapping option is used, the same mapping will be used
1145           for users and groups IDs. If rootidmap is used, the group owning
1146           the bind mounted directory will have no effect.
1147
1148           Note that when this option is used in combination with
1149           --private-users, the resulting mount points will be owned by the
1150           nobody user. That's because the mount and its files and directories
1151           continue to be owned by the relevant host users and groups, which
1152           do not exist in the container, and thus show up under the wildcard
1153           UID 65534 (nobody). If such bind mounts are created, it is
1154           recommended to make them read-only, using --bind-ro=. Alternatively
1155           you can use the "idmap" mount option to map the filesystem IDs.
1156
1157       --bind-user=
1158           Binds the home directory of the specified user on the host into the
1159           container. Takes the name of an existing user on the host as
1160           argument. May be used multiple times to bind multiple users into
1161           the container. This does three things:
1162
1163            1. The user's home directory is bind mounted from the host into
1164               /run/host/home/.
1165
1166            2. An additional UID/GID mapping is added that maps the host
1167               user's UID/GID to a container UID/GID, allocated from the
1168               60514...60577 range.
1169
1170            3. A JSON user and group record is generated in /run/userdb/ that
1171               describes the mapped user. It contains a minimized
1172               representation of the host's user record, adjusted to the
1173               UID/GID and home directory path assigned to the user in the
1174               container. The nss-systemd(8) glibc NSS module will pick up
1175               these records from there and make them available in the
1176               container's user/group databases.
1177
1178           The combination of the three operations above ensures that it is
1179           possible to log into the container using the same account
1180           information as on the host. The user is only mapped transiently,
1181           while the container is running, and the mapping itself does not
1182           result in persistent changes to the container (except maybe for log
1183           messages generated at login time, and similar). Note that in
1184           particular the UID/GID assignment in the container is not made
1185           persistently. If the user is mapped transiently, it is best to not
1186           allow the user to make persistent changes to the container. If the
1187           user leaves files or directories owned by the user, and those
1188           UIDs/GIDs are reused during later container invocations (possibly
1189           with a different --bind-user= mapping), those files and directories
1190           will be accessible to the "new" user.
1191
1192           The user/group record mapping only works if the container contains
1193           systemd 249 or newer, with nss-systemd properly configured in
1194           nsswitch.conf. See nss-systemd(8) for details.
1195
1196           Note that the user record propagated from the host into the
1197           container will contain the UNIX password hash of the user, so that
1198           seamless logins in the container are possible. If the container is
1199           less trusted than the host it's hence important to use a strong
1200           UNIX password hash function (e.g. yescrypt or similar, with the
1201           "$y$" hash prefix).
1202
1203           When binding a user from the host into the container checks are
1204           executed to ensure that the username is not yet known in the
1205           container. Moreover, it is checked that the UID/GID allocated for
1206           it is not currently defined in the user/group databases of the
1207           container. Both checks directly access the container's /etc/passwd
1208           and /etc/group, and thus might not detect existing accounts in
1209           other databases.
1210
1211           This operation is only supported in combination with
1212           --private-users=/-U.
1213
1214       --inaccessible=
1215           Make the specified path inaccessible in the container. This
1216           over-mounts the specified path (which must exist in the container)
1217           with a file node of the same type that is empty and has the most
1218           restrictive access mode supported. This is an effective way to mask
1219           files, directories and other file system objects from the container
1220           payload. This option may be used more than once in case all
1221           specified paths are masked.
1222
1223       --tmpfs=
1224           Mount a tmpfs file system into the container. Takes a single
1225           absolute path argument that specifies where to mount the tmpfs
1226           instance to (in which case the directory access mode will be chosen
1227           as 0755, owned by root/root), or optionally a colon-separated pair
1228           of path and mount option string that is used for mounting (in which
1229           case the kernel default for access mode and owner will be chosen,
1230           unless otherwise specified). Backslash escapes are interpreted in
1231           the path, so "\:" may be used to embed colons in the path.
1232
1233           Note that this option cannot be used to replace the root file
1234           system of the container with a temporary file system. However, the
1235           --volatile= option described below provides similar functionality,
1236           with a focus on implementing stateless operating system images.
1237
1238       --overlay=, --overlay-ro=
1239           Combine multiple directory trees into one overlay file system and
1240           mount it into the container. Takes a list of colon-separated paths
1241           to the directory trees to combine and the destination mount point.
1242
1243           Backslash escapes are interpreted in the paths, so "\:" may be used
1244           to embed colons in the paths.
1245
1246           If three or more paths are specified, then the last specified path
1247           is the destination mount point in the container, all paths
1248           specified before refer to directory trees on the host and are
1249           combined in the specified order into one overlay file system. The
1250           left-most path is hence the lowest directory tree, the
1251           second-to-last path the highest directory tree in the stacking
1252           order. If --overlay-ro= is used instead of --overlay=, a read-only
1253           overlay file system is created. If a writable overlay file system
1254           is created, all changes made to it are written to the highest
1255           directory tree in the stacking order, i.e. the second-to-last
1256           specified.
1257
1258           If only two paths are specified, then the second specified path is
1259           used both as the top-level directory tree in the stacking order as
1260           seen from the host, as well as the mount point for the overlay file
1261           system in the container. At least two paths have to be specified.
1262
1263           The source paths may optionally be prefixed with "+" character. If
1264           so they are taken relative to the image's root directory. The
1265           uppermost source path may also be specified as an empty string, in
1266           which case a temporary directory below the host's /var/tmp/ is
1267           used. The directory is removed automatically when the container is
1268           shut down. This behaviour is useful in order to make read-only
1269           container directories writable while the container is running. For
1270           example, use "--overlay=+/var::/var" in order to automatically
1271           overlay a writable temporary directory on a read-only /var/
1272           directory. If a source path is not absolute, it is resolved
1273           relative to the current working directory.
1274
1275           For details about overlay file systems, see Overlay Filesystem[5].
1276           Note that the semantics of overlay file systems are substantially
1277           different from normal file systems, in particular regarding
1278           reported device and inode information. Device and inode information
1279           may change for a file while it is being written to, and processes
1280           might see out-of-date versions of files at times. Note that this
1281           switch automatically derives the "workdir=" mount option for the
1282           overlay file system from the top-level directory tree, making it a
1283           sibling of it. It is hence essential that the top-level directory
1284           tree is not a mount point itself (since the working directory must
1285           be on the same file system as the top-most directory tree). Also
1286           note that the "lowerdir=" mount option receives the paths to stack
1287           in the opposite order of this switch.
1288
1289           Note that this option cannot be used to replace the root file
1290           system of the container with an overlay file system. However, the
1291           --volatile= option described above provides similar functionality,
1292           with a focus on implementing stateless operating system images.
1293
1294   Input/Output Options
1295       --console=MODE
1296           Configures how to set up standard input, output and error output
1297           for the container payload, as well as the /dev/console device for
1298           the container. Takes one of interactive, read-only, passive, pipe
1299           or autopipe. If interactive, a pseudo-TTY is allocated and made
1300           available as /dev/console in the container. It is then
1301           bi-directionally connected to the standard input and output passed
1302           to systemd-nspawn.  read-only is similar but only the output of the
1303           container is propagated and no input from the caller is read. If
1304           passive, a pseudo TTY is allocated, but it is not connected
1305           anywhere. In pipe mode no pseudo TTY is allocated, but the standard
1306           input, output and error output file descriptors passed to
1307           systemd-nspawn are passed on — as they are — to the container
1308           payload, see the following paragraph. Finally, autopipe mode
1309           operates like interactive when systemd-nspawn is invoked on a
1310           terminal, and like pipe otherwise. Defaults to interactive if
1311           systemd-nspawn is invoked from a terminal, and read-only otherwise.
1312
1313           In pipe mode, /dev/console will not exist in the container. This
1314           means that the container payload generally cannot be a full init
1315           system as init systems tend to require /dev/console to be
1316           available. On the other hand, in this mode container invocations
1317           can be used within shell pipelines. This is because intermediary
1318           pseudo TTYs do not permit independent bidirectional propagation of
1319           the end-of-file (EOF) condition, which is necessary for shell
1320           pipelines to work correctly.  Note that the pipe mode should be
1321           used carefully, as passing arbitrary file descriptors to less
1322           trusted container payloads might open up unwanted interfaces for
1323           access by the container payload. For example, if a passed file
1324           descriptor refers to a TTY of some form, APIs such as TIOCSTI may
1325           be used to synthesize input that might be used for escaping the
1326           container. Hence pipe mode should only be used if the payload is
1327           sufficiently trusted or when the standard input/output/error output
1328           file descriptors are known safe, for example pipes.
1329
1330       --pipe, -P
1331           Equivalent to --console=pipe.
1332
1333   Credentials
1334       --load-credential=ID:PATH, --set-credential=ID:VALUE
1335           Pass a credential to the container. These two options correspond to
1336           the LoadCredential= and SetCredential= settings in unit files. See
1337           systemd.exec(5) for details about these concepts, as well as the
1338           syntax of the option's arguments.
1339
1340           Note: when systemd-nspawn runs as systemd system service it can
1341           propagate the credentials it received via
1342           LoadCredential=/SetCredential= to the container payload. A systemd
1343           service manager running as PID 1 in the container can further
1344           propagate them to the services it itself starts. It is thus
1345           possible to easily propagate credentials from a parent service
1346           manager to a container manager service and from there into its
1347           payload. This can even be done recursively.
1348
1349           In order to embed binary data into the credential data for
1350           --set-credential=, use C-style escaping (i.e.  "\n" to embed a
1351           newline, or "\x00" to embed a NUL byte). Note that the invoking
1352           shell might already apply unescaping once, hence this might require
1353           double escaping!.
1354
1355           The systemd-sysusers.service(8) and systemd-firstboot(1) services
1356           read credentials configured this way for the purpose of configuring
1357           the container's root user's password and shell, as well as system
1358           locale, keymap and timezone during the first boot process of the
1359           container. This is particularly useful in combination with
1360           --volatile=yes where every single boot appears as first boot, since
1361           configuration applied to /etc/ is lost on container reboot cycles.
1362           See the respective man pages for details. Example:
1363
1364               # systemd-nspawn -i image.raw \
1365                         --volatile=yes \
1366                         --set-credential=firstboot.locale:de_DE.UTF-8 \
1367                         --set-credential=passwd.hashed-password.root:'$y$j9T$yAuRJu1o5HioZAGDYPU5d.$F64ni6J2y2nNQve90M/p0ZP0ECP/qqzipNyaY9fjGpC' \
1368                         -b
1369
1370           The above command line will invoke the specified image file
1371           image.raw in volatile mode, i.e. with empty /etc/ and /var/. The
1372           container payload will recognize this as a first boot, and will
1373           invoke systemd-firstboot.service, which then reads the two passed
1374           credentials to configure the system's initial locale and root
1375           password.
1376
1377   Other
1378       --no-pager
1379           Do not pipe output into a pager.
1380
1381       -h, --help
1382           Print a short help text and exit.
1383
1384       --version
1385           Print a short version string and exit.
1386

ENVIRONMENT

1388       $SYSTEMD_LOG_LEVEL
1389           The maximum log level of emitted messages (messages with a higher
1390           log level, i.e. less important ones, will be suppressed). Either
1391           one of (in order of decreasing importance) emerg, alert, crit, err,
1392           warning, notice, info, debug, or an integer in the range 0...7. See
1393           syslog(3) for more information.
1394
1395       $SYSTEMD_LOG_COLOR
1396           A boolean. If true, messages written to the tty will be colored
1397           according to priority.
1398
1399           This setting is only useful when messages are written directly to
1400           the terminal, because journalctl(1) and other tools that display
1401           logs will color messages based on the log level on their own.
1402
1403       $SYSTEMD_LOG_TIME
1404           A boolean. If true, console log messages will be prefixed with a
1405           timestamp.
1406
1407           This setting is only useful when messages are written directly to
1408           the terminal or a file, because journalctl(1) and other tools that
1409           display logs will attach timestamps based on the entry metadata on
1410           their own.
1411
1412       $SYSTEMD_LOG_LOCATION
1413           A boolean. If true, messages will be prefixed with a filename and
1414           line number in the source code where the message originates.
1415
1416           Note that the log location is often attached as metadata to journal
1417           entries anyway. Including it directly in the message text can
1418           nevertheless be convenient when debugging programs.
1419
1420       $SYSTEMD_LOG_TID
1421           A boolean. If true, messages will be prefixed with the current
1422           numerical thread ID (TID).
1423
1424           Note that the this information is attached as metadata to journal
1425           entries anyway. Including it directly in the message text can
1426           nevertheless be convenient when debugging programs.
1427
1428       $SYSTEMD_LOG_TARGET
1429           The destination for log messages. One of console (log to the
1430           attached tty), console-prefixed (log to the attached tty but with
1431           prefixes encoding the log level and "facility", see syslog(3), kmsg
1432           (log to the kernel circular log buffer), journal (log to the
1433           journal), journal-or-kmsg (log to the journal if available, and to
1434           kmsg otherwise), auto (determine the appropriate log target
1435           automatically, the default), null (disable log output).
1436
1437       $SYSTEMD_PAGER
1438           Pager to use when --no-pager is not given; overrides $PAGER. If
1439           neither $SYSTEMD_PAGER nor $PAGER are set, a set of well-known
1440           pager implementations are tried in turn, including less(1) and
1441           more(1), until one is found. If no pager implementation is
1442           discovered no pager is invoked. Setting this environment variable
1443           to an empty string or the value "cat" is equivalent to passing
1444           --no-pager.
1445
1446           Note: if $SYSTEMD_PAGERSECURE is not set, $SYSTEMD_PAGER (as well
1447           as $PAGER) will be silently ignored.
1448
1449       $SYSTEMD_LESS
1450           Override the options passed to less (by default "FRSXMK").
1451
1452           Users might want to change two options in particular:
1453
1454           K
1455               This option instructs the pager to exit immediately when Ctrl+C
1456               is pressed. To allow less to handle Ctrl+C itself to switch
1457               back to the pager command prompt, unset this option.
1458
1459               If the value of $SYSTEMD_LESS does not include "K", and the
1460               pager that is invoked is less, Ctrl+C will be ignored by the
1461               executable, and needs to be handled by the pager.
1462
1463           X
1464               This option instructs the pager to not send termcap
1465               initialization and deinitialization strings to the terminal. It
1466               is set by default to allow command output to remain visible in
1467               the terminal even after the pager exits. Nevertheless, this
1468               prevents some pager functionality from working, in particular
1469               paged output cannot be scrolled with the mouse.
1470
1471           See less(1) for more discussion.
1472
1473       $SYSTEMD_LESSCHARSET
1474           Override the charset passed to less (by default "utf-8", if the
1475           invoking terminal is determined to be UTF-8 compatible).
1476
1477       $SYSTEMD_PAGERSECURE
1478           Takes a boolean argument. When true, the "secure" mode of the pager
1479           is enabled; if false, disabled. If $SYSTEMD_PAGERSECURE is not set
1480           at all, secure mode is enabled if the effective UID is not the same
1481           as the owner of the login session, see geteuid(2) and
1482           sd_pid_get_owner_uid(3). In secure mode, LESSSECURE=1 will be set
1483           when invoking the pager, and the pager shall disable commands that
1484           open or create new files or start new subprocesses. When
1485           $SYSTEMD_PAGERSECURE is not set at all, pagers which are not known
1486           to implement secure mode will not be used. (Currently only less(1)
1487           implements secure mode.)
1488
1489           Note: when commands are invoked with elevated privileges, for
1490           example under sudo(8) or pkexec(1), care must be taken to ensure
1491           that unintended interactive features are not enabled. "Secure" mode
1492           for the pager may be enabled automatically as describe above.
1493           Setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited
1494           environment allows the user to invoke arbitrary commands. Note that
1495           if the $SYSTEMD_PAGER or $PAGER variables are to be honoured,
1496           $SYSTEMD_PAGERSECURE must be set too. It might be reasonable to
1497           completely disable the pager using --no-pager instead.
1498
1499       $SYSTEMD_COLORS
1500           Takes a boolean argument. When true, systemd and related utilities
1501           will use colors in their output, otherwise the output will be
1502           monochrome. Additionally, the variable can take one of the
1503           following special values: "16", "256" to restrict the use of colors
1504           to the base 16 or 256 ANSI colors, respectively. This can be
1505           specified to override the automatic decision based on $TERM and
1506           what the console is connected to.
1507
1508       $SYSTEMD_URLIFY
1509           The value must be a boolean. Controls whether clickable links
1510           should be generated in the output for terminal emulators supporting
1511           this. This can be specified to override the decision that systemd
1512           makes based on $TERM and other conditions.
1513

EXAMPLES

1515       Example 1. Download a Fedora image and start a shell in it
1516
1517           # machinectl pull-raw --verify=no \
1518                 https://download.fedoraproject.org/pub/fedora/linux/releases/37/Cloud/x86_64/images/Fedora-Cloud-Base-37-1.7.x86_64.raw.xz \
1519                 Fedora-Cloud-Base-37-1.7.x86-64
1520           # systemd-nspawn -M Fedora-Cloud-Base-37-1.7.x86-64
1521
1522       This downloads an image using machinectl(1) and opens a shell in it.
1523
1524       Example 2. Build and boot a minimal Fedora distribution in a container
1525
1526           # dnf -y --releasever=37 --installroot=/var/lib/machines/f37 \
1527                 --repo=fedora --repo=updates --setopt=install_weak_deps=False install \
1528                 passwd dnf fedora-release vim-minimal util-linux systemd systemd-networkd
1529           # systemd-nspawn -bD /var/lib/machines/f37
1530
1531       This installs a minimal Fedora distribution into the directory
1532       /var/lib/machines/f37 and then boots that OS in a namespace container.
1533       Because the installation is located underneath the standard
1534       /var/lib/machines/ directory, it is also possible to start the machine
1535       using systemd-nspawn -M f37.
1536
1537       Example 3. Spawn a shell in a container of a minimal Debian unstable
1538       distribution
1539
1540           # debootstrap unstable ~/debian-tree/
1541           # systemd-nspawn -D ~/debian-tree/
1542
1543       This installs a minimal Debian unstable distribution into the directory
1544       ~/debian-tree/ and then spawns a shell from this image in a namespace
1545       container.
1546
1547       debootstrap supports Debian[7], Ubuntu[8], and Tanglu[9] out of the
1548       box, so the same command can be used to install any of those. For other
1549       distributions from the Debian family, a mirror has to be specified, see
1550       debootstrap(8).
1551
1552       Example 4. Boot a minimal Arch Linux distribution in a container
1553
1554           # pacstrap -c ~/arch-tree/ base
1555           # systemd-nspawn -bD ~/arch-tree/
1556
1557       This installs a minimal Arch Linux distribution into the directory
1558       ~/arch-tree/ and then boots an OS in a namespace container in it.
1559
1560       Example 5. Install the OpenSUSE Tumbleweed rolling distribution
1561
1562           # zypper --root=/var/lib/machines/tumbleweed ar -c \
1563                 https://download.opensuse.org/tumbleweed/repo/oss tumbleweed
1564           # zypper --root=/var/lib/machines/tumbleweed refresh
1565           # zypper --root=/var/lib/machines/tumbleweed install --no-recommends \
1566                 systemd shadow zypper openSUSE-release vim
1567           # systemd-nspawn -M tumbleweed passwd root
1568           # systemd-nspawn -M tumbleweed -b
1569
1570       Example 6. Boot into an ephemeral snapshot of the host system
1571
1572           # systemd-nspawn -D / -xb
1573
1574       This runs a copy of the host system in a snapshot which is removed
1575       immediately when the container exits. All file system changes made
1576       during runtime will be lost on shutdown, hence.
1577
1578       Example 7. Run a container with SELinux sandbox security contexts
1579
1580           # chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 -R /srv/container
1581           # systemd-nspawn -L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \
1582                 -Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 -D /srv/container /bin/sh
1583
1584       Example 8. Run a container with an OSTree deployment
1585
1586           # systemd-nspawn -b -i ~/image.raw \
1587                 --pivot-root=/ostree/deploy/$OS/deploy/$CHECKSUM:/sysroot \
1588                 --bind=+/sysroot/ostree/deploy/$OS/var:/var
1589

EXIT STATUS

1591       The exit code of the program executed in the container is returned.
1592

SEE ALSO

1594       systemd(1), systemd.nspawn(5), chroot(1), dnf(8), debootstrap(8),
1595       pacman(8), zypper(8), systemd.slice(5), machinectl(1), btrfs(8)
1596

NOTES

1598        1. Container Interface
1599           https://systemd.io/CONTAINER_INTERFACE
1600
1601        2. Discoverable Partitions Specification
1602           https://uapi-group.org/specifications/specs/discoverable_partitions_specification
1603
1604        3. OCI Runtime Specification
1605           https://github.com/opencontainers/runtime-spec/blob/master/spec.md
1606
1607        4. OSTree
1608           https://ostree.readthedocs.io/en/latest/
1609
1610        5. Overlay Filesystem
1611           https://docs.kernel.org/filesystems/overlayfs.html
1612
1613        6. Fedora
1614           https://getfedora.org
1615
1616        7. Debian
1617           https://www.debian.org
1618
1619        8. Ubuntu
1620           https://www.ubuntu.com
1621
1622        9. Tanglu
1623           https://www.tanglu.org
1624
1625       10. Arch Linux
1626           https://www.archlinux.org
1627
1628       11. OpenSUSE Tumbleweed
1629           https://software.opensuse.org/distributions/tumbleweed
1630
1631
1632
1633systemd 253                                                  SYSTEMD-NSPAWN(1)
Impressum