Debian Codegraph @

upstream/fedora-44/man1/systemd-nspawn.1

raw
1 '\" t
2 .TH "SYSTEMD\-NSPAWN" "1" "" "systemd 259.5" "systemd-nspawn"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd-nspawn \- Spawn a command or OS in a lightweight container
24 .SH "SYNOPSIS"
25 .HP \w'\fBsystemd\-nspawn\fR\ 'u
26 \fBsystemd\-nspawn\fR [OPTIONS...] [\fICOMMAND\fR\ [ARGS...]]
27 .HP \w'\fBsystemd\-nspawn\fR\ 'u
28 \fBsystemd\-nspawn\fR \-\-boot [OPTIONS...] [ARGS...]
29 .SH "DESCRIPTION"
30 .PP
31 \fBsystemd\-nspawn\fR
32 may be used to run a command or OS in a lightweight namespace container\&. In many ways it is similar to
33 \fBchroot\fR(1), but more powerful since it virtualizes the file system hierarchy, as well as the process tree, the various IPC subsystems, and the host and domain names\&.
34 .PP
35 \fBsystemd\-nspawn\fR
36 may be invoked on any directory tree containing an operating system tree, using the
37 \fB\-\-directory=\fR
38 command line option\&. By using the
39 \fB\-\-machine=\fR
40 option an OS tree is automatically searched for in a couple of locations, most importantly in
41 /var/lib/machines/, the suggested directory to place OS container images installed on the system\&.
42 .PP
43 In contrast to
44 \fBchroot\fR(1)\ \&\fBsystemd\-nspawn\fR
45 may be used to boot full Linux\-based operating systems in a container\&.
46 .PP
47 \fBsystemd\-nspawn\fR
48 limits access to various kernel interfaces in the container to read\-only, such as
49 /sys/,
50 /proc/sys/, or
51 /sys/fs/selinux/\&. The host\*(Aqs network interfaces and the system clock may not be changed from within the container\&. Device nodes may not be created\&. The host system cannot be rebooted and kernel modules may not be loaded from within the container\&.
52 \fIThis sandbox can easily be circumvented from within the container if user namespaces are not used\fR\&. This means that untrusted code must always be run in a user namespace, see the discussion of the
53 \fB\-\-private\-users=\fR
54 option below\&.
55 .PP
56 Use a tool like
57 \fBdnf\fR(8),
58 \fBdebootstrap\fR(8), or
59 \fBpacman\fR(8)
60 to set up an OS directory tree suitable as file system hierarchy for
61 \fBsystemd\-nspawn\fR
62 containers\&. See the Examples section below for details on suitable invocation of these commands\&.
63 .PP
64 As a safety check
65 \fBsystemd\-nspawn\fR
66 will verify the existence of
67 /usr/lib/os\-release
68 or
69 /etc/os\-release
70 in the container tree before booting a container (see
71 \fBos-release\fR(5))\&. It might be necessary to add this file to the container tree manually if the OS of the container is too old to contain this file out\-of\-the\-box\&.
72 .PP
73 \fBsystemd\-nspawn\fR
74 may be invoked directly from the interactive command line or run as system service in the background\&. In this mode each container instance runs as its own service instance; a default template unit file
75 systemd\-nspawn@\&.service
76 is provided to make this easy, taking the container name as instance identifier\&. Note that different default options apply when
77 \fBsystemd\-nspawn\fR
78 is invoked by the template unit file than interactively on the command line\&. Most importantly the template unit file makes use of the
79 \fB\-\-boot\fR
80 option which is not the default in case
81 \fBsystemd\-nspawn\fR
82 is invoked from the interactive command line\&. Further differences with the defaults are documented along with the various supported options below\&.
83 .PP
84 The
85 \fBmachinectl\fR(1)
86 tool may be used to execute a number of operations on containers\&. In particular it provides easy\-to\-use commands to run containers as system services using the
87 systemd\-nspawn@\&.service
88 template unit file\&.
89 .PP
90 Along with each container a settings file with the
91 \&.nspawn
92 suffix may exist, containing additional settings to apply when running the container\&. See
93 \fBsystemd.nspawn\fR(5)
94 for details\&. Settings files override the default options used by the
95 systemd\-nspawn@\&.service
96 template unit file, making it usually unnecessary to alter this template file directly\&.
97 .PP
98 Note that
99 \fBsystemd\-nspawn\fR
100 will mount file systems private to the container to
101 /dev/,
102 /run/, and similar\&. These will not be visible outside of the container, and their contents will be lost when the container exits\&.
103 .PP
104 Note that running two
105 \fBsystemd\-nspawn\fR
106 containers from the same directory tree will not make processes in them see each other\&. The PID namespace separation of the two containers is complete and the containers will share very few runtime objects except for the underlying file system\&. Rather use
107 \fBmachinectl\fR(1)\*(Aqs
108 \fBlogin\fR
109 or
110 \fBshell\fR
111 commands to request an additional login session in a running container\&.
112 .PP
113 \fBsystemd\-nspawn\fR
114 implements the
115 \m[blue]\fBContainer Interface\fR\m[]\&\s-2\u[1]\d\s+2
116 specification\&.
117 .PP
118 While running, containers invoked with
119 \fBsystemd\-nspawn\fR
120 are registered with the
121 \fBsystemd-machined\fR(8)
122 service that keeps track of running containers, and provides programming interfaces to interact with them\&.
123 .SH "UNPRIVILEGED OPERATION"
124 .PP
125 \fBsystemd\-nspawn\fR
126 may be invoked with or without privileges\&. The full functionality is currently only available when invoked with privileges\&. When invoked without privileges, various limitations apply, including, but not limited to:
127 .sp
128 .RS 4
129 .ie n \{\
130 \h'-04'\(bu\h'+03'\c
131 .\}
132 .el \{\
133 .sp -1
134 .IP \(bu 2.3
135 .\}
136 Only disk image based containers are supported (i\&.e\&.
137 \fB\-\-image=\fR)\&. Directory based ones (i\&.e\&.
138 \fB\-\-directory=\fR) are only supported if owned by the "foreign" UID range\&.
139 .RE
140 .sp
141 .RS 4
142 .ie n \{\
143 \h'-04'\(bu\h'+03'\c
144 .\}
145 .el \{\
146 .sp -1
147 .IP \(bu 2.3
148 .\}
149 Only
150 \fB\-\-private\-network\fR
151 and
152 \fB\-\-network\-veth\fR
153 networking modes are supported\&.
154 .RE
155 .PP
156 When running in unprivileged mode, some needed functionality is provided via
157 \fBsystemd-mountfsd.service\fR(8)
158 and
159 \fBsystemd-nsresourced.service\fR(8)\&.
160 .SH "OPTIONS"
161 .PP
162 If option
163 \fB\-\-boot\fR
164 is specified, the arguments are used as arguments for the init program\&. Otherwise,
165 \fICOMMAND\fR
166 specifies the program to launch in the container, and the remaining arguments are used as arguments for this program\&. If
167 \fB\-\-boot\fR
168 is not used and no arguments are specified, a shell is launched in the container\&.
169 .PP
170 The following options are understood:
171 .PP
172 \fB\-q\fR, \fB\-\-quiet\fR
173 .RS 4
174 Turns off any status output by the tool itself\&. When this switch is used, the only output from nspawn will be the console output of the container OS itself\&.
175 .sp
176 Added in version 209\&.
177 .RE
178 .PP
179 \fB\-\-settings=\fR\fB\fIMODE\fR\fR
180 .RS 4
181 Controls whether
182 \fBsystemd\-nspawn\fR
183 shall search for and use additional per\-container settings from
184 \&.nspawn
185 files\&. Takes a boolean or the special values
186 \fBoverride\fR
187 or
188 \fBtrusted\fR\&.
189 .sp
190 If enabled (the default), a settings file named after the machine (as specified with the
191 \fB\-\-machine=\fR
192 setting, or derived from the directory or image file name) with the suffix
193 \&.nspawn
194 is searched in
195 /etc/systemd/nspawn/
196 and
197 /run/systemd/nspawn/\&. If it is found there, its settings are read and used\&. If it is not found there, it is subsequently searched in the same directory as the image file or in the immediate parent of the root directory of the container\&. In this case, if the file is found, its settings will be also read and used, but potentially unsafe settings are ignored\&. Note that in both these cases, settings on the command line take precedence over the corresponding settings from loaded
198 \&.nspawn
199 files, if both are specified\&. Unsafe settings are considered all settings that elevate the container\*(Aqs privileges or grant access to additional resources such as files or directories of the host\&. For details about the format and contents of
200 \&.nspawn
201 files, consult
202 \fBsystemd.nspawn\fR(5)\&.
203 .sp
204 If this option is set to
205 \fBoverride\fR, the file is searched, read and used the same way, however, the order of precedence is reversed: settings read from the
206 \&.nspawn
207 file will take precedence over the corresponding command line options, if both are specified\&.
208 .sp
209 If this option is set to
210 \fBtrusted\fR, the file is searched, read and used the same way, but regardless of being found in
211 /etc/systemd/nspawn/,
212 /run/systemd/nspawn/
213 or next to the image file or container root directory, all settings will take effect, however, command line arguments still take precedence over corresponding settings\&.
214 .sp
215 If disabled, no
216 \&.nspawn
217 file is read and no settings except the ones on the command line are in effect\&.
218 .sp
219 Added in version 226\&.
220 .RE
221 .PP
222 \fB\-\-cleanup\fR
223 .RS 4
224 Clean up left\-over mounts and underlying mount points used by the container, and exit without invoking any containers\&. This may be useful when the previous invocation of
225 \fBsystemd\-nspawn\fR
226 was unexpectedly terminated\&. This requires at least one of
227 \fB\-M/\-\-machine=\fR,
228 \fB\-D/\-\-directory=\fR, or
229 \fB\-i/\-\-image=\fR
230 to determine the mounts to be cleaned up\&.
231 .sp
232 Added in version 257\&.
233 .RE
234 .SS "Image Options"
235 .PP
236 \fB\-D\fR, \fB\-\-directory=\fR
237 .RS 4
238 Directory to use as file system root for the container\&.
239 .sp
240 If neither
241 \fB\-\-directory=\fR, nor
242 \fB\-\-image=\fR
243 is specified the directory is determined by searching for a directory named the same as the machine name specified with
244 \fB\-\-machine=\fR\&. See
245 \fBmachinectl\fR(1)
246 section "Files and Directories" for the precise search path\&.
247 .sp
248 In place of the directory path a
249 "\&.v/"
250 versioned directory may be specified, see
251 \fBsystemd.v\fR(7)
252 for details\&.
253 .sp
254 If neither
255 \fB\-\-directory=\fR,
256 \fB\-\-image=\fR, nor
257 \fB\-\-machine=\fR
258 are specified, the current directory will be used\&. May not be specified together with
259 \fB\-\-image=\fR\&.
260 .RE
261 .PP
262 \fB\-\-template=\fR
263 .RS 4
264 Directory or
265 "btrfs"
266 subvolume to use as template for the container\*(Aqs root directory\&. If this is specified and the container\*(Aqs root directory (as configured by
267 \fB\-\-directory=\fR) does not yet exist it is created as
268 "btrfs"
269 snapshot (if supported) or plain directory (otherwise) and populated from this template tree\&. Ideally, the specified template path refers to the root of a
270 "btrfs"
271 subvolume, in which case a simple copy\-on\-write snapshot is taken, and populating the root directory is instant\&. If the specified template path does not refer to the root of a
272 "btrfs"
273 subvolume (or not even to a
274 "btrfs"
275 file system at all), the tree is copied (though possibly in a \*(Aqreflink\*(Aq copy\-on\-write scheme \(em if the file system supports that), which can be substantially more time\-consuming\&. Note that the snapshot taken is of the specified directory or subvolume, including all subdirectories and subvolumes below it, but excluding any sub\-mounts\&. May not be specified together with
276 \fB\-\-image=\fR
277 or
278 \fB\-\-ephemeral\fR\&.
279 .sp
280 Note that this switch leaves hostname, machine ID and all other settings that could identify the instance unmodified\&.
281 .sp
282 Added in version 219\&.
283 .RE
284 .PP
285 \fB\-x\fR, \fB\-\-ephemeral\fR
286 .RS 4
287 If specified, the container is run with a temporary snapshot of its file system that is removed immediately when the container terminates\&. May not be specified together with
288 \fB\-\-template=\fR\&.
289 .sp
290 Note that this switch leaves hostname, machine ID and all other settings that could identify the instance unmodified\&. Please note that \(em as with
291 \fB\-\-template=\fR
292 \(em taking the temporary snapshot is more efficient on file systems that support subvolume snapshots or \*(Aqreflinks\*(Aq natively ("btrfs"
293 or new
294 "xfs") than on more traditional file systems that do not ("ext4")\&. Note that the snapshot taken is of the specified directory or subvolume, including all subdirectories and subvolumes below it, but excluding any sub\-mounts\&.
295 .sp
296 With this option no modifications of the container image are retained\&. Use
297 \fB\-\-volatile=\fR
298 (described below) for other mechanisms to restrict persistency of container images during runtime\&.
299 .sp
300 Added in version 219\&.
301 .RE
302 .PP
303 \fB\-i\fR, \fB\-\-image=\fR
304 .RS 4
305 Disk image to mount the root directory for the container from\&. Takes a path to a regular file or to a block device node\&. The file or block device must contain either:
306 .sp
307 .RS 4
308 .ie n \{\
309 \h'-04'\(bu\h'+03'\c
310 .\}
311 .el \{\
312 .sp -1
313 .IP \(bu 2.3
314 .\}
315 An MBR partition table with a single partition of type 0x83 that is marked bootable\&.
316 .RE
317 .sp
318 .RS 4
319 .ie n \{\
320 \h'-04'\(bu\h'+03'\c
321 .\}
322 .el \{\
323 .sp -1
324 .IP \(bu 2.3
325 .\}
326 A GUID partition table (GPT) with a single partition of type 0fc63daf\-8483\-4772\-8e79\-3d69d8477de4\&.
327 .RE
328 .sp
329 .RS 4
330 .ie n \{\
331 \h'-04'\(bu\h'+03'\c
332 .\}
333 .el \{\
334 .sp -1
335 .IP \(bu 2.3
336 .\}
337 A GUID partition table (GPT) with a marked root partition which is mounted as the root directory of the container\&. Optionally, GPT images may contain a home and/or a server data partition which are mounted to the appropriate places in the container\&. All these partitions must be identified by the partition types defined by the
338 \m[blue]\fBUAPI\&.2 Discoverable Partitions Specification\fR\m[]\&\s-2\u[2]\d\s+2\&.
339 .RE
340 .sp
341 .RS 4
342 .ie n \{\
343 \h'-04'\(bu\h'+03'\c
344 .\}
345 .el \{\
346 .sp -1
347 .IP \(bu 2.3
348 .\}
349 No partition table, and a single file system spanning the whole image\&.
350 .RE
351 .sp
352 On GPT images, if an EFI System Partition (ESP) is discovered, it is automatically mounted to
353 /efi
354 (or
355 /boot
356 as fallback) in case a directory by this name exists and is empty\&.
357 .sp
358 Partitions encrypted with LUKS are automatically decrypted\&. Also, on GPT images dm\-verity data integrity hash partitions are set up if the root hash for them is specified using the
359 \fB\-\-root\-hash=\fR
360 option\&.
361 .sp
362 Single file system images (i\&.e\&. file systems without a surrounding partition table) can be opened using dm\-verity if the integrity data is passed using the
363 \fB\-\-root\-hash=\fR
364 and
365 \fB\-\-verity\-data=\fR
366 (and optionally
367 \fB\-\-root\-hash\-sig=\fR) options\&.
368 .sp
369 Any other partitions, such as foreign partitions or swap partitions are not mounted\&. May not be specified together with
370 \fB\-\-directory=\fR,
371 \fB\-\-template=\fR\&.
372 .sp
373 In place of the image path a
374 "\&.v/"
375 versioned directory may be specified, see
376 \fBsystemd.v\fR(7)
377 for details\&.
378 .sp
379 Added in version 211\&.
380 .RE
381 .PP
382 \fB\-\-image\-policy=\fR\fB\fIpolicy\fR\fR
383 .RS 4
384 Takes an image policy string as argument, as per
385 \fBsystemd.image-policy\fR(7)\&. The policy is enforced when operating on the disk image specified via
386 \fB\-\-image=\fR, see above\&. If not specified, defaults to
387 "root=verity+signed+encrypted+unprotected+absent:usr=verity+signed+encrypted+unprotected+absent:home=encrypted+unprotected+absent:srv=encrypted+unprotected+absent:esp=unprotected+absent:xbootldr=unprotected+absent:tmp=encrypted+unprotected+absent:var=encrypted+unprotected+absent", i\&.e\&. all recognized file systems in the image are used, but not the swap partition\&.
388 .sp
389 Added in version 254\&.
390 .RE
391 .PP
392 \fB\-\-oci\-bundle=\fR
393 .RS 4
394 Takes the path to an OCI runtime bundle to invoke, as specified in the
395 \m[blue]\fBOCI Runtime Specification\fR\m[]\&\s-2\u[3]\d\s+2\&. In this case, no
396 \&.nspawn
397 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)\&.
398 .sp
399 Added in version 242\&.
400 .RE
401 .PP
402 \fB\-\-read\-only\fR
403 .RS 4
404 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
405 \fB\-\-bind=\fR,
406 \fB\-\-tmpfs=\fR
407 and similar options\&. This mode is implied if the container image file or directory is marked read\-only itself\&. It is also implied if
408 \fB\-\-volatile=\fR
409 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\&.
410 .RE
411 .PP
412 \fB\-\-volatile\fR, \fB\-\-volatile=\fR\fB\fIMODE\fR\fR
413 .RS 4
414 Boots the container in volatile mode\&. When no mode parameter is passed or when mode is specified as
415 \fByes\fR, full volatile mode is enabled\&. This means the root directory is mounted as a mostly unpopulated
416 "tmpfs"
417 instance, and
418 /usr/
419 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
420 \fBstate\fR, the OS tree is mounted read\-only, but
421 /var/
422 is mounted as a writable
423 "tmpfs"
424 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
425 \fBoverlay\fR
426 the read\-only root file system is combined with a writable
427 tmpfs
428 instance through
429 "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
430 \fBno\fR
431 (the default), the whole OS tree is made available writable (unless
432 \fB\-\-read\-only\fR
433 is specified, see above)\&.
434 .sp
435 Note that if one of the volatile modes is chosen, its effect is limited to the root file system (or
436 /var/
437 in case of
438 \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
439 /efi/
440 or
441 /boot/) or explicitly (e\&.g\&. through an additional command line option such as
442 \fB\-\-bind=\fR, see below)\&. This means, even if
443 \fB\-\-volatile=overlay\fR
444 is used changes to
445 /efi/
446 or
447 /boot/
448 are prohibited in case such a partition exists in the container image operated on, and even if
449 \fB\-\-volatile=state\fR
450 is used the hypothetical file
451 /etc/foobar
452 is potentially writable if
453 \fB\-\-bind=/etc/foobar\fR
454 is used to mount it from outside the read\-only container
455 /etc/
456 directory\&.
457 .sp
458 The
459 \fB\-\-ephemeral\fR
460 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\&.
461 .sp
462 The
463 \fB\-\-tmpfs=\fR
464 and
465 \fB\-\-overlay=\fR
466 options provide similar functionality, but for specific sub\-directories of the OS image only\&. For details, see below\&.
467 .sp
468 This option provides similar functionality for containers as the
469 "systemd\&.volatile="
470 kernel command line switch provides for host systems\&. See
471 \fBkernel-command-line\fR(7)
472 for details\&.
473 .sp
474 Note that setting this option to
475 \fByes\fR
476 or
477 \fBstate\fR
478 will only work correctly with operating systems in the container that can boot up with only
479 /usr/
480 mounted, and are able to automatically populate
481 /var/
482 (and
483 /etc/
484 in case of
485 "\-\-volatile=yes")\&. Specifically, this means that operating systems that follow the historic split of
486 /bin/
487 and
488 /lib/
489 (and related directories) from
490 /usr/
491 (i\&.e\&. where the former are not symlinks into the latter) are not supported by
492 "\-\-volatile=yes"
493 as container payload\&. The
494 \fBoverlay\fR
495 option does not require any particular preparations in the OS, but do note that
496 "overlayfs"
497 behaviour differs from regular file systems in a number of ways, and hence compatibility is limited\&.
498 .sp
499 Added in version 216\&.
500 .RE
501 .PP
502 \fB\-\-root\-hash=\fR
503 .RS 4
504 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
505 "user\&.verity\&.roothash"
506 extended file attribute (see
507 \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
508 \&.roothash
509 suffix is found next to the image file, bearing otherwise the same name (except if the image has the
510 \&.raw
511 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\&.
512 .sp
513 Note that this configures the root hash for the root file system\&. Disk images may also contain separate file systems for the
514 /usr/
515 hierarchy, which may be Verity protected as well\&. The root hash for this protection may be configured via the
516 "user\&.verity\&.usrhash"
517 extended file attribute or via a
518 \&.usrhash
519 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
520 /usr/
521 from the command line\&.
522 .sp
523 Also see the
524 \fIRootHash=\fR
525 option in
526 \fBsystemd.exec\fR(5)\&.
527 .sp
528 Added in version 233\&.
529 .RE
530 .PP
531 \fB\-\-root\-hash\-sig=\fR
532 .RS 4
533 Takes a PKCS7 signature of the
534 \fB\-\-root\-hash=\fR
535 option\&. The semantics are the same as for the
536 \fIRootHashSignature=\fR
537 option, see
538 \fBsystemd.exec\fR(5)\&.
539 .sp
540 Added in version 246\&.
541 .RE
542 .PP
543 \fB\-\-verity\-data=\fR
544 .RS 4
545 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
546 \&.verity
547 suffix is found next to the image file, bearing otherwise the same name (except if the image has the
548 \&.raw
549 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\&.
550 .sp
551 Added in version 246\&.
552 .RE
553 .PP
554 \fB\-\-pivot\-root=\fR
555 .RS 4
556 Pivot the specified directory to
557 /
558 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
559 /
560 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
561 /, and the old
562 /
563 will be pivoted to the other directory\&. Both paths must be absolute, and are resolved in the container\*(Aqs file system namespace\&.
564 .sp
565 This is for containers which have several bootable directories in them; for example, several
566 \m[blue]\fBOSTree\fR\m[]\&\s-2\u[4]\d\s+2
567 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\&.
568 .sp
569 Added in version 233\&.
570 .RE
571 .SS "Execution Options"
572 .PP
573 \fB\-a\fR, \fB\-\-as\-pid2\fR
574 .RS 4
575 Invoke the shell or specified program as process ID (PID) 2 instead of PID 1 (init)\&. By default, if neither this option nor
576 \fB\-\-boot\fR
577 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
578 \fBsysvinit\fR
579 compatible signal handling (specifically: it needs to reboot on SIGINT, reexecute on SIGTERM, reload configuration on SIGHUP, and so on)\&. With
580 \fB\-\-as\-pid2\fR
581 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
582 \fB\-\-boot\fR\&.
583 .sp
584 Added in version 229\&.
585 .RE
586 .PP
587 \fB\-b\fR, \fB\-\-boot\fR
588 .RS 4
589 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
590 \fB\-\-as\-pid2\fR\&.
591 .sp
592 The following table explains the different modes of invocation and relationship to
593 \fB\-\-as\-pid2\fR
594 (see above):
595 .sp
596 .it 1 an-trap
597 .nr an-no-space-flag 1
598 .nr an-break-flag 1
599 .br
600 .B Table\ \&1.\ \&Invocation Mode
601 .TS
602 allbox tab(:);
603 lB lB.
604 T{
605 Switch
606 T}:T{
607 Explanation
608 T}
609 .T&
610 l l
611 l l
612 l l.
613 T{
614 Neither \fB\-\-as\-pid2\fR nor \fB\-\-boot\fR specified
615 T}:T{
616 The passed parameters are interpreted as the command line, which is executed as PID 1 in the container\&.
617 T}
618 T{
619 \fB\-\-as\-pid2\fR specified
620 T}:T{
621 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\&.
622 T}
623 T{
624 \fB\-\-boot\fR specified
625 T}:T{
626 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\&.
627 T}
628 .TE
629 .sp 1
630 Note that
631 \fB\-\-boot\fR
632 is the default mode of operation if the
633 systemd\-nspawn@\&.service
634 template unit file is used\&.
635 .RE
636 .PP
637 \fB\-\-chdir=\fR
638 .RS 4
639 Change to the specified working directory before invoking the process in the container\&. Expects an absolute path in the container\*(Aqs file system namespace\&.
640 .sp
641 Added in version 229\&.
642 .RE
643 .PP
644 \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
645 .RS 4
646 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
647 "="
648 and
649 \fIVALUE\fR
650 are omitted, the value of the variable with the same name in the program environment will be used\&.
651 .sp
652 Added in version 209\&.
653 .RE
654 .PP
655 \fB\-u\fR, \fB\-\-user=\fR
656 .RS 4
657 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\&.
658 .sp
659 Note that if credentials are used in combination with a non\-root
660 \fB\-\-user=\fR
661 (e\&.g\&.:
662 \fB\-\-set\-credential=\fR
663 or
664 \fB\-\-load\-credential=\fR), then
665 \fB\-\-no\-new\-privileges=yes\fR
666 must be used, and
667 \fB\-\-boot\fR
668 or
669 \fB\-\-as\-pid2\fR
670 must not be used, as the credentials would otherwise be unreadable by the container due to missing privileges after switching to the specified user\&.
671 .RE
672 .PP
673 \fB\-\-kill\-signal=\fR
674 .RS 4
675 Specify the process signal to send to the container\*(Aqs PID 1 when nspawn itself receives
676 \fBSIGTERM\fR, in order to trigger an orderly shutdown of the container\&. Defaults to
677 \fBSIGRTMIN+3\fR
678 if
679 \fB\-\-boot\fR
680 is used (on systemd\-compatible init systems
681 \fBSIGRTMIN+3\fR
682 triggers an orderly shutdown)\&. If
683 \fB\-\-boot\fR
684 is not used and this option is not specified, the container\*(Aqs processes are terminated abruptly via
685 \fBSIGKILL\fR\&. For a list of valid signals, see
686 \fBsignal\fR(7)\&.
687 .sp
688 Added in version 220\&.
689 .RE
690 .PP
691 \fB\-\-notify\-ready=\fR
692 .RS 4
693 Configures support for notifications from the container\*(Aqs init process\&.
694 \fB\-\-notify\-ready=\fR
695 takes a boolean\&. If false
696 \fBsystemd\-nspawn\fR
697 notifies the calling service manager with a
698 "READY=1"
699 message when the init process is created\&. If true it waits for a
700 "READY=1"
701 message from the init process in the VM before sending its own to the service manager\&. For more details about notifications see
702 \fBsd_notify\fR(3)\&.
703 .sp
704 Defaults to false\&. (Note that this is unlike the option of the same name to
705 \fBsystemd-vmspawn\fR(1)
706 that defaults to true\&.)
707 .sp
708 Added in version 231\&.
709 .RE
710 .PP
711 \fB\-\-suppress\-sync=\fR
712 .RS 4
713 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
714 \fBsync\fR(2),
715 \fBfsync()\fR,
716 \fBsyncfs()\fR, \&... will execute no operation, and the
717 \fBO_SYNC\fR/\fBO_DSYNC\fR
718 flags to
719 \fBopen\fR(2)
720 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\&.
721 .sp
722 Added in version 250\&.
723 .RE
724 .SS "System Identity Options"
725 .PP
726 \fB\-M\fR, \fB\-\-machine=\fR
727 .RS 4
728 Sets the machine name for this container\&. This name may be used to identify this container during its runtime (for example in tools like
729 \fBmachinectl\fR(1)
730 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
731 \fB\-\-ephemeral\fR
732 mode is selected\&. If the root directory selected is the host\*(Aqs root directory the host\*(Aqs hostname is used as default instead\&.
733 .sp
734 Added in version 202\&.
735 .RE
736 .PP
737 \fB\-\-hostname=\fR
738 .RS 4
739 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
740 \fB\-\-machine=\fR
741 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
742 \fB\-\-machine=\fR
743 exclusively\&. Note that regardless whether the container\*(Aqs hostname is initialized from the name set with
744 \fB\-\-hostname=\fR
745 or the one set with
746 \fB\-\-machine=\fR, the container can later override its kernel hostname freely on its own as well\&.
747 .sp
748 Added in version 239\&.
749 .RE
750 .PP
751 \fB\-\-uuid=\fR
752 .RS 4
753 Set the specified UUID for the container\&. The init system will initialize
754 /etc/machine\-id
755 from this if this file is not set yet\&. Note that this option takes effect only if
756 /etc/machine\-id
757 in the container is unpopulated\&.
758 .RE
759 .SS "Property Options"
760 .PP
761 \fB\-S\fR, \fB\-\-slice=\fR
762 .RS 4
763 Make the container part of the specified slice, instead of the default
764 machine\&.slice\&. This applies only if the machine is run in its own scope unit, i\&.e\&. if
765 \fB\-\-keep\-unit\fR
766 is not used\&.
767 .sp
768 Added in version 206\&.
769 .RE
770 .PP
771 \fB\-\-property=\fR
772 .RS 4
773 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
774 \fB\-\-keep\-unit\fR
775 is not used\&. Takes unit property assignments in the same format as
776 \fBsystemctl set\-property\fR\&. This is useful to set memory limits and similar for the container\&.
777 .sp
778 Added in version 220\&.
779 .RE
780 .PP
781 \fB\-\-register=\fR
782 .RS 4
783 Controls whether the container is registered with
784 \fBsystemd-machined\fR(8)\&. Takes a boolean argument, which defaults to
785 "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
786 \fBmachinectl\fR(1)
787 and shown by tools such as
788 \fBps\fR(1)\&. If the container does not run a service manager, it is recommended to set this option to
789 "no"\&.
790 .sp
791 Added in version 209\&.
792 .RE
793 .PP
794 \fB\-\-keep\-unit\fR
795 .RS 4
796 Instead of creating a transient scope unit to run the container in, simply use the service or scope unit
797 \fBsystemd\-nspawn\fR
798 has been invoked in\&. If
799 \fB\-\-register=yes\fR
800 is set this unit is registered with
801 \fBsystemd-machined\fR(8)\&. This switch should be used if
802 \fBsystemd\-nspawn\fR
803 is invoked from within a service unit, and the service unit\*(Aqs sole purpose is to run a single
804 \fBsystemd\-nspawn\fR
805 container\&. This option is not available if run from a user session\&.
806 .sp
807 Note that passing
808 \fB\-\-keep\-unit\fR
809 disables the effect of
810 \fB\-\-slice=\fR
811 and
812 \fB\-\-property=\fR\&. Use
813 \fB\-\-keep\-unit\fR
814 and
815 \fB\-\-register=no\fR
816 in combination to disable any kind of unit allocation or registration with
817 \fBsystemd\-machined\fR\&.
818 .sp
819 Added in version 209\&.
820 .RE
821 .SS "User Namespacing Options"
822 .PP
823 \fB\-\-private\-users=\fR
824 .RS 4
825 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:
826 .sp
827 .RS 4
828 .ie n \{\
829 \h'-04' 1.\h'+01'\c
830 .\}
831 .el \{\
832 .sp -1
833 .IP " 1." 4.2
834 .\}
835 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\&.
836 .RE
837 .sp
838 .RS 4
839 .ie n \{\
840 \h'-04' 2.\h'+01'\c
841 .\}
842 .el \{\
843 .sp -1
844 .IP " 2." 4.2
845 .\}
846 If the parameter is
847 "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\&.
848 .RE
849 .sp
850 .RS 4
851 .ie n \{\
852 \h'-04' 3.\h'+01'\c
853 .\}
854 .el \{\
855 .sp -1
856 .IP " 3." 4.2
857 .\}
858 The special value
859 "pick"
860 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
861 "yes"
862 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
863 \fB\-\-private\-users\-ownership=auto\fR
864 (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)\&.
865 .RE
866 .sp
867 .RS 4
868 .ie n \{\
869 \h'-04' 4.\h'+01'\c
870 .\}
871 .el \{\
872 .sp -1
873 .IP " 4." 4.2
874 .\}
875 If the parameter is
876 "no", user namespacing is turned off\&. This is the default when
877 \fBsystemd\-nspawn\fR
878 is invoked directly\&. (Note that the
879 systemd\-nspawn@\&.service
880 unit enables private users\&.) This option is not secure and must not be used to run untrusted code\&.
881 .RE
882 .sp
883 .RS 4
884 .ie n \{\
885 \h'-04' 5.\h'+01'\c
886 .\}
887 .el \{\
888 .sp -1
889 .IP " 5." 4.2
890 .\}
891 If the parameter is
892 "identity", user namespacing is employed with an identity mapping for the first 65536 UIDs/GIDs\&. This is mostly equivalent to
893 \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\&.
894 .RE
895 .sp
896 .RS 4
897 .ie n \{\
898 \h'-04' 6.\h'+01'\c
899 .\}
900 .el \{\
901 .sp -1
902 .IP " 6." 4.2
903 .\}
904 If the parameter is
905 "managed", user namespacing is employed with in
906 \fImanaged\fR
907 mode, i\&.e\&. allocation of a UID range is delegated to
908 \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\&.
909 .RE
910 .sp
911 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
912 \fB\-\-private\-users=pick\fR
913 option\&.
914 .sp
915 When user namespaces are used, the GID range assigned to each container is always chosen identical to the UID range\&.
916 .sp
917 In most cases,
918 \fB\-\-private\-users=managed\fR
919 (or when privileged
920 \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\&.
921 .sp
922 Note that the picked UID/GID range is not written to
923 /etc/passwd
924 or
925 /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
926 \fB\-\-private\-users\-ownership=\fR\&.
927 .sp
928 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\&.
929 .sp
930 Note that for fully unprivileged operation in
931 "managed"
932 mode, any directory image should be owned by the foreign UID range\&.
933 .sp
934 Added in version 220\&.
935 .RE
936 .PP
937 \fB\-\-private\-users\-ownership=\fR
938 .RS 4
939 Controls how to adjust the container image\*(Aqs UIDs and GIDs to match the UID/GID range chosen with
940 \fB\-\-private\-users=\fR, see above\&. Takes one of
941 "off"
942 (to leave the image as is),
943 "chown"
944 (to recursively
945 \fBchown()\fR
946 the container\*(Aqs directory tree as needed),
947 "map"
948 (in order to use transparent ID mapping mounts from UID 0 to the target UID range),
949 "foreign"
950 (the same, but from the foreign UID range base) or
951 "auto"
952 for automatically using
953 "map"
954 or
955 "foreign", where available and applicable and
956 "chown"
957 where not\&.
958 .sp
959 If
960 "chown"
961 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\&.
962 .sp
963 Typically
964 "foreign"
965 or
966 "map"
967 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\&.
968 .sp
969 The
970 \fB\-\-private\-users\-ownership=auto\fR
971 option is implied if
972 \fB\-\-private\-users=pick\fR
973 is used\&. This option has no effect if user namespacing is not used\&.
974 .sp
975 \fBsystemd-dissect\fR(1)\*(Aqs
976 \fB\-\-shift\fR
977 switch may be used to shift UID/GID ownership from or to the 0, foreign or specific container UID/GID base outside of any
978 \fBsystemd\-nspawn\fR
979 invocation\&.
980 .sp
981 Added in version 230\&.
982 .RE
983 .PP
984 \fB\-U\fR
985 .RS 4
986 If the kernel supports the user namespaces feature, equivalent to
987 \fB\-\-private\-users=pick \-\-private\-users\-ownership=auto\fR, otherwise equivalent to
988 \fB\-\-private\-users=no\fR\&.
989 .sp
990 Note that
991 \fB\-U\fR
992 is the default if the
993 systemd\-nspawn@\&.service
994 template unit file is used\&.
995 .sp
996 Note: it is possible to undo the effect of
997 \fB\-\-private\-users\-ownership=chown\fR
998 (or
999 \fB\-U\fR) on the file system by redoing the operation with the first UID of 0:
1000 .sp
1001 .if n \{\
1002 .RS 4
1003 .\}
1004 .nf
1005 systemd\-nspawn \&... \-\-private\-users=0 \-\-private\-users\-ownership=chown
1006 .fi
1007 .if n \{\
1008 .RE
1009 .\}
1010 .sp
1011 Added in version 230\&.
1012 .RE
1013 .SS "Networking Options"
1014 .PP
1015 \fB\-\-private\-network\fR
1016 .RS 4
1017 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
1018 \fB\-\-network\-interface=\fR
1019 and configured with
1020 \fB\-\-network\-veth\fR\&. If this option is specified, the
1021 \fBCAP_NET_ADMIN\fR
1022 capability will be added to the set of capabilities the container retains\&. The latter may be disabled by using
1023 \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\&.
1024 .RE
1025 .PP
1026 \fB\-\-network\-interface=\fR
1027 .RS 4
1028 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
1029 \fB\-\-network\-interface=\fR
1030 implies
1031 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1032 .sp
1033 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
1034 systemd\-nspawn@\&.service
1035 unit file instance, it might hence make sense to add a unit file drop\-in to the service instance (e\&.g\&.
1036 /etc/systemd/system/systemd\-nspawn@foobar\&.service\&.d/50\-network\&.conf) with contents like the following:
1037 .sp
1038 .if n \{\
1039 .RS 4
1040 .\}
1041 .nf
1042 [Unit]
1043 Wants=sys\-subsystem\-net\-devices\-ens1\&.device
1044 After=sys\-subsystem\-net\-devices\-ens1\&.device
1045 .fi
1046 .if n \{\
1047 .RE
1048 .\}
1049 .sp
1050 This will make sure that activation of the container service will be delayed until the
1051 "ens1"
1052 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\&.
1053 .sp
1054 Added in version 209\&.
1055 .RE
1056 .PP
1057 \fB\-\-network\-macvlan=\fR
1058 .RS 4
1059 Create a
1060 "macvlan"
1061 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
1062 "macvlan"
1063 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
1064 "mv\-"\&. Note that
1065 \fB\-\-network\-macvlan=\fR
1066 implies
1067 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1068 .sp
1069 As with
1070 \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\&.
1071 .sp
1072 Added in version 211\&.
1073 .RE
1074 .PP
1075 \fB\-\-network\-ipvlan=\fR
1076 .RS 4
1077 Create an
1078 "ipvlan"
1079 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
1080 "ipvlan"
1081 interface is a virtual interface, similar to a
1082 "macvlan"
1083 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
1084 "iv\-"\&. Note that
1085 \fB\-\-network\-ipvlan=\fR
1086 implies
1087 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1088 .sp
1089 As with
1090 \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\&.
1091 .sp
1092 Added in version 219\&.
1093 .RE
1094 .PP
1095 \fB\-n\fR, \fB\-\-network\-veth\fR
1096 .RS 4
1097 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
1098 \fB\-\-machine=\fR), prefixed with
1099 "ve\-"\&. The container side of the Ethernet link will be named
1100 "host0"\&. The
1101 \fB\-\-network\-veth\fR
1102 option implies
1103 \fB\-\-private\-network\fR\&.
1104 .sp
1105 Note that
1106 \fBsystemd-networkd.service\fR(8)
1107 includes by default a network file
1108 /usr/lib/systemd/network/80\-container\-ve\&.network
1109 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
1110 /usr/lib/systemd/network/80\-container\-host0\&.network
1111 matching the container\-side interface created this way, containing settings to enable client side address assignment via DHCP\&. In case
1112 systemd\-networkd
1113 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\&.
1114 .sp
1115 Note that
1116 \fB\-\-network\-veth\fR
1117 is the default if the
1118 systemd\-nspawn@\&.service
1119 template unit file is used\&.
1120 .sp
1121 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,
1122 \fBsystemd\-nspawn\fR
1123 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
1124 \fBsystemd.net-naming-scheme\fR(7)
1125 for details on older naming algorithms for this interface)\&. Alternatively, the
1126 \fB\-\-network\-veth\-extra=\fR
1127 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
1128 \fB\-\-network\-bridge=\fR
1129 is desired\&.
1130 .sp
1131 Added in version 209\&.
1132 .RE
1133 .PP
1134 \fB\-\-network\-veth\-extra=\fR
1135 .RS 4
1136 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
1137 \fB\-\-network\-veth\fR, and \(em in contrast \(em may be used multiple times, and allows configuration of the network interface names\&. Note that
1138 \fB\-\-network\-bridge=\fR
1139 has no effect on interfaces created with
1140 \fB\-\-network\-veth\-extra=\fR\&.
1141 .sp
1142 Added in version 228\&.
1143 .RE
1144 .PP
1145 \fB\-\-network\-bridge=\fR
1146 .RS 4
1147 Adds the host side of the Ethernet link created with
1148 \fB\-\-network\-veth\fR
1149 to the specified Ethernet bridge interface\&. Expects a valid network interface name of a bridge device as argument\&. Note that
1150 \fB\-\-network\-bridge=\fR
1151 implies
1152 \fB\-\-network\-veth\fR\&. If this option is used, the host side of the Ethernet link will use the
1153 "vb\-"
1154 prefix instead of
1155 "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)\&.
1156 .sp
1157 As with
1158 \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\&.
1159 .sp
1160 Added in version 209\&.
1161 .RE
1162 .PP
1163 \fB\-\-network\-zone=\fR
1164 .RS 4
1165 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
1166 "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
1167 \fB\-\-network\-bridge=\fR, besides this automatic creation/removal of the bridge device\&.
1168 .sp
1169 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
1170 "vz\-"), and it is sufficient to pass the same name to the
1171 \fB\-\-network\-zone=\fR
1172 switch of the various concurrently running containers to join them in one zone\&.
1173 .sp
1174 Note that
1175 \fBsystemd-networkd.service\fR(8)
1176 includes by default a network file
1177 /usr/lib/systemd/network/80\-container\-vz\&.network
1178 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
1179 \fB\-\-network\-zone=\fR
1180 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\&.
1181 .sp
1182 Added in version 230\&.
1183 .RE
1184 .PP
1185 \fB\-\-network\-namespace\-path=\fR
1186 .RS 4
1187 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
1188 /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
1189 /run/netns
1190 created by
1191 \fBip-netns\fR(8), for example,
1192 \fB\-\-network\-namespace\-path=/run/netns/foo\fR\&. Note that this option cannot be used together with other network\-related options, such as
1193 \fB\-\-private\-network\fR
1194 or
1195 \fB\-\-network\-interface=\fR\&.
1196 .sp
1197 Added in version 236\&.
1198 .RE
1199 .PP
1200 \fB\-p\fR, \fB\-\-port=\fR
1201 .RS 4
1202 If private networking is enabled, maps an IP port on the host onto an IP port on the container\&. Takes a protocol specifier (either
1203 "tcp"
1204 or
1205 "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
1206 "tcp"
1207 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
1208 \fB\-\-network\-veth\fR,
1209 \fB\-\-network\-zone=\fR
1210 \fB\-\-network\-bridge=\fR\&.
1211 .sp
1212 Added in version 219\&.
1213 .RE
1214 .SS "Security Options"
1215 .PP
1216 \fB\-\-capability=\fR
1217 .RS 4
1218 List one or more additional capabilities to grant the container\&. Takes a comma\-separated list of capability names, see
1219 \fBcapabilities\fR(7)
1220 for more information\&. Note that the following capabilities will be granted in any way:
1221 \fBCAP_AUDIT_CONTROL\fR,
1222 \fBCAP_AUDIT_WRITE\fR,
1223 \fBCAP_CHOWN\fR,
1224 \fBCAP_DAC_OVERRIDE\fR,
1225 \fBCAP_DAC_READ_SEARCH\fR,
1226 \fBCAP_FOWNER\fR,
1227 \fBCAP_FSETID\fR,
1228 \fBCAP_IPC_OWNER\fR,
1229 \fBCAP_KILL\fR,
1230 \fBCAP_LEASE\fR,
1231 \fBCAP_LINUX_IMMUTABLE\fR,
1232 \fBCAP_MKNOD\fR,
1233 \fBCAP_NET_BIND_SERVICE\fR,
1234 \fBCAP_NET_BROADCAST\fR,
1235 \fBCAP_NET_RAW\fR,
1236 \fBCAP_SETFCAP\fR,
1237 \fBCAP_SETGID\fR,
1238 \fBCAP_SETPCAP\fR,
1239 \fBCAP_SETUID\fR,
1240 \fBCAP_SYS_ADMIN\fR,
1241 \fBCAP_SYS_BOOT\fR,
1242 \fBCAP_SYS_CHROOT\fR,
1243 \fBCAP_SYS_NICE\fR,
1244 \fBCAP_SYS_PTRACE\fR,
1245 \fBCAP_SYS_RESOURCE\fR,
1246 \fBCAP_SYS_TTY_CONFIG\fR\&. Also
1247 \fBCAP_NET_ADMIN\fR
1248 is retained if
1249 \fB\-\-private\-network\fR
1250 is specified\&. If the special value
1251 "all"
1252 is passed, all capabilities are retained\&.
1253 .sp
1254 If the special value of
1255 "help"
1256 is passed, the program will print known capability names and exit\&.
1257 .sp
1258 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1259 \fB\-\-ambient\-capability=\fR\&.
1260 .sp
1261 Added in version 186\&.
1262 .RE
1263 .PP
1264 \fB\-\-drop\-capability=\fR
1265 .RS 4
1266 Specify one or more additional capabilities to drop for the container\&. This allows running the container with fewer capabilities than the default (see above)\&.
1267 .sp
1268 If the special value of
1269 "help"
1270 is passed, the program will print known capability names and exit\&.
1271 .sp
1272 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1273 \fB\-\-ambient\-capability=\fR\&.
1274 .sp
1275 Added in version 209\&.
1276 .RE
1277 .PP
1278 \fB\-\-ambient\-capability=\fR
1279 .RS 4
1280 Specify one or more additional capabilities to pass in the inheritable and ambient set to the program started within the container\&. The value
1281 "all"
1282 is not supported for this setting\&.
1283 .sp
1284 All capabilities specified here must be in the set allowed with the
1285 \fB\-\-capability=\fR
1286 and
1287 \fB\-\-drop\-capability=\fR
1288 options\&. Otherwise, an error message will be shown\&.
1289 .sp
1290 This option cannot be combined with the boot mode of the container (as requested via
1291 \fB\-\-boot\fR)\&.
1292 .sp
1293 If the special value of
1294 "help"
1295 is passed, the program will print known capability names and exit\&.
1296 .sp
1297 Added in version 248\&.
1298 .RE
1299 .PP
1300 \fB\-\-no\-new\-privileges=\fR
1301 .RS 4
1302 Takes a boolean argument\&. Specifies the value of the
1303 \fBPR_SET_NO_NEW_PRIVS\fR
1304 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
1305 \fBprctl\fR(2)
1306 for details about this flag\&.
1307 .sp
1308 Added in version 239\&.
1309 .RE
1310 .PP
1311 \fB\-\-system\-call\-filter=\fR
1312 .RS 4
1313 Alter the system call filter applied to containers\&. Takes a space\-separated list of system call names or group names (the latter prefixed with
1314 "@", as listed by the
1315 \fBsyscall\-filter\fR
1316 command of
1317 \fBsystemd-analyze\fR(1))\&. Passed system calls will be permitted\&. The list may optionally be prefixed by
1318 "~", 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
1319 "~"
1320 prefix) are configured, the negative list takes precedence over the positive list\&. Note that
1321 \fBsystemd\-nspawn\fR
1322 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
1323 "~"
1324 prefix\&. Note that the applied system call filter is also altered implicitly if additional capabilities are passed using the
1325 \fB\-\-capabilities=\fR\&.
1326 .sp
1327 Added in version 235\&.
1328 .RE
1329 .PP
1330 \fB\-Z\fR, \fB\-\-selinux\-context=\fR
1331 .RS 4
1332 Sets the SELinux security context to be used to label processes in the container\&.
1333 .sp
1334 Added in version 209\&.
1335 .RE
1336 .PP
1337 \fB\-L\fR, \fB\-\-selinux\-apifs\-context=\fR
1338 .RS 4
1339 Sets the SELinux security context to be used to label files in the virtual API file systems in the container\&.
1340 .sp
1341 Added in version 209\&.
1342 .RE
1343 .SS "Resource Options"
1344 .PP
1345 \fB\-\-rlimit=\fR
1346 .RS 4
1347 Sets the specified POSIX resource limit for the container payload\&. Expects an assignment of the form
1348 "\fILIMIT\fR=\fISOFT\fR:\fIHARD\fR"
1349 or
1350 "\fILIMIT\fR=\fIVALUE\fR", where
1351 \fILIMIT\fR
1352 should refer to a resource limit type, such as
1353 \fBRLIMIT_NOFILE\fR
1354 or
1355 \fBRLIMIT_NICE\fR\&. The
1356 \fISOFT\fR
1357 and
1358 \fIHARD\fR
1359 fields should refer to the numeric soft and hard resource limit values\&. If the second form is used,
1360 \fIVALUE\fR
1361 may specify a value that is used both as soft and hard limit\&. In place of a numeric value the special string
1362 "infinity"
1363 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
1364 \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
1365 \fBRLIMIT_NPROC\fR\&. This means that unless user namespacing is deployed (i\&.e\&.
1366 \fB\-\-private\-users=\fR
1367 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:
1368 "\-\-rlimit=RLIMIT_NOFILE=8192:16384"\&.
1369 .sp
1370 Added in version 239\&.
1371 .RE
1372 .PP
1373 \fB\-\-oom\-score\-adjust=\fR
1374 .RS 4
1375 Changes the OOM ("Out Of Memory") score adjustment value for the container payload\&. This controls
1376 /proc/self/oom_score_adj
1377 which influences the preference with which this container is terminated when memory becomes scarce\&. For details see
1378 \fBproc\fR(5)\&. Takes an integer in the range \-1000\&...1000\&.
1379 .sp
1380 Added in version 239\&.
1381 .RE
1382 .PP
1383 \fB\-\-cpu\-affinity=\fR
1384 .RS 4
1385 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
1386 \fBsched_setaffinity\fR(2)
1387 for details\&.
1388 .sp
1389 Added in version 239\&.
1390 .RE
1391 .PP
1392 \fB\-\-personality=\fR
1393 .RS 4
1394 Control the architecture ("personality") reported by
1395 \fBuname\fR(2)
1396 in the container\&. Currently, only
1397 "x86"
1398 and
1399 "x86\-64"
1400 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\&.
1401 .sp
1402 Added in version 209\&.
1403 .RE
1404 .SS "Integration Options"
1405 .PP
1406 \fB\-\-resolv\-conf=\fR
1407 .RS 4
1408 Configures how
1409 /etc/resolv\&.conf
1410 inside of the container shall be handled (i\&.e\&. DNS configuration synchronization from host to container)\&. Takes one of
1411 "off",
1412 "copy\-host",
1413 "copy\-static",
1414 "copy\-uplink",
1415 "copy\-stub",
1416 "replace\-host",
1417 "replace\-static",
1418 "replace\-uplink",
1419 "replace\-stub",
1420 "bind\-host",
1421 "bind\-static",
1422 "bind\-uplink",
1423 "bind\-stub",
1424 "delete"
1425 or
1426 "auto"\&.
1427 .sp
1428 If set to
1429 "off"
1430 the
1431 /etc/resolv\&.conf
1432 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&.
1433 .sp
1434 If set to
1435 "copy\-host", the
1436 /etc/resolv\&.conf
1437 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
1438 "replace\-host"
1439 is used the file is copied, replacing any existing inode, including symlinks\&. Similarly, if
1440 "bind\-host"
1441 is used, the file is bind mounted from the host into the container\&.
1442 .sp
1443 If set to
1444 "copy\-static",
1445 "replace\-static"
1446 or
1447 "bind\-static"
1448 the static
1449 resolv\&.conf
1450 file supplied with
1451 \fBsystemd-resolved.service\fR(8)
1452 (specifically:
1453 /usr/lib/systemd/resolv\&.conf) is copied or bind mounted into the container\&.
1454 .sp
1455 If set to
1456 "copy\-uplink",
1457 "replace\-uplink"
1458 or
1459 "bind\-uplink"
1460 the uplink
1461 resolv\&.conf
1462 file managed by
1463 systemd\-resolved\&.service
1464 (specifically:
1465 /run/systemd/resolve/resolv\&.conf) is copied or bind mounted into the container\&.
1466 .sp
1467 If set to
1468 "copy\-stub",
1469 "replace\-stub"
1470 or
1471 "bind\-stub"
1472 the stub
1473 resolv\&.conf
1474 file managed by
1475 systemd\-resolved\&.service
1476 (specifically:
1477 /run/systemd/resolve/stub\-resolv\&.conf) is copied or bind mounted into the container\&.
1478 .sp
1479 If set to
1480 "delete"
1481 the
1482 /etc/resolv\&.conf
1483 file in the container is deleted if it exists\&.
1484 .sp
1485 Finally, if set to
1486 "auto"
1487 the file is left as it is if private networking is turned on (see
1488 \fB\-\-private\-network\fR)\&. Otherwise, if
1489 systemd\-resolved\&.service
1490 is running its stub
1491 resolv\&.conf
1492 file is used, and if not the host\*(Aqs
1493 /etc/resolv\&.conf
1494 file\&. In the latter cases the file is copied if the image is writable, and bind mounted otherwise\&.
1495 .sp
1496 It\*(Aqs recommended to use
1497 "copy\-\&..."
1498 or
1499 "replace\-\&..."
1500 if the container shall be able to make changes to the DNS configuration on its own, deviating from the host\*(Aqs settings\&. Otherwise,
1501 "bind"
1502 is preferable, as it means direct changes to
1503 /etc/resolv\&.conf
1504 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
1505 "auto"\&.
1506 .sp
1507 Added in version 239\&.
1508 .RE
1509 .PP
1510 \fB\-\-timezone=\fR
1511 .RS 4
1512 Configures how
1513 /etc/localtime
1514 inside of the container (i\&.e\&. local timezone synchronization from host to container) shall be handled\&. Takes one of
1515 "off",
1516 "copy",
1517 "bind",
1518 "symlink",
1519 "delete"
1520 or
1521 "auto"\&. If set to
1522 "off"
1523 the
1524 /etc/localtime
1525 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&. If set to
1526 "copy"
1527 the
1528 /etc/localtime
1529 file of the host is copied into the container\&. Similarly, if
1530 "bind"
1531 is used, the file is bind mounted from the host into the container\&. If set to
1532 "symlink", a symlink is created pointing from
1533 /etc/localtime
1534 in the container to the timezone file in the container that matches the timezone setting on the host\&. If set to
1535 "delete", the file in the container is deleted, should it exist\&. If set to
1536 "auto"
1537 and the
1538 /etc/localtime
1539 file of the host is a symlink, then
1540 "symlink"
1541 mode is used, and
1542 "copy"
1543 otherwise, except if the image is read\-only in which case
1544 "bind"
1545 is used instead\&. Defaults to
1546 "auto"\&.
1547 .sp
1548 Added in version 239\&.
1549 .RE
1550 .PP
1551 \fB\-\-link\-journal=\fR
1552 .RS 4
1553 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
1554 "no",
1555 "host",
1556 "try\-host",
1557 "guest",
1558 "try\-guest",
1559 "auto"\&. If
1560 "no", the journal is not linked\&. If
1561 "host", the journal files are stored on the host file system (beneath
1562 /var/log/journal/\fImachine\-id\fR) and the subdirectory is bind\-mounted into the container at the same location\&. If
1563 "guest", the journal files are stored on the guest file system (beneath
1564 /var/log/journal/\fImachine\-id\fR) and the subdirectory is symlinked into the host at the same location\&.
1565 "try\-host"
1566 and
1567 "try\-guest"
1568 do the same but do not fail if the host does not have persistent journaling enabled, or if the container is in the
1569 \fB\-\-ephemeral\fR
1570 mode\&. If
1571 "auto"
1572 (the default), and the right subdirectory of
1573 /var/log/journal
1574 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
1575 "guest"
1576 or
1577 "host"
1578 will link the journal persistently if further on the default of
1579 "auto"
1580 is used\&.
1581 .sp
1582 Note that
1583 \fB\-\-link\-journal=try\-guest\fR
1584 is the default if the
1585 systemd\-nspawn@\&.service
1586 template unit file is used\&.
1587 .sp
1588 Added in version 187\&.
1589 .RE
1590 .PP
1591 \fB\-j\fR
1592 .RS 4
1593 Equivalent to
1594 \fB\-\-link\-journal=try\-guest\fR\&.
1595 .sp
1596 Added in version 187\&.
1597 .RE
1598 .SS "Mount Options"
1599 .PP
1600 \fB\-\-bind=\fR, \fB\-\-bind\-ro=\fR
1601 .RS 4
1602 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
1603 "+"
1604 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
1605 /var/tmp/
1606 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
1607 \fB\-\-bind\-ro=\fR
1608 option creates read\-only bind mounts\&. Backslash escapes are interpreted, so
1609 "\e:"
1610 may be used to embed colons in either path\&. This option may be specified multiple times for creating multiple independent bind mount points\&.
1611 .sp
1612 Mount options are comma\-separated\&.
1613 \fBrbind\fR
1614 and
1615 \fBnorbind\fR
1616 control whether to create a recursive or a regular bind mount\&. Defaults to
1617 \fBrbind\fR\&.
1618 \fBnoidmap\fR,
1619 \fBidmap\fR,
1620 \fBrootidmap\fR
1621 and
1622 \fBowneridmap\fR
1623 control ID mapping\&.
1624 .sp
1625 Using
1626 \fBidmap\fR,
1627 \fBrootidmap\fR
1628 or
1629 \fBowneridmap\fR
1630 requires support by the source filesystem for user/group ID mapped mounts\&. Defaults to
1631 \fBnoidmap\fR\&. With
1632 \fBx\fR
1633 being the container\*(Aqs UID range offset,
1634 \fBy\fR
1635 being the length of the container\*(Aqs UID range, and
1636 \fBp\fR
1637 being the owner UID of the bind mount source inode on the host:
1638 .sp
1639 .RS 4
1640 .ie n \{\
1641 \h'-04'\(bu\h'+03'\c
1642 .\}
1643 .el \{\
1644 .sp -1
1645 .IP \(bu 2.3
1646 .\}
1647 If
1648 \fBnoidmap\fR
1649 is used, any user
1650 \fBz\fR
1651 in the range
1652 \fB0 \&... y\fR
1653 seen from inside of the container is mapped to
1654 \fBx + z\fR
1655 in the
1656 \fBx \&... x + y\fR
1657 range on the host\&. Other host users are mapped to
1658 \fBnobody\fR
1659 inside the container\&.
1660 .RE
1661 .sp
1662 .RS 4
1663 .ie n \{\
1664 \h'-04'\(bu\h'+03'\c
1665 .\}
1666 .el \{\
1667 .sp -1
1668 .IP \(bu 2.3
1669 .\}
1670 If
1671 \fBidmap\fR
1672 is used, any user
1673 \fBz\fR
1674 in the UID range
1675 \fB0 \&... y\fR
1676 as seen from inside the container is mapped to the same
1677 \fBz\fR
1678 in the same
1679 \fB0 \&... y\fR
1680 range on the host\&. Other host users are mapped to
1681 \fBnobody\fR
1682 inside the container\&.
1683 .RE
1684 .sp
1685 .RS 4
1686 .ie n \{\
1687 \h'-04'\(bu\h'+03'\c
1688 .\}
1689 .el \{\
1690 .sp -1
1691 .IP \(bu 2.3
1692 .\}
1693 If
1694 \fBrootidmap\fR
1695 is used, the user
1696 \fB0\fR
1697 seen from inside of the container is mapped to
1698 \fBp\fR
1699 on the host\&. Other host users are mapped to
1700 \fBnobody\fR
1701 inside the container\&.
1702 .RE
1703 .sp
1704 .RS 4
1705 .ie n \{\
1706 \h'-04'\(bu\h'+03'\c
1707 .\}
1708 .el \{\
1709 .sp -1
1710 .IP \(bu 2.3
1711 .\}
1712 If
1713 \fBowneridmap\fR
1714 is used, the owner of the target directory inside of the container is mapped to
1715 \fBp\fR
1716 on the host\&. Other host users are mapped to
1717 \fBnobody\fR
1718 inside the container\&.
1719 .RE
1720 .sp
1721 Whichever ID mapping option is used, the same mapping will be used for users and groups IDs\&. If
1722 \fBrootidmap\fR
1723 or
1724 \fBowneridmap\fR
1725 are used, the group owning the bind mounted directory will have no effect\&.
1726 .sp
1727 Note that when this option is used in combination with
1728 \fB\-\-private\-users\fR, the resulting mount points will be owned by the
1729 \fBnobody\fR
1730 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
1731 \fB\-\-bind\-ro=\fR\&. Alternatively you can use the "idmap" mount option to map the filesystem IDs\&.
1732 .sp
1733 Added in version 198\&.
1734 .RE
1735 .PP
1736 \fB\-\-bind\-user=\fR
1737 .RS 4
1738 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:
1739 .sp
1740 .RS 4
1741 .ie n \{\
1742 \h'-04' 1.\h'+01'\c
1743 .\}
1744 .el \{\
1745 .sp -1
1746 .IP " 1." 4.2
1747 .\}
1748 The user\*(Aqs home directory is bind mounted from the host into
1749 /run/host/home/, using an idmapped mount to map the host user\*(Aqs UID/GID to its assigned UID/GID in the container\&.
1750 .RE
1751 .sp
1752 .RS 4
1753 .ie n \{\
1754 \h'-04' 2.\h'+01'\c
1755 .\}
1756 .el \{\
1757 .sp -1
1758 .IP " 2." 4.2
1759 .\}
1760 A JSON user and group record is generated in
1761 /run/userdb/
1762 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
1763 \fBnss-systemd\fR(8)
1764 glibc NSS module will pick up these records from there and make them available in the container\*(Aqs user/group databases\&.
1765 .RE
1766 .sp
1767 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
1768 \fB\-\-bind\-user=\fR
1769 mapping), those files and directories will be accessible to the "new" user\&.
1770 .sp
1771 The user/group record mapping only works if the container contains systemd 249 or newer, with
1772 \fBnss\-systemd\fR
1773 properly configured in
1774 nsswitch\&.conf\&. See
1775 \fBnss-systemd\fR(8)
1776 for details\&.
1777 .sp
1778 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
1779 "$y$"
1780 hash prefix)\&.
1781 .sp
1782 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
1783 /etc/passwd
1784 and
1785 /etc/group, and thus might not detect existing accounts in other databases\&.
1786 .sp
1787 Added in version 249\&.
1788 .RE
1789 .PP
1790 \fB\-\-bind\-user\-shell=\fR
1791 .RS 4
1792 When used with
1793 \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\&.
1794 .sp
1795 .RS 4
1796 .ie n \{\
1797 \h'-04'\(bu\h'+03'\c
1798 .\}
1799 .el \{\
1800 .sp -1
1801 .IP \(bu 2.3
1802 .\}
1803 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\&.
1804 .RE
1805 .sp
1806 .RS 4
1807 .ie n \{\
1808 \h'-04'\(bu\h'+03'\c
1809 .\}
1810 .el \{\
1811 .sp -1
1812 .IP \(bu 2.3
1813 .\}
1814 If true, the shells specified by the host user records are included in the user records of all users bound into the container\&.
1815 .RE
1816 .sp
1817 .RS 4
1818 .ie n \{\
1819 \h'-04'\(bu\h'+03'\c
1820 .\}
1821 .el \{\
1822 .sp -1
1823 .IP \(bu 2.3
1824 .\}
1825 If passed an absolute path, sets that path as the shell for user records of all users bound into the container\&.
1826 .RE
1827 .sp
1828 Note: This will not check whether the specified shells exist in the container\&.
1829 .sp
1830 This operation is only supported in combination with
1831 \fB\-\-bind\-user=\fR\&.
1832 .sp
1833 Added in version 258\&.
1834 .RE
1835 .PP
1836 \fB\-\-bind\-user\-group=\fR\fB\fINAME\fR\fR
1837 .RS 4
1838 When used with
1839 \fB\-\-bind\-user=\fR, includes the specified group as an auxiliary group in the user records of users bound into the container\&. Takes a group name\&.
1840 .sp
1841 Note: This will not check whether the specified groups 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 259\&.
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 UAPI.2 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