Debian Codegraph @

upstream/opensuse-tumbleweed/man1/systemd-nspawn.1

raw
1 '\" t
2 .TH "SYSTEMD\-NSPAWN" "1" "" "systemd 260.1" "systemd-nspawn"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd-nspawn \- Spawn a command or OS in a lightweight container
24 .SH "SYNOPSIS"
25 .HP \w'\fBsystemd\-nspawn\fR\ 'u
26 \fBsystemd\-nspawn\fR [OPTIONS...] [\fICOMMAND\fR\ [ARGS...]]
27 .HP \w'\fBsystemd\-nspawn\fR\ 'u
28 \fBsystemd\-nspawn\fR \-\-boot [OPTIONS...] [ARGS...]
29 .SH "DESCRIPTION"
30 .PP
31 \fBsystemd\-nspawn\fR
32 may be used to run a command or OS in a lightweight namespace container\&. In many ways it is similar to
33 \fBchroot\fR(1), but more powerful since it virtualizes the file system hierarchy, as well as the process tree, the various IPC subsystems, and the host and domain names\&.
34 .PP
35 \fBsystemd\-nspawn\fR
36 may be invoked on any directory tree containing an operating system tree, using the
37 \fB\-\-directory=\fR
38 command line option\&. By using the
39 \fB\-\-machine=\fR
40 option an OS tree is automatically searched for in a couple of locations, most importantly in
41 /var/lib/machines/, the suggested directory to place OS container images installed on the system\&.
42 .PP
43 In contrast to
44 \fBchroot\fR(1)\ \&\fBsystemd\-nspawn\fR
45 may be used to boot full Linux\-based operating systems in a container\&.
46 .PP
47 \fBsystemd\-nspawn\fR
48 limits access to various kernel interfaces in the container to read\-only, such as
49 /sys/,
50 /proc/sys/, or
51 /sys/fs/selinux/\&. The host\*(Aqs network interfaces and the system clock may not be changed from within the container\&. Device nodes may not be created\&. The host system cannot be rebooted and kernel modules may not be loaded from within the container\&.
52 \fIThis sandbox can easily be circumvented from within the container if user namespaces are not used\fR\&. This means that untrusted code must always be run in a user namespace, see the discussion of the
53 \fB\-\-private\-users=\fR
54 option below\&.
55 .PP
56 Use a tool like
57 \fBdnf\fR(8),
58 \fBdebootstrap\fR(8), or
59 \fBpacman\fR(8)
60 to set up an OS directory tree suitable as file system hierarchy for
61 \fBsystemd\-nspawn\fR
62 containers\&. See the Examples section below for details on suitable invocation of these commands\&.
63 .PP
64 As a safety check
65 \fBsystemd\-nspawn\fR
66 will verify the existence of
67 /usr/lib/os\-release
68 or
69 /etc/os\-release
70 in the container tree before booting a container (see
71 \fBos-release\fR(5))\&. It might be necessary to add this file to the container tree manually if the OS of the container is too old to contain this file out\-of\-the\-box\&.
72 .PP
73 \fBsystemd\-nspawn\fR
74 may be invoked directly from the interactive command line or run as system service in the background\&. In this mode each container instance runs as its own service instance; a default template unit file
75 systemd\-nspawn@\&.service
76 is provided to make this easy, taking the container name as instance identifier\&. Note that different default options apply when
77 \fBsystemd\-nspawn\fR
78 is invoked by the template unit file than interactively on the command line\&. Most importantly the template unit file makes use of the
79 \fB\-\-boot\fR
80 option which is not the default in case
81 \fBsystemd\-nspawn\fR
82 is invoked from the interactive command line\&. Further differences with the defaults are documented along with the various supported options below\&.
83 .PP
84 The
85 \fBmachinectl\fR(1)
86 tool may be used to execute a number of operations on containers\&. In particular it provides easy\-to\-use commands to run containers as system services using the
87 systemd\-nspawn@\&.service
88 template unit file\&.
89 .PP
90 Along with each container a settings file with the
91 \&.nspawn
92 suffix may exist, containing additional settings to apply when running the container\&. See
93 \fBsystemd.nspawn\fR(5)
94 for details\&. Settings files override the default options used by the
95 systemd\-nspawn@\&.service
96 template unit file, making it usually unnecessary to alter this template file directly\&.
97 .PP
98 Note that
99 \fBsystemd\-nspawn\fR
100 will mount file systems private to the container to
101 /dev/,
102 /run/, and similar\&. These will not be visible outside of the container, and their contents will be lost when the container exits\&.
103 .PP
104 Note that running two
105 \fBsystemd\-nspawn\fR
106 containers from the same directory tree will not make processes in them see each other\&. The PID namespace separation of the two containers is complete and the containers will share very few runtime objects except for the underlying file system\&. Rather use
107 \fBmachinectl\fR(1)\*(Aqs
108 \fBlogin\fR
109 or
110 \fBshell\fR
111 commands to request an additional login session in a running container\&.
112 .PP
113 \fBsystemd\-nspawn\fR
114 implements the
115 \m[blue]\fBContainer Interface\fR\m[]\&\s-2\u[1]\d\s+2
116 specification\&.
117 .PP
118 While running, containers invoked with
119 \fBsystemd\-nspawn\fR
120 are registered with the
121 \fBsystemd-machined\fR(8)
122 service that keeps track of running containers, and provides programming interfaces to interact with them\&.
123 .SH "UNPRIVILEGED OPERATION"
124 .PP
125 \fBsystemd\-nspawn\fR
126 may be invoked with or without privileges\&. The full functionality is currently only available when invoked with privileges\&. When invoked without privileges, various limitations apply, including, but not limited to:
127 .sp
128 .RS 4
129 .ie n \{\
130 \h'-04'\(bu\h'+03'\c
131 .\}
132 .el \{\
133 .sp -1
134 .IP \(bu 2.3
135 .\}
136 Only disk image based containers are supported (i\&.e\&.
137 \fB\-\-image=\fR)\&. Directory based ones (i\&.e\&.
138 \fB\-\-directory=\fR) are only supported if owned by the "foreign" UID range\&.
139 .RE
140 .sp
141 .RS 4
142 .ie n \{\
143 \h'-04'\(bu\h'+03'\c
144 .\}
145 .el \{\
146 .sp -1
147 .IP \(bu 2.3
148 .\}
149 Only
150 \fB\-\-private\-network\fR
151 and
152 \fB\-\-network\-veth\fR
153 networking modes are supported\&.
154 .RE
155 .PP
156 When running in unprivileged mode, some needed functionality is provided via
157 \fBsystemd-mountfsd.service\fR(8)
158 and
159 \fBsystemd-nsresourced.service\fR(8)\&.
160 .SH "OPTIONS"
161 .PP
162 If option
163 \fB\-\-boot\fR
164 is specified, the arguments are used as arguments for the init program\&. Otherwise,
165 \fICOMMAND\fR
166 specifies the program to launch in the container, and the remaining arguments are used as arguments for this program\&. If
167 \fB\-\-boot\fR
168 is not used and no arguments are specified, a shell is launched in the container\&.
169 .PP
170 The following options are understood:
171 .PP
172 \fB\-q\fR, \fB\-\-quiet\fR
173 .RS 4
174 Turns off any status output by the tool itself\&. When this switch is used, the only output from nspawn will be the console output of the container OS itself\&.
175 .sp
176 Added in version 209\&.
177 .RE
178 .PP
179 \fB\-\-settings=\fR\fB\fIMODE\fR\fR
180 .RS 4
181 Controls whether
182 \fBsystemd\-nspawn\fR
183 shall search for and use additional per\-container settings from
184 \&.nspawn
185 files\&. Takes a boolean or the special values
186 \fBoverride\fR
187 or
188 \fBtrusted\fR\&.
189 .sp
190 If enabled (the default), a settings file named after the machine (as specified with the
191 \fB\-\-machine=\fR
192 setting, or derived from the directory or image file name) with the suffix
193 \&.nspawn
194 is searched in
195 /etc/systemd/nspawn/
196 and
197 /run/systemd/nspawn/\&. If it is found there, its settings are read and used\&. If it is not found there, it is subsequently searched in the same directory as the image file or in the immediate parent of the root directory of the container\&. In this case, if the file is found, its settings will be also read and used, but potentially unsafe settings are ignored\&. Note that in both these cases, settings on the command line take precedence over the corresponding settings from loaded
198 \&.nspawn
199 files, if both are specified\&. Unsafe settings are considered all settings that elevate the container\*(Aqs privileges or grant access to additional resources such as files or directories of the host\&. For details about the format and contents of
200 \&.nspawn
201 files, consult
202 \fBsystemd.nspawn\fR(5)\&.
203 .sp
204 If this option is set to
205 \fBoverride\fR, the file is searched, read and used the same way, however, the order of precedence is reversed: settings read from the
206 \&.nspawn
207 file will take precedence over the corresponding command line options, if both are specified\&.
208 .sp
209 If this option is set to
210 \fBtrusted\fR, the file is searched, read and used the same way, but regardless of being found in
211 /etc/systemd/nspawn/,
212 /run/systemd/nspawn/
213 or next to the image file or container root directory, all settings will take effect, however, command line arguments still take precedence over corresponding settings\&.
214 .sp
215 If disabled, no
216 \&.nspawn
217 file is read and no settings except the ones on the command line are in effect\&.
218 .sp
219 Added in version 226\&.
220 .RE
221 .PP
222 \fB\-\-cleanup\fR
223 .RS 4
224 Clean up left\-over mounts and underlying mount points used by the container, and exit without invoking any containers\&. This may be useful when the previous invocation of
225 \fBsystemd\-nspawn\fR
226 was unexpectedly terminated\&. This requires at least one of
227 \fB\-M/\-\-machine=\fR,
228 \fB\-D/\-\-directory=\fR, or
229 \fB\-i/\-\-image=\fR
230 to determine the mounts to be cleaned up\&.
231 .sp
232 Added in version 257\&.
233 .RE
234 .SS "Image Options"
235 .PP
236 \fB\-D\fR, \fB\-\-directory=\fR
237 .RS 4
238 Directory to use as file system root for the container\&.
239 .sp
240 If neither
241 \fB\-\-directory=\fR, nor
242 \fB\-\-image=\fR
243 is specified the directory is determined by searching for a directory named the same as the machine name specified with
244 \fB\-\-machine=\fR\&. See
245 \fBmachinectl\fR(1)
246 section "Files and Directories" for the precise search path\&.
247 .sp
248 In place of the directory path a
249 "\&.v/"
250 versioned directory may be specified, see
251 \fBsystemd.v\fR(7)
252 for details\&.
253 .sp
254 If neither
255 \fB\-\-directory=\fR,
256 \fB\-\-image=\fR, nor
257 \fB\-\-machine=\fR
258 are specified, the current directory will be used\&. May not be specified together with
259 \fB\-\-image=\fR\&.
260 .RE
261 .PP
262 \fB\-\-template=\fR
263 .RS 4
264 Directory or
265 "btrfs"
266 subvolume to use as template for the container\*(Aqs root directory\&. If this is specified and the container\*(Aqs root directory (as configured by
267 \fB\-\-directory=\fR) does not yet exist it is created as
268 "btrfs"
269 snapshot (if supported) or plain directory (otherwise) and populated from this template tree\&. Ideally, the specified template path refers to the root of a
270 "btrfs"
271 subvolume, in which case a simple copy\-on\-write snapshot is taken, and populating the root directory is instant\&. If the specified template path does not refer to the root of a
272 "btrfs"
273 subvolume (or not even to a
274 "btrfs"
275 file system at all), the tree is copied (though possibly in a \*(Aqreflink\*(Aq copy\-on\-write scheme \(em if the file system supports that), which can be substantially more time\-consuming\&. Note that the snapshot taken is of the specified directory or subvolume, including all subdirectories and subvolumes below it, but excluding any sub\-mounts\&. May not be specified together with
276 \fB\-\-image=\fR
277 or
278 \fB\-\-ephemeral\fR\&.
279 .sp
280 Note that this switch leaves hostname, machine ID and all other settings that could identify the instance unmodified\&.
281 .sp
282 Added in version 219\&.
283 .RE
284 .PP
285 \fB\-x\fR, \fB\-\-ephemeral\fR
286 .RS 4
287 If specified, the container is run with a temporary snapshot of its file system that is removed immediately when the container terminates\&. May not be specified together with
288 \fB\-\-template=\fR\&.
289 .sp
290 Note that this switch leaves hostname, machine ID and all other settings that could identify the instance unmodified\&. Please note that \(em as with
291 \fB\-\-template=\fR
292 \(em taking the temporary snapshot is more efficient on file systems that support subvolume snapshots or \*(Aqreflinks\*(Aq natively ("btrfs"
293 or new
294 "xfs") than on more traditional file systems that do not ("ext4")\&. Note that the snapshot taken is of the specified directory or subvolume, including all subdirectories and subvolumes below it, but excluding any sub\-mounts\&.
295 .sp
296 With this option no modifications of the container image are retained\&. Use
297 \fB\-\-volatile=\fR
298 (described below) for other mechanisms to restrict persistency of container images during runtime\&.
299 .sp
300 Added in version 219\&.
301 .RE
302 .PP
303 \fB\-i\fR, \fB\-\-image=\fR
304 .RS 4
305 Disk image to mount the root directory for the container from\&. Takes a path to a regular file or to a block device node\&. The file or block device must contain either:
306 .sp
307 .RS 4
308 .ie n \{\
309 \h'-04'\(bu\h'+03'\c
310 .\}
311 .el \{\
312 .sp -1
313 .IP \(bu 2.3
314 .\}
315 An MBR partition table with a single partition of type 0x83 that is marked bootable\&.
316 .RE
317 .sp
318 .RS 4
319 .ie n \{\
320 \h'-04'\(bu\h'+03'\c
321 .\}
322 .el \{\
323 .sp -1
324 .IP \(bu 2.3
325 .\}
326 A GUID partition table (GPT) with a single partition of type 0fc63daf\-8483\-4772\-8e79\-3d69d8477de4\&.
327 .RE
328 .sp
329 .RS 4
330 .ie n \{\
331 \h'-04'\(bu\h'+03'\c
332 .\}
333 .el \{\
334 .sp -1
335 .IP \(bu 2.3
336 .\}
337 A GUID partition table (GPT) with a marked root partition which is mounted as the root directory of the container\&. Optionally, GPT images may contain a home and/or a server data partition which are mounted to the appropriate places in the container\&. All these partitions must be identified by the partition types defined by the
338 \m[blue]\fBUAPI\&.2 Discoverable Partitions Specification\fR\m[]\&\s-2\u[2]\d\s+2\&.
339 .RE
340 .sp
341 .RS 4
342 .ie n \{\
343 \h'-04'\(bu\h'+03'\c
344 .\}
345 .el \{\
346 .sp -1
347 .IP \(bu 2.3
348 .\}
349 No partition table, and a single file system spanning the whole image\&.
350 .RE
351 .sp
352 On GPT images, if an EFI System Partition (ESP) is discovered, it is automatically mounted to
353 /efi
354 (or
355 /boot
356 as fallback) in case a directory by this name exists and is empty\&.
357 .sp
358 Partitions encrypted with LUKS are automatically decrypted\&. Also, on GPT images dm\-verity data integrity hash partitions are set up if the root hash for them is specified using the
359 \fB\-\-root\-hash=\fR
360 option\&.
361 .sp
362 Single file system images (i\&.e\&. file systems without a surrounding partition table) can be opened using dm\-verity if the integrity data is passed using the
363 \fB\-\-root\-hash=\fR
364 and
365 \fB\-\-verity\-data=\fR
366 (and optionally
367 \fB\-\-root\-hash\-sig=\fR) options\&.
368 .sp
369 Any other partitions, such as foreign partitions or swap partitions are not mounted\&. May not be specified together with
370 \fB\-\-directory=\fR,
371 \fB\-\-template=\fR\&.
372 .sp
373 In place of the image path a
374 "\&.v/"
375 versioned directory may be specified, see
376 \fBsystemd.v\fR(7)
377 for details\&.
378 .sp
379 Added in version 211\&.
380 .RE
381 .PP
382 \fB\-\-image\-policy=\fR\fB\fIpolicy\fR\fR
383 .RS 4
384 Takes an image policy string as argument, as per
385 \fBsystemd.image-policy\fR(7)\&. The policy is enforced when operating on the disk image specified via
386 \fB\-\-image=\fR, see above\&. If not specified, defaults to
387 "root=verity+signed+encrypted+unprotected+absent:usr=verity+signed+encrypted+unprotected+absent:home=encrypted+unprotected+absent:srv=encrypted+unprotected+absent:esp=unprotected+absent:xbootldr=unprotected+absent:tmp=encrypted+unprotected+absent:var=encrypted+unprotected+absent", i\&.e\&. all recognized file systems in the image are used, but not the swap partition\&.
388 .sp
389 Added in version 254\&.
390 .RE
391 .PP
392 \fB\-\-mstack=\fR
393 .RS 4
394 Mount stack to mount the root directory for the container from\&. Takes a path to a directory implementing
395 \fBsystemd.mstack\fR(7)\&. This may be used to run a container of an
396 "overlayfs"
397 assembled from a number of layers, possibly writable and augmented with additional bind mounts\&.
398 .sp
399 Added in version 260\&.
400 .RE
401 .PP
402 \fB\-\-oci\-bundle=\fR
403 .RS 4
404 Takes the path to an OCI runtime bundle to invoke, as specified in the
405 \m[blue]\fBOCI Runtime Specification\fR\m[]\&\s-2\u[3]\d\s+2\&. In this case, no
406 \&.nspawn
407 file is loaded, and the root directory and various settings are read from the OCI runtime JSON data (but data passed on the command line takes precedence)\&.
408 .sp
409 Added in version 242\&.
410 .RE
411 .PP
412 \fB\-\-read\-only\fR
413 .RS 4
414 Mount the container\*(Aqs root file system (and any other file systems contained in the container image) read\-only\&. This has no effect on additional mounts made with
415 \fB\-\-bind=\fR,
416 \fB\-\-tmpfs=\fR
417 and similar options\&. This mode is implied if the container image file or directory is marked read\-only itself\&. It is also implied if
418 \fB\-\-volatile=\fR
419 is used\&. In this case, the container image on disk is strictly read\-only, while changes are permitted but kept non\-persistently in memory only\&. For further details, see below\&.
420 .RE
421 .PP
422 \fB\-\-volatile\fR, \fB\-\-volatile=\fR\fB\fIMODE\fR\fR
423 .RS 4
424 Boots the container in volatile mode\&. When no mode parameter is passed or when mode is specified as
425 \fByes\fR, full volatile mode is enabled\&. This means the root directory is mounted as a mostly unpopulated
426 "tmpfs"
427 instance, and
428 /usr/
429 from the OS tree is mounted into it in read\-only mode (the system thus starts up with read\-only OS image, but pristine state and configuration, any changes are lost on shutdown)\&. When the mode parameter is specified as
430 \fBstate\fR, the OS tree is mounted read\-only, but
431 /var/
432 is mounted as a writable
433 "tmpfs"
434 instance into it (the system thus starts up with read\-only OS resources and configuration, but pristine state, and any changes to the latter are lost on shutdown)\&. When the mode parameter is specified as
435 \fBoverlay\fR
436 the read\-only root file system is combined with a writable
437 tmpfs
438 instance through
439 "overlayfs", so that it appears at it normally would, but any changes are applied to the temporary file system only and lost when the container is terminated\&. When the mode parameter is specified as
440 \fBno\fR
441 (the default), the whole OS tree is made available writable (unless
442 \fB\-\-read\-only\fR
443 is specified, see above)\&.
444 .sp
445 Note that if one of the volatile modes is chosen, its effect is limited to the root file system (or
446 /var/
447 in case of
448 \fBstate\fR), and any other mounts placed in the hierarchy are unaffected \(em regardless of whether they are established automatically (e\&.g\&. the EFI system partition that might be mounted to
449 /efi/
450 or
451 /boot/) or explicitly (e\&.g\&. through an additional command line option such as
452 \fB\-\-bind=\fR, see below)\&. This means, even if
453 \fB\-\-volatile=overlay\fR
454 is used changes to
455 /efi/
456 or
457 /boot/
458 are prohibited in case such a partition exists in the container image operated on, and even if
459 \fB\-\-volatile=state\fR
460 is used the hypothetical file
461 /etc/foobar
462 is potentially writable if
463 \fB\-\-bind=/etc/foobar\fR
464 is used to mount it from outside the read\-only container
465 /etc/
466 directory\&.
467 .sp
468 The
469 \fB\-\-ephemeral\fR
470 option is closely related to this setting, and provides similar behaviour by making a temporary, ephemeral copy of the whole OS image and executing that\&. For further details, see above\&.
471 .sp
472 The
473 \fB\-\-tmpfs=\fR
474 and
475 \fB\-\-overlay=\fR
476 options provide similar functionality, but for specific sub\-directories of the OS image only\&. For details, see below\&.
477 .sp
478 This option provides similar functionality for containers as the
479 "systemd\&.volatile="
480 kernel command line switch provides for host systems\&. See
481 \fBkernel-command-line\fR(7)
482 for details\&.
483 .sp
484 Note that setting this option to
485 \fByes\fR
486 or
487 \fBstate\fR
488 will only work correctly with operating systems in the container that can boot up with only
489 /usr/
490 mounted, and are able to automatically populate
491 /var/
492 (and
493 /etc/
494 in case of
495 "\-\-volatile=yes")\&. Specifically, this means that operating systems that follow the historic split of
496 /bin/
497 and
498 /lib/
499 (and related directories) from
500 /usr/
501 (i\&.e\&. where the former are not symlinks into the latter) are not supported by
502 "\-\-volatile=yes"
503 as container payload\&. The
504 \fBoverlay\fR
505 option does not require any particular preparations in the OS, but do note that
506 "overlayfs"
507 behaviour differs from regular file systems in a number of ways, and hence compatibility is limited\&.
508 .sp
509 Added in version 216\&.
510 .RE
511 .PP
512 \fB\-\-root\-hash=\fR
513 .RS 4
514 Takes a data integrity (dm\-verity) root hash specified in hexadecimal\&. This option enables data integrity checks using dm\-verity, if the used image contains the appropriate integrity data (see above)\&. The specified hash must match the root hash of integrity data, and is usually at least 256 bits (and hence 64 formatted hexadecimal characters) long (in case of SHA256 for example)\&. If this option is not specified, but the image file carries the
515 "user\&.verity\&.roothash"
516 extended file attribute (see
517 \fBxattr\fR(7)), then the root hash is read from it, also as formatted hexadecimal characters\&. If the extended file attribute is not found (or is not supported by the underlying file system), but a file with the
518 \&.roothash
519 suffix is found next to the image file, bearing otherwise the same name (except if the image has the
520 \&.raw
521 suffix, in which case the root hash file must not have it in its name), the root hash is read from it and automatically used, also as formatted hexadecimal characters\&.
522 .sp
523 Note that this configures the root hash for the root file system\&. Disk images may also contain separate file systems for the
524 /usr/
525 hierarchy, which may be Verity protected as well\&. The root hash for this protection may be configured via the
526 "user\&.verity\&.usrhash"
527 extended file attribute or via a
528 \&.usrhash
529 file adjacent to the disk image, following the same format and logic as for the root hash for the root file system described here\&. Note that there\*(Aqs currently no switch to configure the root hash for the
530 /usr/
531 from the command line\&.
532 .sp
533 Also see the
534 \fIRootHash=\fR
535 option in
536 \fBsystemd.exec\fR(5)\&.
537 .sp
538 Added in version 233\&.
539 .RE
540 .PP
541 \fB\-\-root\-hash\-sig=\fR
542 .RS 4
543 Takes a PKCS7 signature of the
544 \fB\-\-root\-hash=\fR
545 option\&. The semantics are the same as for the
546 \fIRootHashSignature=\fR
547 option, see
548 \fBsystemd.exec\fR(5)\&.
549 .sp
550 Added in version 246\&.
551 .RE
552 .PP
553 \fB\-\-verity\-data=\fR
554 .RS 4
555 Takes the path to a data integrity (dm\-verity) file\&. This option enables data integrity checks using dm\-verity, if a root\-hash is passed and if the used image itself does not contain the integrity data\&. The integrity data must be matched by the root hash\&. If this option is not specified, but a file with the
556 \&.verity
557 suffix is found next to the image file, bearing otherwise the same name (except if the image has the
558 \&.raw
559 suffix, in which case the verity data file must not have it in its name), the verity data is read from it and automatically used\&.
560 .sp
561 Added in version 246\&.
562 .RE
563 .PP
564 \fB\-\-pivot\-root=\fR
565 .RS 4
566 Pivot the specified directory to
567 /
568 inside the container, and either unmount the container\*(Aqs old root, or pivot it to another specified directory\&. Takes one of: a path argument \(em in which case the specified path will be pivoted to
569 /
570 and the old root will be unmounted; or a colon\-separated pair of new root path and pivot destination for the old root\&. The new root path will be pivoted to
571 /, and the old
572 /
573 will be pivoted to the other directory\&. Both paths must be absolute, and are resolved in the container\*(Aqs file system namespace\&.
574 .sp
575 This is for containers which have several bootable directories in them; for example, several
576 \fBostree\fR(1)
577 deployments\&. It emulates the behavior of the boot loader and the initrd which normally select which directory to mount as the root and start the container\*(Aqs PID 1 in\&.
578 .sp
579 Added in version 233\&.
580 .RE
581 .SS "Execution Options"
582 .PP
583 \fB\-a\fR, \fB\-\-as\-pid2\fR
584 .RS 4
585 Invoke the shell or specified program as process ID (PID) 2 instead of PID 1 (init)\&. By default, if neither this option nor
586 \fB\-\-boot\fR
587 is used, the selected program is run as the process with PID 1, a mode only suitable for programs that are aware of the special semantics that the process with PID 1 has on UNIX\&. For example, it needs to reap all processes reparented to it, and should implement
588 \fBsysvinit\fR
589 compatible signal handling (specifically: it needs to reboot on SIGINT, reexecute on SIGTERM, reload configuration on SIGHUP, and so on)\&. With
590 \fB\-\-as\-pid2\fR
591 a minimal stub init process is run as PID 1 and the selected program is executed as PID 2 (and hence does not need to implement any special semantics)\&. The stub init process will reap processes as necessary and react appropriately to signals\&. It is recommended to use this mode to invoke arbitrary commands in containers, unless they have been modified to run correctly as PID 1\&. Or in other words: this switch should be used for pretty much all commands, except when the command refers to an init or shell implementation, as these are generally capable of running correctly as PID 1\&. This option may not be combined with
592 \fB\-\-boot\fR\&.
593 .sp
594 Added in version 229\&.
595 .RE
596 .PP
597 \fB\-b\fR, \fB\-\-boot\fR
598 .RS 4
599 Automatically search for an init program and invoke it as PID 1, instead of a shell or a user supplied program\&. If this option is used, arguments specified on the command line are used as arguments for the init program\&. This option may not be combined with
600 \fB\-\-as\-pid2\fR\&.
601 .sp
602 The following table explains the different modes of invocation and relationship to
603 \fB\-\-as\-pid2\fR
604 (see above):
605 .sp
606 .it 1 an-trap
607 .nr an-no-space-flag 1
608 .nr an-break-flag 1
609 .br
610 .B Table\ \&1.\ \&Invocation Mode
611 .TS
612 allbox tab(:);
613 lB lB.
614 T{
615 Switch
616 T}:T{
617 Explanation
618 T}
619 .T&
620 l l
621 l l
622 l l.
623 T{
624 Neither \fB\-\-as\-pid2\fR nor \fB\-\-boot\fR specified
625 T}:T{
626 The passed parameters are interpreted as the command line, which is executed as PID 1 in the container\&.
627 T}
628 T{
629 \fB\-\-as\-pid2\fR specified
630 T}:T{
631 The passed parameters are interpreted as the command line, which is executed as PID 2 in the container\&. A stub init process is run as PID 1\&.
632 T}
633 T{
634 \fB\-\-boot\fR specified
635 T}:T{
636 An init program is automatically searched for and run as PID 1 in the container\&. The passed parameters are used as invocation parameters for this process\&.
637 T}
638 .TE
639 .sp 1
640 Note that
641 \fB\-\-boot\fR
642 is the default mode of operation if the
643 systemd\-nspawn@\&.service
644 template unit file is used\&.
645 .RE
646 .PP
647 \fB\-\-chdir=\fR
648 .RS 4
649 Change to the specified working directory before invoking the process in the container\&. Expects an absolute path in the container\*(Aqs file system namespace\&.
650 .sp
651 Added in version 229\&.
652 .RE
653 .PP
654 \fB\-E \fR\fB\fINAME\fR\fR\fB[=\fR\fB\fIVALUE\fR\fR\fB]\fR, \fB\-\-setenv=\fR\fB\fINAME\fR\fR\fB[=\fR\fB\fIVALUE\fR\fR\fB]\fR
655 .RS 4
656 Specifies an environment variable to pass to the init process in the container\&. This may be used to override the default variables or to set additional variables\&. It may be used more than once to set multiple variables\&. When
657 "="
658 and
659 \fIVALUE\fR
660 are omitted, the value of the variable with the same name in the program environment will be used\&.
661 .sp
662 Added in version 209\&.
663 .RE
664 .PP
665 \fB\-u\fR, \fB\-\-user=\fR
666 .RS 4
667 After transitioning into the container, change to the specified user defined in the container\*(Aqs user database\&. Like all other systemd\-nspawn features, this is not a security feature and provides protection against accidental destructive operations only\&.
668 .sp
669 Note that if credentials are used in combination with a non\-root
670 \fB\-\-user=\fR
671 (e\&.g\&.:
672 \fB\-\-set\-credential=\fR
673 or
674 \fB\-\-load\-credential=\fR), then
675 \fB\-\-no\-new\-privileges=yes\fR
676 must be used, and
677 \fB\-\-boot\fR
678 or
679 \fB\-\-as\-pid2\fR
680 must not be used, as the credentials would otherwise be unreadable by the container due to missing privileges after switching to the specified user\&.
681 .RE
682 .PP
683 \fB\-\-kill\-signal=\fR
684 .RS 4
685 Specify the process signal to send to the container\*(Aqs PID 1 when nspawn itself receives
686 \fBSIGTERM\fR, in order to trigger an orderly shutdown of the container\&. Defaults to
687 \fBSIGRTMIN+3\fR
688 if
689 \fB\-\-boot\fR
690 is used (on systemd\-compatible init systems
691 \fBSIGRTMIN+3\fR
692 triggers an orderly shutdown)\&. If
693 \fB\-\-boot\fR
694 is not used and this option is not specified, the container\*(Aqs processes are terminated abruptly via
695 \fBSIGKILL\fR\&. For a list of valid signals, see
696 \fBsignal\fR(7)\&.
697 .sp
698 Added in version 220\&.
699 .RE
700 .PP
701 \fB\-\-notify\-ready=\fR
702 .RS 4
703 Configures support for notifications from the container\*(Aqs init process\&.
704 \fB\-\-notify\-ready=\fR
705 takes a boolean\&. If false
706 \fBsystemd\-nspawn\fR
707 notifies the calling service manager with a
708 "READY=1"
709 message when the init process is created\&. If true it waits for a
710 "READY=1"
711 message from the init process in the VM before sending its own to the service manager\&. For more details about notifications see
712 \fBsd_notify\fR(3)\&.
713 .sp
714 Defaults to false\&. (Note that this is unlike the option of the same name to
715 \fBsystemd-vmspawn\fR(1)
716 that defaults to true\&.)
717 .sp
718 Added in version 231\&.
719 .RE
720 .PP
721 \fB\-\-suppress\-sync=\fR
722 .RS 4
723 Expects a boolean argument\&. If true, turns off any form of on\-disk file system synchronization for the container payload\&. This means all system calls such as
724 \fBsync\fR(2),
725 \fBfsync()\fR,
726 \fBsyncfs()\fR, \&... will execute no operation, and the
727 \fBO_SYNC\fR/\fBO_DSYNC\fR
728 flags to
729 \fBopen\fR(2)
730 and related calls will be made unavailable\&. This is potentially dangerous, as assumed data integrity guarantees to the container payload are not actually enforced (i\&.e\&. data assumed to have been written to disk might be lost if the system is shut down abnormally)\&. However, this can dramatically improve container runtime performance \(en as long as these guarantees are not required or desirable, for example because any data written by the container is of temporary, redundant nature, or just an intermediary artifact that will be further processed and finalized by a later step in a pipeline\&. Defaults to false\&.
731 .sp
732 Added in version 250\&.
733 .RE
734 .SS "System Identity Options"
735 .PP
736 \fB\-M\fR, \fB\-\-machine=\fR
737 .RS 4
738 Sets the machine name for this container\&. This name may be used to identify this container during its runtime (for example in tools like
739 \fBmachinectl\fR(1)
740 and similar), and is used to initialize the container\*(Aqs hostname (which the container can choose to override, however)\&. If not specified, the last component of the root directory path of the container is used, possibly suffixed with a random identifier in case
741 \fB\-\-ephemeral\fR
742 mode is selected\&. If the root directory selected is the host\*(Aqs root directory the host\*(Aqs hostname is used as default instead\&.
743 .sp
744 Added in version 202\&.
745 .RE
746 .PP
747 \fB\-\-hostname=\fR
748 .RS 4
749 Controls the hostname to set within the container, if different from the machine name\&. Expects a valid hostname as argument\&. If this option is used, the kernel hostname of the container will be set to this value, otherwise it will be initialized to the machine name as controlled by the
750 \fB\-\-machine=\fR
751 option described above\&. The machine name is used for various aspect of identification of the container from the outside, the kernel hostname configurable with this option is useful for the container to identify itself from the inside\&. It is usually a good idea to keep both forms of identification synchronized, in order to avoid confusion\&. It is hence recommended to avoid usage of this option, and use
752 \fB\-\-machine=\fR
753 exclusively\&. Note that regardless whether the container\*(Aqs hostname is initialized from the name set with
754 \fB\-\-hostname=\fR
755 or the one set with
756 \fB\-\-machine=\fR, the container can later override its kernel hostname freely on its own as well\&.
757 .sp
758 Added in version 239\&.
759 .RE
760 .PP
761 \fB\-\-uuid=\fR
762 .RS 4
763 Set the specified UUID for the container\&. The init system will initialize
764 /etc/machine\-id
765 from this if this file is not set yet\&. Note that this option takes effect only if
766 /etc/machine\-id
767 in the container is unpopulated\&.
768 .RE
769 .SS "Property Options"
770 .PP
771 \fB\-S\fR, \fB\-\-slice=\fR
772 .RS 4
773 Make the container part of the specified slice, instead of the default
774 machine\&.slice\&. This applies only if the machine is run in its own scope unit, i\&.e\&. if
775 \fB\-\-keep\-unit\fR
776 is not used\&.
777 .sp
778 Added in version 206\&.
779 .RE
780 .PP
781 \fB\-\-property=\fR
782 .RS 4
783 Set a unit property on the scope unit to register for the machine\&. This applies only if the machine is run in its own scope unit, i\&.e\&. if
784 \fB\-\-keep\-unit\fR
785 is not used\&. Takes unit property assignments in the same format as
786 \fBsystemctl set\-property\fR\&. This is useful to set memory limits and similar for the container\&.
787 .sp
788 Added in version 220\&.
789 .RE
790 .PP
791 \fB\-\-register=\fR
792 .RS 4
793 Controls whether the container is registered with
794 \fBsystemd-machined\fR(8)\&. Takes a boolean argument, which defaults to
795 "yes"\&. This option should be enabled when the container runs a full Operating System (more specifically: a system and service manager as PID 1), and is useful to ensure that the container is accessible via
796 \fBmachinectl\fR(1)
797 and shown by tools such as
798 \fBps\fR(1)\&. If the container does not run a service manager, it is recommended to set this option to
799 "no"\&.
800 .sp
801 Added in version 209\&.
802 .RE
803 .PP
804 \fB\-\-keep\-unit\fR
805 .RS 4
806 Instead of creating a transient scope unit to run the container in, simply use the service or scope unit
807 \fBsystemd\-nspawn\fR
808 has been invoked in\&. If
809 \fB\-\-register=yes\fR
810 is set this unit is registered with
811 \fBsystemd-machined\fR(8)\&. This switch should be used if
812 \fBsystemd\-nspawn\fR
813 is invoked from within a service unit, and the service unit\*(Aqs sole purpose is to run a single
814 \fBsystemd\-nspawn\fR
815 container\&. This option is not available if run from a user session\&.
816 .sp
817 Note that passing
818 \fB\-\-keep\-unit\fR
819 disables the effect of
820 \fB\-\-slice=\fR
821 and
822 \fB\-\-property=\fR\&. Use
823 \fB\-\-keep\-unit\fR
824 and
825 \fB\-\-register=no\fR
826 in combination to disable any kind of unit allocation or registration with
827 \fBsystemd\-machined\fR\&.
828 .sp
829 Added in version 209\&.
830 .RE
831 .SS "User Namespacing Options"
832 .PP
833 \fB\-\-private\-users=\fR
834 .RS 4
835 Controls user namespacing\&. If enabled, the container will run with its own private set of UNIX user and group ids (UIDs and GIDs)\&. This involves mapping the private UIDs/GIDs used in the container (starting with the container\*(Aqs root user 0 and up) to a range of UIDs/GIDs on the host that are not used for other purposes (usually in the range beyond the host\*(Aqs UID/GID 65536)\&. The parameter may be specified as follows:
836 .sp
837 .RS 4
838 .ie n \{\
839 \h'-04' 1.\h'+01'\c
840 .\}
841 .el \{\
842 .sp -1
843 .IP " 1." 4.2
844 .\}
845 If one or two colon\-separated numbers are specified, user namespacing is turned on\&. The first parameter specifies the first host UID/GID to assign to the container, the second parameter specifies the number of host UIDs/GIDs to assign to the container\&. If the second parameter is omitted, 65536 UIDs/GIDs are assigned\&.
846 .RE
847 .sp
848 .RS 4
849 .ie n \{\
850 \h'-04' 2.\h'+01'\c
851 .\}
852 .el \{\
853 .sp -1
854 .IP " 2." 4.2
855 .\}
856 If the parameter is
857 "yes", user namespacing is turned on\&. The UID/GID range to use is determined automatically from the file ownership of the root directory of the container\*(Aqs directory tree\&. To use this option, make sure to prepare the directory tree in advance, and ensure that all files and directories in it are owned by UIDs/GIDs in the range you\*(Aqd like to use\&. Also, make sure that used file ACLs exclusively reference UIDs/GIDs in the appropriate range\&. In this mode, the number of UIDs/GIDs assigned to the container is 65536, and the owner UID/GID of the root directory must be a multiple of 65536\&.
858 .RE
859 .sp
860 .RS 4
861 .ie n \{\
862 \h'-04' 3.\h'+01'\c
863 .\}
864 .el \{\
865 .sp -1
866 .IP " 3." 4.2
867 .\}
868 The special value
869 "pick"
870 turns on user namespacing\&. In this case the UID/GID range is automatically chosen\&. As first step, the file owner UID/GID of the root directory of the container\*(Aqs directory tree is read, and it is checked that no other container is currently using it\&. If this check is successful, the UID/GID range determined this way is used, similarly to the behavior if
871 "yes"
872 is specified\&. If the check is not successful (and thus the UID/GID range indicated in the root directory\*(Aqs file owner is already used elsewhere) a new \(en currently unused \(en UID/GID range of 65536 UIDs/GIDs is randomly chosen between the host UID/GIDs of 524288 and 1878982656, always starting at a multiple of 65536, and, if possible, consistently hashed from the machine name\&. This setting implies
873 \fB\-\-private\-users\-ownership=auto\fR
874 (see below), which possibly has the effect that the files and directories in the container\*(Aqs directory tree will be owned by the appropriate users of the range picked\&. Using this option makes user namespace behavior fully automatic\&. Note that the first invocation of a previously unused container image might result in picking a new UID/GID range for it, and thus in the (possibly expensive) file ownership adjustment operation\&. However, subsequent invocations of the container will be cheap (unless of course the picked UID/GID range is assigned to a different use by then)\&.
875 .RE
876 .sp
877 .RS 4
878 .ie n \{\
879 \h'-04' 4.\h'+01'\c
880 .\}
881 .el \{\
882 .sp -1
883 .IP " 4." 4.2
884 .\}
885 If the parameter is
886 "no", user namespacing is turned off\&. This is the default when
887 \fBsystemd\-nspawn\fR
888 is invoked directly\&. (Note that the
889 systemd\-nspawn@\&.service
890 unit enables private users\&.) This option is not secure and must not be used to run untrusted code\&.
891 .RE
892 .sp
893 .RS 4
894 .ie n \{\
895 \h'-04' 5.\h'+01'\c
896 .\}
897 .el \{\
898 .sp -1
899 .IP " 5." 4.2
900 .\}
901 If the parameter is
902 "identity", user namespacing is employed with an identity mapping for the first 65536 UIDs/GIDs\&. This is mostly equivalent to
903 \fB\-\-private\-users=0:65536\fR\&. While it does not provide UID/GID isolation, since all host and container UIDs/GIDs are chosen identically it does provide process capability isolation, but may be useful if proper user namespacing with distinct UID maps is not possible\&. This option is not secure and must not be used to run untrusted code\&.
904 .RE
905 .sp
906 .RS 4
907 .ie n \{\
908 \h'-04' 6.\h'+01'\c
909 .\}
910 .el \{\
911 .sp -1
912 .IP " 6." 4.2
913 .\}
914 If the parameter is
915 "managed", user namespacing is employed with in
916 \fImanaged\fR
917 mode, i\&.e\&. allocation of a UID range is delegated to
918 \fBsystemd-nsresourced.service\fR(8)\&. This mode is selected by default if invoked unprivileged, but can also be requested explicitly when privileged\&. In this mode a 64K UID range is automatically picked\&.
919 .RE
920 .sp
921 It is recommended to assign at least 65536 UIDs/GIDs to each container, so that the usable UID/GID range in the container covers 16 bits\&. For best security, do not assign overlapping UID/GID ranges to multiple containers\&. It is hence a good idea to use the upper 16 bit of the host 32\-bit UIDs/GIDs as container identifier, while the lower 16 bits encode the container UID/GID used\&. This is in fact the behavior enforced by the
922 \fB\-\-private\-users=pick\fR
923 option\&.
924 .sp
925 When user namespaces are used, the GID range assigned to each container is always chosen identical to the UID range\&.
926 .sp
927 In most cases,
928 \fB\-\-private\-users=managed\fR
929 (or when privileged
930 \fB\-\-private\-users=pick\fR, too) is the recommended option as user namespacing is advised for security, and this option massively enhances container security while operating fully automatically in most cases\&.
931 .sp
932 Note that the picked UID/GID range is not written to
933 /etc/passwd
934 or
935 /etc/group\&. In fact, the allocation of the range is not stored persistently, except possibly in the file ownership of the files and directories of the container, see
936 \fB\-\-private\-users\-ownership=\fR\&.
937 .sp
938 Note that when user namespacing is used without UID mapping (see below) file ownership on disk reflects this, and all of the container\*(Aqs files and directories are owned by the container\*(Aqs effective user and group IDs\&. This means that copying files from and to the container image requires correction of the numeric UID/GID values, according to the UID/GID shift applied\&.
939 .sp
940 Note that for fully unprivileged operation in
941 "managed"
942 mode, any directory image should be owned by the foreign UID range\&.
943 .sp
944 Added in version 220\&.
945 .RE
946 .PP
947 \fB\-\-private\-users\-ownership=\fR
948 .RS 4
949 Controls how to adjust the container image\*(Aqs UIDs and GIDs to match the UID/GID range chosen with
950 \fB\-\-private\-users=\fR, see above\&. Takes one of
951 "off"
952 (to leave the image as is),
953 "chown"
954 (to recursively
955 \fBchown()\fR
956 the container\*(Aqs directory tree as needed),
957 "map"
958 (in order to use transparent ID mapping mounts from UID 0 to the target UID range),
959 "foreign"
960 (the same, but from the foreign UID range base) or
961 "auto"
962 for automatically using
963 "map"
964 or
965 "foreign", where available and applicable and
966 "chown"
967 where not\&.
968 .sp
969 If
970 "chown"
971 is selected, all files and directories in the container\*(Aqs directory tree will be adjusted so that they are owned by the appropriate UIDs/GIDs selected for the container (see above)\&. This operation is potentially expensive, as it involves iterating through the full directory tree of the container\&. Besides actual file ownership, file ACLs are adjusted as well\&.
972 .sp
973 Typically
974 "foreign"
975 or
976 "map"
977 is the best choice, since it transparently maps UIDs/GIDs in memory as needed without modifying the image, and without requiring an expensive recursive adjustment operation\&. However, it is not available for all file systems, currently\&.
978 .sp
979 The
980 \fB\-\-private\-users\-ownership=auto\fR
981 option is implied if
982 \fB\-\-private\-users=pick\fR
983 is used\&. This option has no effect if user namespacing is not used\&.
984 .sp
985 \fBsystemd-dissect\fR(1)\*(Aqs
986 \fB\-\-shift\fR
987 switch may be used to shift UID/GID ownership from or to the 0, foreign or specific container UID/GID base outside of any
988 \fBsystemd\-nspawn\fR
989 invocation\&.
990 .sp
991 Added in version 230\&.
992 .RE
993 .PP
994 \fB\-\-private\-users\-delegate=\fR
995 .RS 4
996 Takes a non\-negative integer\&. Requests that the specified number of additional 64K UID/GID ranges are delegated into the container\*(Aqs user namespace\&. These delegated ranges are mapped 1:1 (i\&.e\&. the same UID/GID values are used inside and outside the user namespace) and can be used by nested containers to allocate their own transient UID/GID ranges via
997 \fBsystemd-nsresourced.service\fR(8)\&.
998 .sp
999 This option requires
1000 \fB\-\-private\-users=managed\fR, as the delegation is performed by
1001 \fBsystemd-nsresourced.service\fR(8)
1002 as part of the user namespace allocation\&. The maximum number of delegated ranges is 16\&. Defaults to 0, i\&.e\&. no delegation\&.
1003 .sp
1004 When this option is used with a non\-zero value, the
1005 \fBsystemd-nsresourced.service\fR(8)
1006 Varlink socket (/run/systemd/io\&.systemd\&.NamespaceResource) is automatically bind\-mounted into the container along with the necessary discovery symlinks in
1007 /run/systemd/userdb/
1008 and
1009 /run/varlink/registry/\&. This allows processes inside the container to contact
1010 \fBsystemd\-nsresourced\fR
1011 on the host in order to allocate nested user namespaces from the delegated ranges\&.
1012 .sp
1013 Added in version 260\&.
1014 .RE
1015 .PP
1016 \fB\-U\fR
1017 .RS 4
1018 If the kernel supports the user namespaces feature, equivalent to
1019 \fB\-\-private\-users=pick \-\-private\-users\-ownership=auto\fR, otherwise equivalent to
1020 \fB\-\-private\-users=no\fR\&.
1021 .sp
1022 Note that
1023 \fB\-U\fR
1024 is the default if the
1025 systemd\-nspawn@\&.service
1026 template unit file is used\&.
1027 .sp
1028 Note: it is possible to undo the effect of
1029 \fB\-\-private\-users\-ownership=chown\fR
1030 (or
1031 \fB\-U\fR) on the file system by redoing the operation with the first UID of 0:
1032 .sp
1033 .if n \{\
1034 .RS 4
1035 .\}
1036 .nf
1037 systemd\-nspawn \&... \-\-private\-users=0 \-\-private\-users\-ownership=chown
1038 .fi
1039 .if n \{\
1040 .RE
1041 .\}
1042 .sp
1043 Added in version 230\&.
1044 .RE
1045 .SS "Networking Options"
1046 .PP
1047 \fB\-\-private\-network\fR
1048 .RS 4
1049 Disconnect networking of the container from the host\&. This makes all network interfaces unavailable in the container, with the exception of the loopback device and those specified with
1050 \fB\-\-network\-interface=\fR
1051 and configured with
1052 \fB\-\-network\-veth\fR\&. If this option is specified, the
1053 \fBCAP_NET_ADMIN\fR
1054 capability will be added to the set of capabilities the container retains\&. The latter may be disabled by using
1055 \fB\-\-drop\-capability=\fR\&. If this option is not specified (or implied by one of the options listed below), the container will have full access to the host network\&.
1056 .RE
1057 .PP
1058 \fB\-\-network\-interface=\fR
1059 .RS 4
1060 Assign the specified network interface to the container\&. Either takes a single interface name, referencing the name on the host, or a colon\-separated pair of interfaces, in which case the first one references the name on the host, and the second one the name in the container\&. When the container terminates, the interface is moved back to the calling namespace and renamed to its original name\&. Note that
1061 \fB\-\-network\-interface=\fR
1062 implies
1063 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1064 .sp
1065 Note that any network interface specified this way must already exist at the time the container is started\&. If the container shall be started automatically at boot via a
1066 systemd\-nspawn@\&.service
1067 unit file instance, it might hence make sense to add a unit file drop\-in to the service instance (e\&.g\&.
1068 /etc/systemd/system/systemd\-nspawn@foobar\&.service\&.d/50\-network\&.conf) with contents like the following:
1069 .sp
1070 .if n \{\
1071 .RS 4
1072 .\}
1073 .nf
1074 [Unit]
1075 Wants=sys\-subsystem\-net\-devices\-ens1\&.device
1076 After=sys\-subsystem\-net\-devices\-ens1\&.device
1077 .fi
1078 .if n \{\
1079 .RE
1080 .\}
1081 .sp
1082 This will make sure that activation of the container service will be delayed until the
1083 "ens1"
1084 network interface has shown up\&. This is required since hardware probing is fully asynchronous, and network interfaces might be discovered only later during the boot process, after the container would normally be started without these explicit dependencies\&.
1085 .sp
1086 Added in version 209\&.
1087 .RE
1088 .PP
1089 \fB\-\-network\-macvlan=\fR
1090 .RS 4
1091 Create a
1092 "macvlan"
1093 interface of the specified Ethernet network interface and add it to the container\&. Either takes a single interface name, referencing the name on the host, or a colon\-separated pair of interfaces, in which case the first one references the name on the host, and the second one the name in the container\&. A
1094 "macvlan"
1095 interface is a virtual interface that adds a second MAC address to an existing physical Ethernet link\&. If the container interface name is not defined, the interface in the container will be named after the interface on the host, prefixed with
1096 "mv\-"\&. Note that
1097 \fB\-\-network\-macvlan=\fR
1098 implies
1099 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1100 .sp
1101 As with
1102 \fB\-\-network\-interface=\fR, the underlying Ethernet network interface must already exist at the time the container is started, and thus similar unit file drop\-ins as described above might be useful\&.
1103 .sp
1104 Added in version 211\&.
1105 .RE
1106 .PP
1107 \fB\-\-network\-ipvlan=\fR
1108 .RS 4
1109 Create an
1110 "ipvlan"
1111 interface of the specified Ethernet network interface and add it to the container\&. Either takes a single interface name, referencing the name on the host, or a colon\-separated pair of interfaces, in which case the first one references the name on the host, and the second one the name in the container\&. An
1112 "ipvlan"
1113 interface is a virtual interface, similar to a
1114 "macvlan"
1115 interface, which uses the same MAC address as the underlying interface\&. If the container interface name is not defined, the interface in the container will be named after the interface on the host, prefixed with
1116 "iv\-"\&. Note that
1117 \fB\-\-network\-ipvlan=\fR
1118 implies
1119 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1120 .sp
1121 As with
1122 \fB\-\-network\-interface=\fR, the underlying Ethernet network interface must already exist at the time the container is started, and thus similar unit file drop\-ins as described above might be useful\&.
1123 .sp
1124 Added in version 219\&.
1125 .RE
1126 .PP
1127 \fB\-n\fR, \fB\-\-network\-veth\fR
1128 .RS 4
1129 Create a virtual Ethernet link ("veth") between host and container\&. The host side of the Ethernet link will be available as a network interface named after the container\*(Aqs name (as specified with
1130 \fB\-\-machine=\fR), prefixed with
1131 "ve\-"\&. The container side of the Ethernet link will be named
1132 "host0"\&. The
1133 \fB\-\-network\-veth\fR
1134 option implies
1135 \fB\-\-private\-network\fR\&.
1136 .sp
1137 Note that
1138 \fBsystemd-networkd.service\fR(8)
1139 includes by default a network file
1140 /usr/lib/systemd/network/80\-container\-ve\&.network
1141 matching the host\-side interfaces created this way, which contains settings to enable automatic address provisioning on the created virtual link via DHCP, as well as automatic IP routing onto the host\*(Aqs external network interfaces\&. It also contains
1142 /usr/lib/systemd/network/80\-container\-host0\&.network
1143 matching the container\-side interface created this way, containing settings to enable client side address assignment via DHCP\&. In case
1144 systemd\-networkd
1145 is running on both the host and inside the container, automatic IP communication from the container to the host is thus available, with further connectivity to the external network\&.
1146 .sp
1147 Note that
1148 \fB\-\-network\-veth\fR
1149 is the default if the
1150 systemd\-nspawn@\&.service
1151 template unit file is used\&.
1152 .sp
1153 Note that on Linux network interface names may have a length of 15 characters at maximum, while container names may have a length up to 64 characters\&. As this option derives the host\-side interface name from the container name the name is possibly truncated\&. Thus, care needs to be taken to ensure that interface names remain unique in this case, or even better container names are generally not chosen longer than 12 characters, to avoid the truncation\&. If the name is truncated,
1154 \fBsystemd\-nspawn\fR
1155 will automatically append a 4\-digit hash value to the name to reduce the chance of collisions\&. However, the hash algorithm is not collision\-free\&. (See
1156 \fBsystemd.net-naming-scheme\fR(7)
1157 for details on older naming algorithms for this interface)\&. Alternatively, the
1158 \fB\-\-network\-veth\-extra=\fR
1159 option may be used, which allows free configuration of the host\-side interface name independently of the container name \(em but might require a bit more additional configuration in case bridging in a fashion similar to
1160 \fB\-\-network\-bridge=\fR
1161 is desired\&.
1162 .sp
1163 Added in version 209\&.
1164 .RE
1165 .PP
1166 \fB\-\-network\-veth\-extra=\fR
1167 .RS 4
1168 Adds an additional virtual Ethernet link between host and container\&. Takes a colon\-separated pair of host interface name and container interface name\&. The latter may be omitted in which case the container and host sides will be assigned the same name\&. This switch is independent of
1169 \fB\-\-network\-veth\fR, and \(em in contrast \(em may be used multiple times, and allows configuration of the network interface names\&. Note that
1170 \fB\-\-network\-bridge=\fR
1171 has no effect on interfaces created with
1172 \fB\-\-network\-veth\-extra=\fR\&.
1173 .sp
1174 Added in version 228\&.
1175 .RE
1176 .PP
1177 \fB\-\-network\-bridge=\fR
1178 .RS 4
1179 Adds the host side of the Ethernet link created with
1180 \fB\-\-network\-veth\fR
1181 to the specified Ethernet bridge interface\&. Expects a valid network interface name of a bridge device as argument\&. Note that
1182 \fB\-\-network\-bridge=\fR
1183 implies
1184 \fB\-\-network\-veth\fR\&. If this option is used, the host side of the Ethernet link will use the
1185 "vb\-"
1186 prefix instead of
1187 "ve\-"\&. Regardless of the used naming prefix the same network interface name length limits imposed by Linux apply, along with the complications this creates (for details see above)\&.
1188 .sp
1189 As with
1190 \fB\-\-network\-interface=\fR, the underlying bridge network interface must already exist at the time the container is started, and thus similar unit file drop\-ins as described above might be useful\&.
1191 .sp
1192 Added in version 209\&.
1193 .RE
1194 .PP
1195 \fB\-\-network\-zone=\fR
1196 .RS 4
1197 Creates a virtual Ethernet link ("veth") to the container and adds it to an automatically managed Ethernet bridge interface\&. The bridge interface is named after the passed argument, prefixed with
1198 "vz\-"\&. The bridge interface is automatically created when the first container configured for its name is started, and is automatically removed when the last container configured for its name exits\&. Hence, each bridge interface configured this way exists only as long as there\*(Aqs at least one container referencing it running\&. This option is very similar to
1199 \fB\-\-network\-bridge=\fR, besides this automatic creation/removal of the bridge device\&.
1200 .sp
1201 This setting makes it easy to place multiple related containers on a common, virtual Ethernet\-based broadcast domain, here called a "zone"\&. Each container may only be part of one zone, but each zone may contain any number of containers\&. Each zone is referenced by its name\&. Names may be chosen freely (as long as they form valid network interface names when prefixed with
1202 "vz\-"), and it is sufficient to pass the same name to the
1203 \fB\-\-network\-zone=\fR
1204 switch of the various concurrently running containers to join them in one zone\&.
1205 .sp
1206 Note that
1207 \fBsystemd-networkd.service\fR(8)
1208 includes by default a network file
1209 /usr/lib/systemd/network/80\-container\-vz\&.network
1210 matching the bridge interfaces created this way, which contains settings to enable automatic address provisioning on the created virtual network via DHCP, as well as automatic IP routing onto the host\*(Aqs external network interfaces\&. Using
1211 \fB\-\-network\-zone=\fR
1212 is hence in most cases fully automatic and sufficient to connect multiple local containers in a joined broadcast domain to the host, with further connectivity to the external network\&.
1213 .sp
1214 Added in version 230\&.
1215 .RE
1216 .PP
1217 \fB\-\-network\-namespace\-path=\fR
1218 .RS 4
1219 Takes the path to a file representing a kernel network namespace that the container shall run in\&. The specified path should refer to a (possibly bind\-mounted) network namespace file, as exposed by the kernel below
1220 /proc/$PID/ns/net\&. This makes the container enter the given network namespace\&. One of the typical use cases is to give a network namespace under
1221 /run/netns
1222 created by
1223 \fBip-netns\fR(8), for example,
1224 \fB\-\-network\-namespace\-path=/run/netns/foo\fR\&. Note that this option cannot be used together with other network\-related options, such as
1225 \fB\-\-private\-network\fR
1226 or
1227 \fB\-\-network\-interface=\fR\&.
1228 .sp
1229 Added in version 236\&.
1230 .RE
1231 .PP
1232 \fB\-p\fR, \fB\-\-port=\fR
1233 .RS 4
1234 If private networking is enabled, maps an IP port on the host onto an IP port on the container\&. Takes a protocol specifier (either
1235 "tcp"
1236 or
1237 "udp"), separated by a colon from a host port number in the range 1 to 65535, separated by a colon from a container port number in the range from 1 to 65535\&. The protocol specifier and its separating colon may be omitted, in which case
1238 "tcp"
1239 is assumed\&. The container port number and its colon may be omitted, in which case the same port as the host port is implied\&. This option is only supported if private networking is used, such as with
1240 \fB\-\-network\-veth\fR,
1241 \fB\-\-network\-zone=\fR
1242 \fB\-\-network\-bridge=\fR\&.
1243 .sp
1244 Added in version 219\&.
1245 .RE
1246 .SS "Security Options"
1247 .PP
1248 \fB\-\-capability=\fR
1249 .RS 4
1250 List one or more additional capabilities to grant the container\&. Takes a comma\-separated list of capability names, see
1251 \fBcapabilities\fR(7)
1252 for more information\&. Note that the following capabilities will be granted in any way:
1253 \fBCAP_AUDIT_CONTROL\fR,
1254 \fBCAP_AUDIT_WRITE\fR,
1255 \fBCAP_CHOWN\fR,
1256 \fBCAP_DAC_OVERRIDE\fR,
1257 \fBCAP_DAC_READ_SEARCH\fR,
1258 \fBCAP_FOWNER\fR,
1259 \fBCAP_FSETID\fR,
1260 \fBCAP_IPC_OWNER\fR,
1261 \fBCAP_KILL\fR,
1262 \fBCAP_LEASE\fR,
1263 \fBCAP_LINUX_IMMUTABLE\fR,
1264 \fBCAP_MKNOD\fR,
1265 \fBCAP_NET_BIND_SERVICE\fR,
1266 \fBCAP_NET_BROADCAST\fR,
1267 \fBCAP_NET_RAW\fR,
1268 \fBCAP_SETFCAP\fR,
1269 \fBCAP_SETGID\fR,
1270 \fBCAP_SETPCAP\fR,
1271 \fBCAP_SETUID\fR,
1272 \fBCAP_SYS_ADMIN\fR,
1273 \fBCAP_SYS_BOOT\fR,
1274 \fBCAP_SYS_CHROOT\fR,
1275 \fBCAP_SYS_NICE\fR,
1276 \fBCAP_SYS_PTRACE\fR,
1277 \fBCAP_SYS_RESOURCE\fR,
1278 \fBCAP_SYS_TTY_CONFIG\fR\&. Also
1279 \fBCAP_NET_ADMIN\fR
1280 is retained if
1281 \fB\-\-private\-network\fR
1282 is specified\&. If the special value
1283 "all"
1284 is passed, all capabilities are retained\&.
1285 .sp
1286 If the special value of
1287 "help"
1288 is passed, the program will print known capability names and exit\&.
1289 .sp
1290 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1291 \fB\-\-ambient\-capability=\fR\&.
1292 .sp
1293 Added in version 186\&.
1294 .RE
1295 .PP
1296 \fB\-\-drop\-capability=\fR
1297 .RS 4
1298 Specify one or more additional capabilities to drop for the container\&. This allows running the container with fewer capabilities than the default (see above)\&.
1299 .sp
1300 If the special value of
1301 "help"
1302 is passed, the program will print known capability names and exit\&.
1303 .sp
1304 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1305 \fB\-\-ambient\-capability=\fR\&.
1306 .sp
1307 Added in version 209\&.
1308 .RE
1309 .PP
1310 \fB\-\-ambient\-capability=\fR
1311 .RS 4
1312 Specify one or more additional capabilities to pass in the inheritable and ambient set to the program started within the container\&. The value
1313 "all"
1314 is not supported for this setting\&.
1315 .sp
1316 All capabilities specified here must be in the set allowed with the
1317 \fB\-\-capability=\fR
1318 and
1319 \fB\-\-drop\-capability=\fR
1320 options\&. Otherwise, an error message will be shown\&.
1321 .sp
1322 This option cannot be combined with the boot mode of the container (as requested via
1323 \fB\-\-boot\fR)\&.
1324 .sp
1325 If the special value of
1326 "help"
1327 is passed, the program will print known capability names and exit\&.
1328 .sp
1329 Added in version 248\&.
1330 .RE
1331 .PP
1332 \fB\-\-no\-new\-privileges=\fR
1333 .RS 4
1334 Takes a boolean argument\&. Specifies the value of the
1335 \fBPR_SET_NO_NEW_PRIVS\fR
1336 flag for the container payload\&. Defaults to off\&. When turned on the payload code of the container cannot acquire new privileges, i\&.e\&. the "setuid" file bit as well as file system capabilities will not have an effect anymore\&. See
1337 \fBprctl\fR(2)
1338 for details about this flag\&.
1339 .sp
1340 Added in version 239\&.
1341 .RE
1342 .PP
1343 \fB\-\-system\-call\-filter=\fR
1344 .RS 4
1345 Alter the system call filter applied to containers\&. Takes a space\-separated list of system call names or group names (the latter prefixed with
1346 "@", as listed by the
1347 \fBsyscall\-filter\fR
1348 command of
1349 \fBsystemd-analyze\fR(1))\&. Passed system calls will be permitted\&. The list may optionally be prefixed by
1350 "~", in which case all listed system calls are prohibited\&. If this command line option is used multiple times the configured lists are combined\&. If both a positive and a negative list (that is one system call list without and one with the
1351 "~"
1352 prefix) are configured, the negative list takes precedence over the positive list\&. Note that
1353 \fBsystemd\-nspawn\fR
1354 always implements a system call allow list (as opposed to a deny list!), and this command line option hence adds or removes entries from the default allow list, depending on the
1355 "~"
1356 prefix\&. Note that the applied system call filter is also altered implicitly if additional capabilities are passed using the
1357 \fB\-\-capabilities=\fR\&.
1358 .sp
1359 Added in version 235\&.
1360 .RE
1361 .PP
1362 \fB\-Z\fR, \fB\-\-selinux\-context=\fR
1363 .RS 4
1364 Sets the SELinux security context to be used to label processes in the container\&.
1365 .sp
1366 Added in version 209\&.
1367 .RE
1368 .PP
1369 \fB\-L\fR, \fB\-\-selinux\-apifs\-context=\fR
1370 .RS 4
1371 Sets the SELinux security context to be used to label files in the virtual API file systems in the container\&.
1372 .sp
1373 Added in version 209\&.
1374 .RE
1375 .SS "Resource Options"
1376 .PP
1377 \fB\-\-rlimit=\fR
1378 .RS 4
1379 Sets the specified POSIX resource limit for the container payload\&. Expects an assignment of the form
1380 "\fILIMIT\fR=\fISOFT\fR:\fIHARD\fR"
1381 or
1382 "\fILIMIT\fR=\fIVALUE\fR", where
1383 \fILIMIT\fR
1384 should refer to a resource limit type, such as
1385 \fBRLIMIT_NOFILE\fR
1386 or
1387 \fBRLIMIT_NICE\fR\&. The
1388 \fISOFT\fR
1389 and
1390 \fIHARD\fR
1391 fields should refer to the numeric soft and hard resource limit values\&. If the second form is used,
1392 \fIVALUE\fR
1393 may specify a value that is used both as soft and hard limit\&. In place of a numeric value the special string
1394 "infinity"
1395 may be used to turn off resource limiting for the specific type of resource\&. This command line option may be used multiple times to control limits on multiple limit types\&. If used multiple times for the same limit type, the last use wins\&. For details about resource limits see
1396 \fBsetrlimit\fR(2)\&. By default resource limits for the container\*(Aqs init process (PID 1) are set to the same values the Linux kernel originally passed to the host init system\&. Note that some resource limits are enforced on resources counted per user, in particular
1397 \fBRLIMIT_NPROC\fR\&. This means that unless user namespacing is deployed (i\&.e\&.
1398 \fB\-\-private\-users=\fR
1399 is used, see above), any limits set will be applied to the resource usage of the same user on all local containers as well as the host\&. This means particular care needs to be taken with these limits as they might be triggered by possibly less trusted code\&. Example:
1400 "\-\-rlimit=RLIMIT_NOFILE=8192:16384"\&.
1401 .sp
1402 Added in version 239\&.
1403 .RE
1404 .PP
1405 \fB\-\-oom\-score\-adjust=\fR
1406 .RS 4
1407 Changes the OOM ("Out Of Memory") score adjustment value for the container payload\&. This controls
1408 /proc/self/oom_score_adj
1409 which influences the preference with which this container is terminated when memory becomes scarce\&. For details see
1410 \fBproc\fR(5)\&. Takes an integer in the range \-1000\&...1000\&.
1411 .sp
1412 Added in version 239\&.
1413 .RE
1414 .PP
1415 \fB\-\-cpu\-affinity=\fR
1416 .RS 4
1417 Controls the CPU affinity of the container payload\&. Takes a comma separated list of CPU numbers or number ranges (the latter\*(Aqs start and end value separated by dashes)\&. See
1418 \fBsched_setaffinity\fR(2)
1419 for details\&.
1420 .sp
1421 Added in version 239\&.
1422 .RE
1423 .PP
1424 \fB\-\-personality=\fR
1425 .RS 4
1426 Control the architecture ("personality") reported by
1427 \fBuname\fR(2)
1428 in the container\&. Currently, only
1429 "x86"
1430 and
1431 "x86\-64"
1432 are supported\&. This is useful when running a 32\-bit container on a 64\-bit host\&. If this setting is not used, the personality reported in the container is the same as the one reported on the host\&.
1433 .sp
1434 Added in version 209\&.
1435 .RE
1436 .SS "Integration Options"
1437 .PP
1438 \fB\-\-resolv\-conf=\fR
1439 .RS 4
1440 Configures how
1441 /etc/resolv\&.conf
1442 inside of the container shall be handled (i\&.e\&. DNS configuration synchronization from host to container)\&. Takes one of
1443 "off",
1444 "copy\-host",
1445 "copy\-static",
1446 "copy\-uplink",
1447 "copy\-stub",
1448 "replace\-host",
1449 "replace\-static",
1450 "replace\-uplink",
1451 "replace\-stub",
1452 "bind\-host",
1453 "bind\-static",
1454 "bind\-uplink",
1455 "bind\-stub",
1456 "delete"
1457 or
1458 "auto"\&.
1459 .sp
1460 If set to
1461 "off"
1462 the
1463 /etc/resolv\&.conf
1464 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&.
1465 .sp
1466 If set to
1467 "copy\-host", the
1468 /etc/resolv\&.conf
1469 file from the host is copied into the container, unless the file exists already and is not a regular file (e\&.g\&. a symlink)\&. Similarly, if
1470 "replace\-host"
1471 is used the file is copied, replacing any existing inode, including symlinks\&. Similarly, if
1472 "bind\-host"
1473 is used, the file is bind mounted from the host into the container\&.
1474 .sp
1475 If set to
1476 "copy\-static",
1477 "replace\-static"
1478 or
1479 "bind\-static"
1480 the static
1481 resolv\&.conf
1482 file supplied with
1483 \fBsystemd-resolved.service\fR(8)
1484 (specifically:
1485 /usr/lib/systemd/resolv\&.conf) is copied or bind mounted into the container\&.
1486 .sp
1487 If set to
1488 "copy\-uplink",
1489 "replace\-uplink"
1490 or
1491 "bind\-uplink"
1492 the uplink
1493 resolv\&.conf
1494 file managed by
1495 systemd\-resolved\&.service
1496 (specifically:
1497 /run/systemd/resolve/resolv\&.conf) is copied or bind mounted into the container\&.
1498 .sp
1499 If set to
1500 "copy\-stub",
1501 "replace\-stub"
1502 or
1503 "bind\-stub"
1504 the stub
1505 resolv\&.conf
1506 file managed by
1507 systemd\-resolved\&.service
1508 (specifically:
1509 /run/systemd/resolve/stub\-resolv\&.conf) is copied or bind mounted into the container\&.
1510 .sp
1511 If set to
1512 "delete"
1513 the
1514 /etc/resolv\&.conf
1515 file in the container is deleted if it exists\&.
1516 .sp
1517 Finally, if set to
1518 "auto"
1519 the file is left as it is if private networking is turned on (see
1520 \fB\-\-private\-network\fR)\&. Otherwise, if
1521 systemd\-resolved\&.service
1522 is running its stub
1523 resolv\&.conf
1524 file is used, and if not the host\*(Aqs
1525 /etc/resolv\&.conf
1526 file\&. In the latter cases the file is copied if the image is writable, and bind mounted otherwise\&.
1527 .sp
1528 It\*(Aqs recommended to use
1529 "copy\-\&..."
1530 or
1531 "replace\-\&..."
1532 if the container shall be able to make changes to the DNS configuration on its own, deviating from the host\*(Aqs settings\&. Otherwise,
1533 "bind"
1534 is preferable, as it means direct changes to
1535 /etc/resolv\&.conf
1536 in the container are not allowed, as it is a read\-only bind mount (but note that if the container has enough privileges, it might simply go ahead and unmount the bind mount anyway)\&. Note that both if the file is bind mounted and if it is copied no further propagation of configuration is generally done after the one\-time early initialization (this is because the file is usually updated through copying and renaming)\&. Defaults to
1537 "auto"\&.
1538 .sp
1539 Added in version 239\&.
1540 .RE
1541 .PP
1542 \fB\-\-timezone=\fR
1543 .RS 4
1544 Configures how
1545 /etc/localtime
1546 inside of the container (i\&.e\&. local timezone synchronization from host to container) shall be handled\&. Takes one of
1547 "off",
1548 "copy",
1549 "bind",
1550 "symlink",
1551 "delete"
1552 or
1553 "auto"\&. If set to
1554 "off"
1555 the
1556 /etc/localtime
1557 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&. If set to
1558 "copy"
1559 the
1560 /etc/localtime
1561 file of the host is copied into the container\&. Similarly, if
1562 "bind"
1563 is used, the file is bind mounted from the host into the container\&. If set to
1564 "symlink", a symlink is created pointing from
1565 /etc/localtime
1566 in the container to the timezone file in the container that matches the timezone setting on the host\&. If set to
1567 "delete", the file in the container is deleted, should it exist\&. If set to
1568 "auto"
1569 and the
1570 /etc/localtime
1571 file of the host is a symlink, then
1572 "symlink"
1573 mode is used, and
1574 "copy"
1575 otherwise, except if the image is read\-only in which case
1576 "bind"
1577 is used instead\&. Defaults to
1578 "auto"\&.
1579 .sp
1580 Added in version 239\&.
1581 .RE
1582 .PP
1583 \fB\-\-link\-journal=\fR
1584 .RS 4
1585 Control whether the container\*(Aqs journal shall be made visible to the host system\&. If enabled, allows viewing the container\*(Aqs journal files from the host (but not vice versa)\&. Takes one of
1586 "no",
1587 "host",
1588 "try\-host",
1589 "guest",
1590 "try\-guest",
1591 "auto"\&. If
1592 "no", the journal is not linked\&. If
1593 "host", the journal files are stored on the host file system (beneath
1594 /var/log/journal/\fImachine\-id\fR) and the subdirectory is bind\-mounted into the container at the same location\&. If
1595 "guest", the journal files are stored on the guest file system (beneath
1596 /var/log/journal/\fImachine\-id\fR) and the subdirectory is symlinked into the host at the same location\&.
1597 "try\-host"
1598 and
1599 "try\-guest"
1600 do the same but do not fail if the host does not have persistent journaling enabled, or if the container is in the
1601 \fB\-\-ephemeral\fR
1602 mode\&. If
1603 "auto"
1604 (the default), and the right subdirectory of
1605 /var/log/journal
1606 exists, it will be bind mounted into the container\&. If the subdirectory does not exist, no linking is performed\&. Effectively, booting a container once with
1607 "guest"
1608 or
1609 "host"
1610 will link the journal persistently if further on the default of
1611 "auto"
1612 is used\&.
1613 .sp
1614 Note that
1615 \fB\-\-link\-journal=try\-guest\fR
1616 is the default if the
1617 systemd\-nspawn@\&.service
1618 template unit file is used\&.
1619 .sp
1620 Added in version 187\&.
1621 .RE
1622 .PP
1623 \fB\-j\fR
1624 .RS 4
1625 Equivalent to
1626 \fB\-\-link\-journal=try\-guest\fR\&.
1627 .sp
1628 Added in version 187\&.
1629 .RE
1630 .SS "Mount Options"
1631 .PP
1632 \fB\-\-bind=\fR, \fB\-\-bind\-ro=\fR
1633 .RS 4
1634 Bind mount a file or directory from the host into the container\&. Takes one of: a path argument\ \&\(em in which case the specified path will be mounted from the host to the same path in the container, or a colon\-separated pair of paths\ \&\(em in which case the first specified path is the source in the host, and the second path is the destination in the container, or a colon\-separated triple of source path, destination path and mount options\&. The source path may optionally be prefixed with a
1635 "+"
1636 character\&. If so, the source path is taken relative to the image\*(Aqs root directory\&. This permits setting up bind mounts within the container image\&. The source path may be specified as empty string, in which case a temporary directory below the host\*(Aqs
1637 /var/tmp/
1638 directory is used\&. It is automatically removed when the container is shut down\&. If the source path is not absolute, it is resolved relative to the current working directory\&. The
1639 \fB\-\-bind\-ro=\fR
1640 option creates read\-only bind mounts\&. Backslash escapes are interpreted, so
1641 "\e:"
1642 may be used to embed colons in either path\&. This option may be specified multiple times for creating multiple independent bind mount points\&.
1643 .sp
1644 Mount options are comma\-separated\&.
1645 \fBrbind\fR
1646 and
1647 \fBnorbind\fR
1648 control whether to create a recursive or a regular bind mount\&. Defaults to
1649 \fBrbind\fR\&.
1650 \fBnoidmap\fR,
1651 \fBidmap\fR,
1652 \fBrootidmap\fR
1653 and
1654 \fBowneridmap\fR
1655 control ID mapping\&.
1656 .sp
1657 Using
1658 \fBidmap\fR,
1659 \fBrootidmap\fR
1660 or
1661 \fBowneridmap\fR
1662 requires support by the source filesystem for user/group ID mapped mounts\&. Defaults to
1663 \fBnoidmap\fR\&. With
1664 \fBx\fR
1665 being the container\*(Aqs UID range offset,
1666 \fBy\fR
1667 being the length of the container\*(Aqs UID range, and
1668 \fBp\fR
1669 being the owner UID of the bind mount source inode on the host:
1670 .sp
1671 .RS 4
1672 .ie n \{\
1673 \h'-04'\(bu\h'+03'\c
1674 .\}
1675 .el \{\
1676 .sp -1
1677 .IP \(bu 2.3
1678 .\}
1679 If
1680 \fBnoidmap\fR
1681 is used, any user
1682 \fBz\fR
1683 in the range
1684 \fB0 \&... y\fR
1685 seen from inside of the container is mapped to
1686 \fBx + z\fR
1687 in the
1688 \fBx \&... x + y\fR
1689 range on the host\&. Other host users are mapped to
1690 \fBnobody\fR
1691 inside the container\&.
1692 .RE
1693 .sp
1694 .RS 4
1695 .ie n \{\
1696 \h'-04'\(bu\h'+03'\c
1697 .\}
1698 .el \{\
1699 .sp -1
1700 .IP \(bu 2.3
1701 .\}
1702 If
1703 \fBidmap\fR
1704 is used, any user
1705 \fBz\fR
1706 in the UID range
1707 \fB0 \&... y\fR
1708 as seen from inside the container is mapped to the same
1709 \fBz\fR
1710 in the same
1711 \fB0 \&... y\fR
1712 range on the host\&. Other host users are mapped to
1713 \fBnobody\fR
1714 inside the container\&.
1715 .RE
1716 .sp
1717 .RS 4
1718 .ie n \{\
1719 \h'-04'\(bu\h'+03'\c
1720 .\}
1721 .el \{\
1722 .sp -1
1723 .IP \(bu 2.3
1724 .\}
1725 If
1726 \fBrootidmap\fR
1727 is used, the user
1728 \fB0\fR
1729 seen from inside of the container is mapped to
1730 \fBp\fR
1731 on the host\&. Other host users are mapped to
1732 \fBnobody\fR
1733 inside the container\&.
1734 .RE
1735 .sp
1736 .RS 4
1737 .ie n \{\
1738 \h'-04'\(bu\h'+03'\c
1739 .\}
1740 .el \{\
1741 .sp -1
1742 .IP \(bu 2.3
1743 .\}
1744 If
1745 \fBowneridmap\fR
1746 is used, the owner of the target directory inside of the container is mapped to
1747 \fBp\fR
1748 on the host\&. Other host users are mapped to
1749 \fBnobody\fR
1750 inside the container\&.
1751 .RE
1752 .sp
1753 Whichever ID mapping option is used, the same mapping will be used for users and groups IDs\&. If
1754 \fBrootidmap\fR
1755 or
1756 \fBowneridmap\fR
1757 are used, the group owning the bind mounted directory will have no effect\&.
1758 .sp
1759 Note that when this option is used in combination with
1760 \fB\-\-private\-users\fR, the resulting mount points will be owned by the
1761 \fBnobody\fR
1762 user\&. That\*(Aqs because the mount and its files and directories continue to be owned by the relevant host users and groups, which do not exist in the container, and thus show up under the wildcard UID 65534 (nobody)\&. If such bind mounts are created, it is recommended to make them read\-only, using
1763 \fB\-\-bind\-ro=\fR\&. Alternatively you can use the "idmap" mount option to map the filesystem IDs\&.
1764 .sp
1765 Added in version 198\&.
1766 .RE
1767 .PP
1768 \fB\-\-bind\-user=\fR
1769 .RS 4
1770 Binds the home directory of the specified user on the host into the container\&. Takes the name of an existing user on the host as argument\&. May be used multiple times to bind multiple users into the container\&. This does two things:
1771 .sp
1772 .RS 4
1773 .ie n \{\
1774 \h'-04' 1.\h'+01'\c
1775 .\}
1776 .el \{\
1777 .sp -1
1778 .IP " 1." 4.2
1779 .\}
1780 The user\*(Aqs home directory is bind mounted from the host into
1781 /run/host/home/, using an idmapped mount to map the host user\*(Aqs UID/GID to its assigned UID/GID in the container\&.
1782 .RE
1783 .sp
1784 .RS 4
1785 .ie n \{\
1786 \h'-04' 2.\h'+01'\c
1787 .\}
1788 .el \{\
1789 .sp -1
1790 .IP " 2." 4.2
1791 .\}
1792 A JSON user and group record is generated in
1793 /run/userdb/
1794 that describes the mapped user\&. It contains a minimized representation of the host\*(Aqs user record, adjusted to the UID/GID and home directory path assigned to the user in the container\&. The
1795 \fBnss-systemd\fR(8)
1796 glibc NSS module will pick up these records from there and make them available in the container\*(Aqs user/group databases\&.
1797 .RE
1798 .sp
1799 The combination of the two operations above ensures that it is possible to log into the container using the same account information as on the host\&. The user is only mapped transiently, while the container is running, and the mapping itself does not result in persistent changes to the container (except maybe for log messages generated at login time, and similar)\&. Note that in particular the UID/GID assignment in the container is not made persistently\&. If the user is mapped transiently, it is best to not allow the user to make persistent changes to the container\&. If the user leaves files or directories owned by the user, and those UIDs/GIDs are reused during later container invocations (possibly with a different
1800 \fB\-\-bind\-user=\fR
1801 mapping), those files and directories will be accessible to the "new" user\&.
1802 .sp
1803 The user/group record mapping only works if the container contains systemd 249 or newer, with
1804 \fBnss\-systemd\fR
1805 properly configured in
1806 nsswitch\&.conf\&. See
1807 \fBnss-systemd\fR(8)
1808 for details\&.
1809 .sp
1810 Note that the user record propagated from the host into the container will contain the UNIX password hash of the user, so that seamless logins in the container are possible\&. If the container is less trusted than the host it is hence important to use a strong UNIX password hash function (e\&.g\&. yescrypt or similar, with the
1811 "$y$"
1812 hash prefix)\&.
1813 .sp
1814 When binding a user from the host into the container checks are executed to ensure that the username is not yet known in the container\&. Moreover, it is checked that the UID/GID allocated for it is not currently defined in the user/group databases of the container\&. Both checks directly access the container\*(Aqs
1815 /etc/passwd
1816 and
1817 /etc/group, and thus might not detect existing accounts in other databases\&.
1818 .sp
1819 Added in version 249\&.
1820 .RE
1821 .PP
1822 \fB\-\-bind\-user\-shell=\fR
1823 .RS 4
1824 When used with
1825 \fB\-\-bind\-user=\fR, includes the specified shell in the user records of users bound into the container\&. Takes either a boolean or an absolute path\&.
1826 .sp
1827 .RS 4
1828 .ie n \{\
1829 \h'-04'\(bu\h'+03'\c
1830 .\}
1831 .el \{\
1832 .sp -1
1833 .IP \(bu 2.3
1834 .\}
1835 If false (the default), no shell is passed in the user records for users bound into the container\&. This causes bound users to the use the container\*(Aqs default shell\&.
1836 .RE
1837 .sp
1838 .RS 4
1839 .ie n \{\
1840 \h'-04'\(bu\h'+03'\c
1841 .\}
1842 .el \{\
1843 .sp -1
1844 .IP \(bu 2.3
1845 .\}
1846 If true, the shells specified by the host user records are included in the user records of all users bound into the container\&.
1847 .RE
1848 .sp
1849 .RS 4
1850 .ie n \{\
1851 \h'-04'\(bu\h'+03'\c
1852 .\}
1853 .el \{\
1854 .sp -1
1855 .IP \(bu 2.3
1856 .\}
1857 If passed an absolute path, sets that path as the shell for user records of all users bound into the container\&.
1858 .RE
1859 .sp
1860 Note: This will not check whether the specified shells exist in the container\&.
1861 .sp
1862 This operation is only supported in combination with
1863 \fB\-\-bind\-user=\fR\&.
1864 .sp
1865 Added in version 258\&.
1866 .RE
1867 .PP
1868 \fB\-\-bind\-user\-group=\fR\fB\fINAME\fR\fR
1869 .RS 4
1870 When used with
1871 \fB\-\-bind\-user=\fR, includes the specified group as an auxiliary group in the user records of users bound into the container\&. Takes a group name\&.
1872 .sp
1873 Note: This will not check whether the specified groups exist in the container\&.
1874 .sp
1875 This operation is only supported in combination with
1876 \fB\-\-bind\-user=\fR\&.
1877 .sp
1878 Added in version 259\&.
1879 .RE
1880 .PP
1881 \fB\-\-inaccessible=\fR
1882 .RS 4
1883 Make the specified path inaccessible in the container\&. This over\-mounts the specified path (which must exist in the container) with a file node of the same type that is empty and has the most restrictive access mode supported\&. This is an effective way to mask files, directories and other file system objects from the container payload\&. This option may be used more than once in case all specified paths are masked\&.
1884 .sp
1885 Added in version 242\&.
1886 .RE
1887 .PP
1888 \fB\-\-tmpfs=\fR
1889 .RS 4
1890 Mount a tmpfs file system into the container\&. Takes a single absolute path argument that specifies where to mount the tmpfs instance to (in which case the directory access mode will be chosen as 0755, owned by root/root), or optionally a colon\-separated pair of path and mount option string that is used for mounting (in which case the kernel default for access mode and owner will be chosen, unless otherwise specified)\&. Backslash escapes are interpreted in the path, so
1891 "\e:"
1892 may be used to embed colons in the path\&.
1893 .sp
1894 Note that this option cannot be used to replace the root file system of the container with a temporary file system\&. However, the
1895 \fB\-\-volatile=\fR
1896 option described below provides similar functionality, with a focus on implementing stateless operating system images\&.
1897 .sp
1898 Added in version 214\&.
1899 .RE
1900 .PP
1901 \fB\-\-overlay=\fR, \fB\-\-overlay\-ro=\fR
1902 .RS 4
1903 Combine multiple directory trees into one overlay file system and mount it into the container\&. Takes a list of colon\-separated paths to the directory trees to combine and the destination mount point\&.
1904 .sp
1905 Backslash escapes are interpreted in the paths, so
1906 "\e:"
1907 may be used to embed colons in the paths\&.
1908 .sp
1909 If three or more paths are specified, then the last specified path is the destination mount point in the container, all paths specified before refer to directory trees on the host and are combined in the specified order into one overlay file system\&. The left\-most path is hence the lowest directory tree, the second\-to\-last path the highest directory tree in the stacking order\&. If
1910 \fB\-\-overlay\-ro=\fR
1911 is used instead of
1912 \fB\-\-overlay=\fR, a read\-only overlay file system is created\&. If a writable overlay file system is created, all changes made to it are written to the highest directory tree in the stacking order, i\&.e\&. the second\-to\-last specified\&.
1913 .sp
1914 If only two paths are specified, then the second specified path is used both as the top\-level directory tree in the stacking order as seen from the host, as well as the mount point for the overlay file system in the container\&. At least two paths have to be specified\&.
1915 .sp
1916 The source paths may optionally be prefixed with
1917 "+"
1918 character\&. If so they are taken relative to the image\*(Aqs root directory\&. The uppermost source path may also be specified as an empty string, in which case a temporary directory below the host\*(Aqs
1919 /var/tmp/
1920 is used\&. The directory is removed automatically when the container is shut down\&. This behaviour is useful in order to make read\-only container directories writable while the container is running\&. For example, use
1921 "\-\-overlay=+/var::/var"
1922 in order to automatically overlay a writable temporary directory on a read\-only
1923 /var/
1924 directory\&. If a source path is not absolute, it is resolved relative to the current working directory\&.
1925 .sp
1926 For details about overlay file systems, see
1927 \m[blue]\fBOverlay Filesystem\fR\m[]\&\s-2\u[4]\d\s+2\&. Note that the semantics of overlay file systems are substantially different from normal file systems, in particular regarding reported device and inode information\&. Device and inode information may change for a file while it is being written to, and processes might see out\-of\-date versions of files at times\&. Note that this switch automatically derives the
1928 "workdir="
1929 mount option for the overlay file system from the top\-level directory tree, making it a sibling of it\&. It is hence essential that the top\-level directory tree is not a mount point itself (since the working directory must be on the same file system as the top\-most directory tree)\&. Also note that the
1930 "lowerdir="
1931 mount option receives the paths to stack in the opposite order of this switch\&.
1932 .sp
1933 Note that this option cannot be used to replace the root file system of the container with an overlay file system\&. However, the
1934 \fB\-\-volatile=\fR
1935 option described above provides similar functionality, with a focus on implementing stateless operating system images\&.
1936 .sp
1937 Added in version 220\&.
1938 .RE
1939 .SS "Input/Output Options"
1940 .PP
1941 \fB\-\-console=\fR\fB\fIMODE\fR\fR
1942 .RS 4
1943 Configures how to set up standard input, output and error output for the container payload, as well as the
1944 /dev/console
1945 device for the container\&. Takes one of
1946 \fBinteractive\fR,
1947 \fBread\-only\fR,
1948 \fBpassive\fR,
1949 \fBpipe\fR
1950 or
1951 \fBautopipe\fR\&. If
1952 \fBinteractive\fR, a pseudo\-TTY is allocated and made available as
1953 /dev/console
1954 in the container\&. It is then bi\-directionally connected to the standard input and output passed to
1955 \fBsystemd\-nspawn\fR\&.
1956 \fBread\-only\fR
1957 is similar but only the output of the container is propagated and no input from the caller is read\&. If
1958 \fBpassive\fR, a pseudo TTY is allocated, but it is not connected anywhere\&. In
1959 \fBpipe\fR
1960 mode no pseudo TTY is allocated, but the standard input, output and error output file descriptors passed to
1961 \fBsystemd\-nspawn\fR
1962 are passed on \(em as they are \(em to the container payload, see the following paragraph\&. Finally,
1963 \fBautopipe\fR
1964 mode operates like
1965 \fBinteractive\fR
1966 when
1967 \fBsystemd\-nspawn\fR
1968 is invoked on a terminal, and like
1969 \fBpipe\fR
1970 otherwise\&. Defaults to
1971 \fBinteractive\fR
1972 if
1973 \fBsystemd\-nspawn\fR
1974 is invoked from a terminal, and
1975 \fBread\-only\fR
1976 otherwise\&.
1977 .sp
1978 In
1979 \fBpipe\fR
1980 mode,
1981 /dev/console
1982 will not exist in the container\&. This means that the container payload generally cannot be a full init system as init systems tend to require
1983 /dev/console
1984 to be available\&. On the other hand, in this mode container invocations can be used within shell pipelines\&. This is because intermediary pseudo TTYs do not permit independent bidirectional propagation of the end\-of\-file (EOF) condition, which is necessary for shell pipelines to work correctly\&.
1985 \fINote that the \fR\fI\fBpipe\fR\fR\fI mode should be used carefully\fR, as passing arbitrary file descriptors to less trusted container payloads might open up unwanted interfaces for access by the container payload\&. For example, if a passed file descriptor refers to a TTY of some form, APIs such as
1986 \fBTIOCSTI\fR
1987 may be used to synthesize input that might be used for escaping the container\&. Hence
1988 \fBpipe\fR
1989 mode should only be used if the payload is sufficiently trusted or when the standard input/output/error output file descriptors are known safe, for example pipes\&.
1990 .sp
1991 Added in version 242\&.
1992 .RE
1993 .PP
1994 \fB\-\-pipe\fR, \fB\-P\fR
1995 .RS 4
1996 Equivalent to
1997 \fB\-\-console=pipe\fR\&.
1998 .sp
1999 Added in version 242\&.
2000 .RE
2001 .PP
2002 \fB\-\-background=\fR\fB\fICOLOR\fR\fR
2003 .RS 4
2004 Change the terminal background color to the specified ANSI color as long as the container runs\&. The color specified should be an ANSI X3\&.64 SGR background color, i\&.e\&. strings such as
2005 "40",
2006 "41", \&...,
2007 "47",
2008 "48;2;\&...",
2009 "48;5;\&..."\&. See
2010 \m[blue]\fBANSI Escape Code (Wikipedia)\fR\m[]\&\s-2\u[5]\d\s+2
2011 for details\&. Assign an empty string to disable any coloring\&.
2012 .sp
2013 Added in version 256\&.
2014 .RE
2015 .SS "Credentials"
2016 .PP
2017 \fB\-\-load\-credential=\fR\fB\fIID\fR\fR\fB:\fR\fB\fIPATH\fR\fR, \fB\-\-set\-credential=\fR\fB\fIID\fR\fR\fB:\fR\fB\fIVALUE\fR\fR
2018 .RS 4
2019 Pass a credential to the container\&. These two options correspond to the
2020 \fILoadCredential=\fR
2021 and
2022 \fISetCredential=\fR
2023 settings in unit files\&. See
2024 \fBsystemd.exec\fR(5)
2025 for details about these concepts, as well as the syntax of the option\*(Aqs arguments\&.
2026 .sp
2027 Note: when
2028 \fBsystemd\-nspawn\fR
2029 runs as systemd system service it can propagate the credentials it received via
2030 \fILoadCredential=\fR/\fISetCredential=\fR
2031 to the container payload\&. A systemd service manager running as PID 1 in the container can further propagate them to the services it itself starts\&. It is thus possible to easily propagate credentials from a parent service manager to a container manager service and from there into its payload\&. This can even be done recursively\&.
2032 .sp
2033 In order to embed binary data into the credential data for
2034 \fB\-\-set\-credential=\fR, use C\-style escaping (i\&.e\&.
2035 "\en"
2036 to embed a newline, or
2037 "\ex00"
2038 to embed a
2039 \fBNUL\fR
2040 byte)\&. Note that the invoking shell might already apply unescaping once, hence this might require double escaping!
2041 .sp
2042 The
2043 \fBsystemd-sysusers.service\fR(8)
2044 and
2045 \fBsystemd-firstboot\fR(1)
2046 services read credentials configured this way for the purpose of configuring the container\*(Aqs root user\*(Aqs password and shell, as well as system locale, keymap and timezone during the first boot process of the container\&. This is particularly useful in combination with
2047 \fB\-\-volatile=yes\fR
2048 where every single boot appears as first boot, since configuration applied to
2049 /etc/
2050 is lost on container reboot cycles\&. See the respective man pages for details\&. Example:
2051 .sp
2052 .if n \{\
2053 .RS 4
2054 .\}
2055 .nf
2056 # systemd\-nspawn \-i image\&.raw \e
2057 \-\-volatile=yes \e
2058 \-\-set\-credential=firstboot\&.locale:de_DE\&.UTF\-8 \e
2059 \-\-set\-credential=passwd\&.hashed\-password\&.root:\*(Aq$y$j9T$yAuRJu1o5HioZAGDYPU5d\&.$F64ni6J2y2nNQve90M/p0ZP0ECP/qqzipNyaY9fjGpC\*(Aq \e
2060 \-b
2061 .fi
2062 .if n \{\
2063 .RE
2064 .\}
2065 .sp
2066 The above command line will invoke the specified image file
2067 image\&.raw
2068 in volatile mode, i\&.e\&. with empty
2069 /etc/
2070 and
2071 /var/\&. The container payload will recognize this as a first boot, and will invoke
2072 systemd\-firstboot\&.service, which then reads the two passed credentials to configure the system\*(Aqs initial locale and root password\&.
2073 .sp
2074 Added in version 247\&.
2075 .RE
2076 .SS "Other"
2077 .PP
2078 \fB\-\-no\-pager\fR
2079 .RS 4
2080 Do not pipe output into a pager\&.
2081 .RE
2082 .PP
2083 \fB\-h\fR, \fB\-\-help\fR
2084 .RS 4
2085 Print a short help text and exit\&.
2086 .RE
2087 .PP
2088 \fB\-\-version\fR
2089 .RS 4
2090 Print a short version string and exit\&.
2091 .RE
2092 .PP
2093 \fB\-\-no\-ask\-password\fR
2094 .RS 4
2095 Do not query the user for authentication for privileged operations\&.
2096 .RE
2097 .SH "HOTKEYS"
2098 .PP
2099 When invoked in interactive mode (i\&.e\&. the default
2100 \fB\-\-console=interactive\fR), a few special keyboard shortcuts are understood that control the container runtime\&. These shortcuts need to be typed within 1s to have effect, otherwise they will be forwarded to the container as regular keypresses\&.
2101 .PP
2102 Ctrl\-] Ctrl\-] Ctrl\-]
2103 .RS 4
2104 Immediately terminate the container, killing all processes\&.
2105 .RE
2106 .PP
2107 Ctrl\-] Ctrl\-] r
2108 .RS 4
2109 Issue a reboot request to the container\&.
2110 .sp
2111 Added in version 258\&.
2112 .RE
2113 .PP
2114 Ctrl\-] Ctrl\-] p
2115 .RS 4
2116 Issue a shutdown request to the container\&.
2117 .sp
2118 Added in version 258\&.
2119 .RE
2120 .SH "ENVIRONMENT"
2121 .PP
2122 \fI$SYSTEMD_LOG_LEVEL\fR
2123 .RS 4
2124 The maximum log level of emitted messages (messages with a higher log level, i\&.e\&. less important ones, will be suppressed)\&. Takes a comma\-separated list of values\&. A value may be either one of (in order of decreasing importance)
2125 \fBemerg\fR,
2126 \fBalert\fR,
2127 \fBcrit\fR,
2128 \fBerr\fR,
2129 \fBwarning\fR,
2130 \fBnotice\fR,
2131 \fBinfo\fR,
2132 \fBdebug\fR, or an integer in the range 0\&...7\&. See
2133 \fBsyslog\fR(3)
2134 for more information\&. Each value may optionally be prefixed with one of
2135 \fBconsole\fR,
2136 \fBsyslog\fR,
2137 \fBkmsg\fR
2138 or
2139 \fBjournal\fR
2140 followed by a colon to set the maximum log level for that specific log target (e\&.g\&.
2141 \fBSYSTEMD_LOG_LEVEL=debug,console:info\fR
2142 specifies to log at debug level except when logging to the console which should be at info level)\&. Note that the global maximum log level takes priority over any per target maximum log levels\&.
2143 .RE
2144 .PP
2145 \fI$SYSTEMD_LOG_COLOR\fR
2146 .RS 4
2147 A boolean\&. If true, messages written to the tty will be colored according to priority\&.
2148 .sp
2149 This setting is only useful when messages are written directly to the terminal, because
2150 \fBjournalctl\fR(1)
2151 and other tools that display logs will color messages based on the log level on their own\&.
2152 .RE
2153 .PP
2154 \fI$SYSTEMD_LOG_TIME\fR
2155 .RS 4
2156 A boolean\&. If true, console log messages will be prefixed with a timestamp\&.
2157 .sp
2158 This setting is only useful when messages are written directly to the terminal or a file, because
2159 \fBjournalctl\fR(1)
2160 and other tools that display logs will attach timestamps based on the entry metadata on their own\&.
2161 .RE
2162 .PP
2163 \fI$SYSTEMD_LOG_LOCATION\fR
2164 .RS 4
2165 A boolean\&. If true, messages will be prefixed with a filename and line number in the source code where the message originates\&.
2166 .sp
2167 Note that the log location is often attached as metadata to journal entries anyway\&. Including it directly in the message text can nevertheless be convenient when debugging programs\&.
2168 .RE
2169 .PP
2170 \fI$SYSTEMD_LOG_TID\fR
2171 .RS 4
2172 A boolean\&. If true, messages will be prefixed with the current numerical thread ID (TID)\&.
2173 .sp
2174 Note that the this information is attached as metadata to journal entries anyway\&. Including it directly in the message text can nevertheless be convenient when debugging programs\&.
2175 .RE
2176 .PP
2177 \fI$SYSTEMD_LOG_TARGET\fR
2178 .RS 4
2179 The destination for log messages\&. One of
2180 \fBconsole\fR
2181 (log to the attached tty),
2182 \fBconsole\-prefixed\fR
2183 (log to the attached tty but with prefixes encoding the log level and "facility", see
2184 \fBsyslog\fR(3),
2185 \fBkmsg\fR
2186 (log to the kernel circular log buffer),
2187 \fBjournal\fR
2188 (log to the journal),
2189 \fBjournal\-or\-kmsg\fR
2190 (log to the journal if available, and to kmsg otherwise),
2191 \fBauto\fR
2192 (determine the appropriate log target automatically, the default),
2193 \fBnull\fR
2194 (disable log output)\&.
2195 .RE
2196 .PP
2197 \fI$SYSTEMD_LOG_RATELIMIT_KMSG\fR
2198 .RS 4
2199 Whether to ratelimit kmsg or not\&. Takes a boolean\&. Defaults to
2200 "true"\&. If disabled, systemd will not ratelimit messages written to kmsg\&.
2201 .RE
2202 .PP
2203 \fI$SYSTEMD_PAGER\fR, \fI$PAGER\fR
2204 .RS 4
2205 Pager to use when
2206 \fB\-\-no\-pager\fR
2207 is not given\&.
2208 \fI$SYSTEMD_PAGER\fR
2209 is used if set; otherwise
2210 \fI$PAGER\fR
2211 is used\&. If neither
2212 \fI$SYSTEMD_PAGER\fR
2213 nor
2214 \fI$PAGER\fR
2215 are set, a set of well\-known pager implementations is tried in turn, including
2216 \fBless\fR(1)
2217 and
2218 \fBmore\fR(1), until one is found\&. If no pager implementation is discovered, no pager is invoked\&. Setting those environment variables to an empty string or the value
2219 "cat"
2220 is equivalent to passing
2221 \fB\-\-no\-pager\fR\&.
2222 .sp
2223 Note: if
2224 \fI$SYSTEMD_PAGERSECURE\fR
2225 is not set,
2226 \fI$SYSTEMD_PAGER\fR
2227 and
2228 \fI$PAGER\fR
2229 can only be used to disable the pager (with
2230 "cat"
2231 or
2232 ""), and are otherwise ignored\&.
2233 .RE
2234 .PP
2235 \fI$SYSTEMD_LESS\fR
2236 .RS 4
2237 Override the options passed to
2238 \fBless\fR
2239 (by default
2240 "FRSXMK")\&.
2241 .sp
2242 Users might want to change two options in particular:
2243 .PP
2244 \fBK\fR
2245 .RS 4
2246 This option instructs the pager to exit immediately when
2247 Ctrl+C
2248 is pressed\&. To allow
2249 \fBless\fR
2250 to handle
2251 Ctrl+C
2252 itself to switch back to the pager command prompt, unset this option\&.
2253 .sp
2254 If the value of
2255 \fI$SYSTEMD_LESS\fR
2256 does not include
2257 "K", and the pager that is invoked is
2258 \fBless\fR,
2259 Ctrl+C
2260 will be ignored by the executable, and needs to be handled by the pager\&.
2261 .RE
2262 .PP
2263 \fBX\fR
2264 .RS 4
2265 This option instructs the pager to not send termcap initialization and deinitialization strings to the terminal\&. It is set by default to allow command output to remain visible in the terminal even after the pager exits\&. Nevertheless, this prevents some pager functionality from working, in particular paged output cannot be scrolled with the mouse\&.
2266 .RE
2267 .sp
2268 Note that setting the regular
2269 \fI$LESS\fR
2270 environment variable has no effect for
2271 \fBless\fR
2272 invocations by systemd tools\&.
2273 .sp
2274 See
2275 \fBless\fR(1)
2276 for more discussion\&.
2277 .RE
2278 .PP
2279 \fI$SYSTEMD_LESSCHARSET\fR
2280 .RS 4
2281 Override the charset passed to
2282 \fBless\fR
2283 (by default
2284 "utf\-8", if the invoking terminal is determined to be UTF\-8 compatible)\&.
2285 .sp
2286 Note that setting the regular
2287 \fI$LESSCHARSET\fR
2288 environment variable has no effect for
2289 \fBless\fR
2290 invocations by systemd tools\&.
2291 .RE
2292 .PP
2293 \fI$SYSTEMD_PAGERSECURE\fR
2294 .RS 4
2295 Common pager commands like
2296 \fBless\fR(1), in addition to "paging", i\&.e\&. scrolling through the output, support opening of or writing to other files and running arbitrary shell commands\&. When commands are invoked with elevated privileges, for example under
2297 \fBsudo\fR(8)
2298 or
2299 \fBpkexec\fR(1), the pager becomes a security boundary\&. Care must be taken that only programs with strictly limited functionality are used as pagers, and unintended interactive features like opening or creation of new files or starting of subprocesses are not allowed\&. "Secure mode" for the pager may be enabled as described below,
2300 \fIif the pager supports that\fR
2301 (most pagers are not written in a way that takes this into consideration)\&. It is recommended to either explicitly enable "secure mode" or to completely disable the pager using
2302 \fB\-\-no\-pager\fR
2303 or
2304 \fIPAGER=cat\fR
2305 when allowing untrusted users to execute commands with elevated privileges\&.
2306 .sp
2307 This option takes a boolean argument\&. When set to true, the "secure mode" of the pager is enabled\&. In "secure mode",
2308 \fBLESSSECURE=1\fR
2309 will be set when invoking the pager, which instructs the pager to disable commands that open or create new files or start new subprocesses\&. Currently only
2310 \fBless\fR(1)
2311 is known to understand this variable and implement "secure mode"\&.
2312 .sp
2313 When set to false, no limitation is placed on the pager\&. Setting
2314 \fISYSTEMD_PAGERSECURE=0\fR
2315 or not removing it from the inherited environment may allow the user to invoke arbitrary commands\&.
2316 .sp
2317 When
2318 \fI$SYSTEMD_PAGERSECURE\fR
2319 is not set, systemd tools attempt to automatically figure out if "secure mode" should be enabled and whether the pager supports it\&. "Secure mode" is enabled if the effective UID is not the same as the owner of the login session, see
2320 \fBgeteuid\fR(2)
2321 and
2322 \fBsd_pid_get_owner_uid\fR(3), or when running under
2323 \fBsudo\fR(8)
2324 or similar tools (\fI$SUDO_UID\fR
2325 is set
2326 \&\s-2\u[6]\d\s+2)\&. In those cases,
2327 \fISYSTEMD_PAGERSECURE=1\fR
2328 will be set and pagers which are not known to implement "secure mode" will not be used at all\&. Note that this autodetection only covers the most common mechanisms to elevate privileges and is intended as convenience\&. It is recommended to explicitly set
2329 \fI$SYSTEMD_PAGERSECURE\fR
2330 or disable the pager\&.
2331 .sp
2332 Note that if the
2333 \fI$SYSTEMD_PAGER\fR
2334 or
2335 \fI$PAGER\fR
2336 variables are to be honoured, other than to disable the pager,
2337 \fI$SYSTEMD_PAGERSECURE\fR
2338 must be set too\&.
2339 .RE
2340 .PP
2341 \fI$SYSTEMD_COLORS\fR
2342 .RS 4
2343 Takes a boolean argument, or a special value\&. By default (unset),
2344 \fBsystemd\fR
2345 and related utilities will use colors in their output if possible\&. If
2346 \fI$COLORTERM\fR
2347 is set to
2348 "truecolor"
2349 or
2350 "24bit", 24\-bit colors will be enabled, 256 colors otherwise, unless
2351 \fI$NO_COLOR\fR
2352 or
2353 \fI$TERM\fR
2354 indicates colors are disabled\&.
2355 .PP
2356 \fBtrue\fR
2357 .RS 4
2358 Same as unset, except that
2359 \fI$NO_COLOR\fR
2360 is ignored\&.
2361 .RE
2362 .PP
2363 \fBfalse\fR
2364 .RS 4
2365 The output will be monochrome\&.
2366 .RE
2367 .PP
2368 "16", "256", "24bit"
2369 .RS 4
2370 Always use the base 16 ANSI colors, 256 colors, or 24 bit color, respectively\&.
2371 .RE
2372 .PP
2373 "auto\-16", "auto\-256", "auto\-24bit"
2374 .RS 4
2375 Use the given quantity of colours, subject to
2376 \fI$TERM\fR, and what the console is connected to\&.
2377 .RE
2378 .RE
2379 .PP
2380 \fI$SYSTEMD_URLIFY\fR
2381 .RS 4
2382 The value must be a boolean\&. Controls whether clickable links should be generated in the output for terminal emulators supporting this\&. This can be specified to override the decision that
2383 \fBsystemd\fR
2384 makes based on
2385 \fI$TERM\fR
2386 and other conditions\&.
2387 .RE
2388 .SH "EXAMPLES"
2389 .PP
2390 \fBExample\ \&1.\ \&Download an Ubuntu TAR image and open a shell in it\fR
2391 .sp
2392 .if n \{\
2393 .RS 4
2394 .\}
2395 .nf
2396 # importctl pull\-tar \-mN https://cloud\-images\&.ubuntu\&.com/jammy/current/jammy\-server\-cloudimg\-amd64\-root\&.tar\&.xz
2397 # systemd\-nspawn \-M jammy\-server\-cloudimg\-amd64\-root
2398 .fi
2399 .if n \{\
2400 .RE
2401 .\}
2402 .PP
2403 This downloads and verifies the specified
2404 \&.tar
2405 image, and then uses
2406 \fBsystemd-nspawn\fR(1)
2407 to open a shell in it\&.
2408 .PP
2409 \fBExample\ \&2.\ \&Build and boot a minimal Fedora distribution in a container\fR
2410 .sp
2411 .if n \{\
2412 .RS 4
2413 .\}
2414 .nf
2415 # dnf \-y \-\-releasever=43 \-\-installroot=/var/lib/machines/f43 \e
2416 \-\-use\-host\-config \-\-setopt=install_weak_deps=0 \e
2417 \-\-repo=fedora \-\-repo=updates install \e
2418 passwd dnf fedora\-release nano util\-linux systemd systemd\-networkd
2419 # systemd\-nspawn \-bD /var/lib/machines/f43
2420 .fi
2421 .if n \{\
2422 .RE
2423 .\}
2424 .PP
2425 (Omit
2426 \fI\-\-use\-host\-config\fR
2427 when using
2428 \fBdnf\fR
2429 <= 4\&.) This installs a minimal Fedora distribution into the directory
2430 /var/lib/machines/f43
2431 and then boots that OS in a namespace container\&. Because the installation is located underneath the standard
2432 /var/lib/machines/
2433 directory, it is also possible to start the machine using
2434 \fBsystemd\-nspawn \-M f43\fR\&.
2435 .PP
2436 \fBExample\ \&3.\ \&Spawn a shell in a container of a minimal Debian unstable distribution\fR
2437 .sp
2438 .if n \{\
2439 .RS 4
2440 .\}
2441 .nf
2442 # debootstrap unstable ~/debian\-tree/
2443 # systemd\-nspawn \-D ~/debian\-tree/
2444 .fi
2445 .if n \{\
2446 .RE
2447 .\}
2448 .PP
2449 This installs a minimal Debian unstable distribution into the directory
2450 ~/debian\-tree/
2451 and then spawns a shell from this image in a namespace container\&.
2452 .PP
2453 \fBdebootstrap\fR
2454 supports
2455 \m[blue]\fBDebian\fR\m[]\&\s-2\u[7]\d\s+2, and
2456 \m[blue]\fBUbuntu\fR\m[]\&\s-2\u[8]\d\s+2
2457 out of the box, so the same command can be used to install any of those\&. For other distributions from the Debian family, a mirror has to be specified, see
2458 \fBdebootstrap\fR(8)\&.
2459 .PP
2460 \fBExample\ \&4.\ \&Boot a minimal Arch Linux distribution in a container\fR
2461 .sp
2462 .if n \{\
2463 .RS 4
2464 .\}
2465 .nf
2466 # pacstrap \-c ~/arch\-tree/ base
2467 # systemd\-nspawn \-bD ~/arch\-tree/
2468 .fi
2469 .if n \{\
2470 .RE
2471 .\}
2472 .PP
2473 This installs a minimal Arch Linux distribution into the directory
2474 ~/arch\-tree/
2475 and then boots an OS in a namespace container in it\&.
2476 .PP
2477 \fBExample\ \&5.\ \&Install the OpenSUSE Tumbleweed rolling distribution\fR
2478 .sp
2479 .if n \{\
2480 .RS 4
2481 .\}
2482 .nf
2483 # zypper \-\-root=/var/lib/machines/tumbleweed ar \-c \e
2484 https://download\&.opensuse\&.org/tumbleweed/repo/oss tumbleweed
2485 # zypper \-\-root=/var/lib/machines/tumbleweed refresh
2486 # zypper \-\-root=/var/lib/machines/tumbleweed install \-\-no\-recommends \e
2487 systemd shadow zypper openSUSE\-release vim
2488 # systemd\-nspawn \-M tumbleweed passwd root
2489 # systemd\-nspawn \-M tumbleweed \-b
2490 .fi
2491 .if n \{\
2492 .RE
2493 .\}
2494 .PP
2495 \fBExample\ \&6.\ \&Boot into an ephemeral snapshot of the host system\fR
2496 .sp
2497 .if n \{\
2498 .RS 4
2499 .\}
2500 .nf
2501 # systemd\-nspawn \-D / \-xb
2502 .fi
2503 .if n \{\
2504 .RE
2505 .\}
2506 .PP
2507 This runs a copy of the host system in a snapshot which is removed immediately when the container exits\&. All file system changes made during runtime will be lost on shutdown, hence\&.
2508 .PP
2509 \fBExample\ \&7.\ \&Run a container with SELinux sandbox security contexts\fR
2510 .sp
2511 .if n \{\
2512 .RS 4
2513 .\}
2514 .nf
2515 # chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \-R /srv/container
2516 # systemd\-nspawn \-L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \e
2517 \-Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 \-D /srv/container /bin/sh
2518 .fi
2519 .if n \{\
2520 .RE
2521 .\}
2522 .PP
2523 \fBExample\ \&8.\ \&Run a container with an OSTree deployment\fR
2524 .sp
2525 .if n \{\
2526 .RS 4
2527 .\}
2528 .nf
2529 # systemd\-nspawn \-b \-i ~/image\&.raw \e
2530 \-\-pivot\-root=/ostree/deploy/$OS/deploy/$CHECKSUM:/sysroot \e
2531 \-\-bind=+/sysroot/ostree/deploy/$OS/var:/var
2532 .fi
2533 .if n \{\
2534 .RE
2535 .\}
2536 .SH "EXIT STATUS"
2537 .PP
2538 The exit code of the program executed in the container is returned\&.
2539 .SH "SEE ALSO"
2540 .PP
2541 \fBsystemd\fR(1), \fBsystemd.nspawn\fR(5), \fBchroot\fR(1), \fBdnf\fR(8), \fBdebootstrap\fR(8), \fBpacman\fR(8), \fBzypper\fR(8), \fBsystemd.slice\fR(5), \fBmachinectl\fR(1), \fBimportctl\fR(1), \fBsystemd-mountfsd.service\fR(8), \fBsystemd-nsresourced.service\fR(8), \fBsystemd.mstack\fR(7), \fBbtrfs\fR(8)
2542 .SH "NOTES"
2543 .IP " 1." 4
2544 Container Interface
2545 .RS 4
2546 \%https://systemd.io/CONTAINER_INTERFACE
2547 .RE
2548 .IP " 2." 4
2549 UAPI.2 Discoverable Partitions Specification
2550 .RS 4
2551 \%https://uapi-group.org/specifications/specs/discoverable_partitions_specification
2552 .RE
2553 .IP " 3." 4
2554 OCI Runtime Specification
2555 .RS 4
2556 \%https://github.com/opencontainers/runtime-spec/blob/master/spec.md
2557 .RE
2558 .IP " 4." 4
2559 Overlay Filesystem
2560 .RS 4
2561 \%https://docs.kernel.org/filesystems/overlayfs.html
2562 .RE
2563 .IP " 5." 4
2564 ANSI Escape Code (Wikipedia)
2565 .RS 4
2566 \%https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
2567 .RE
2568 .IP " 6." 4
2569 It is recommended for other tools to set and check
2570 \fI$SUDO_UID\fR
2571 as appropriate, treating it is a common interface.
2572 .IP " 7." 4
2573 Debian
2574 .RS 4
2575 \%https://www.debian.org
2576 .RE
2577 .IP " 8." 4
2578 Ubuntu
2579 .RS 4
2580 \%https://www.ubuntu.com
2581 .RE
2582 .IP " 9." 4
2583 Arch Linux
2584 .RS 4
2585 \%https://www.archlinux.org
2586 .RE
2587 .IP "10." 4
2588 OpenSUSE Tumbleweed
2589 .RS 4
2590 \%https://software.opensuse.org/distributions/tumbleweed
2591 .RE