Debian Codegraph @

upstream/mageia-cauldron/man1/systemd-nspawn.1

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