Debian Codegraph @

upstream/debian-trixie/man1/systemd-nspawn.1

raw
1 '\" t
2 .TH "SYSTEMD\-NSPAWN" "1" "" "systemd 257.13" "systemd-nspawn"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd-nspawn \- Spawn a command or OS in a lightweight container
24 .SH "SYNOPSIS"
25 .HP \w'\fBsystemd\-nspawn\fR\ 'u
26 \fBsystemd\-nspawn\fR [OPTIONS...] [\fICOMMAND\fR\ [ARGS...]]
27 .HP \w'\fBsystemd\-nspawn\fR\ 'u
28 \fBsystemd\-nspawn\fR \-\-boot [OPTIONS...] [ARGS...]
29 .SH "DESCRIPTION"
30 .PP
31 \fBsystemd\-nspawn\fR
32 may be used to run a command or OS in a lightweight namespace container\&. In many ways it is similar to
33 \fBchroot\fR(1), but more powerful since it virtualizes the file system hierarchy, as well as the process tree, the various IPC subsystems, and the host and domain names\&.
34 .PP
35 \fBsystemd\-nspawn\fR
36 may be invoked on any directory tree containing an operating system tree, using the
37 \fB\-\-directory=\fR
38 command line option\&. By using the
39 \fB\-\-machine=\fR
40 option an OS tree is automatically searched for in a couple of locations, most importantly in
41 /var/lib/machines/, the suggested directory to place OS container images installed on the system\&.
42 .PP
43 In contrast to
44 \fBchroot\fR(1)\ \&\fBsystemd\-nspawn\fR
45 may be used to boot full Linux\-based operating systems in a container\&.
46 .PP
47 \fBsystemd\-nspawn\fR
48 limits access to various kernel interfaces in the container to read\-only, such as
49 /sys/,
50 /proc/sys/, or
51 /sys/fs/selinux/\&. The host\*(Aqs network interfaces and the system clock may not be changed from within the container\&. Device nodes may not be created\&. The host system cannot be rebooted and kernel modules may not be loaded from within the container\&.
52 \fIThis sandbox can easily be circumvented from within the container if user namespaces are not used\fR\&. This means that untrusted code must always be run in a user namespace, see the discussion of the
53 \fB\-\-private\-users=\fR
54 option below\&.
55 .PP
56 Use a tool like
57 \fBdnf\fR(8),
58 \fBdebootstrap\fR(8), or
59 \fBpacman\fR(8)
60 to set up an OS directory tree suitable as file system hierarchy for
61 \fBsystemd\-nspawn\fR
62 containers\&. See the Examples section below for details on suitable invocation of these commands\&.
63 .PP
64 As a safety check
65 \fBsystemd\-nspawn\fR
66 will verify the existence of
67 /usr/lib/os\-release
68 or
69 /etc/os\-release
70 in the container tree before booting a container (see
71 \fBos-release\fR(5))\&. It might be necessary to add this file to the container tree manually if the OS of the container is too old to contain this file out\-of\-the\-box\&.
72 .PP
73 \fBsystemd\-nspawn\fR
74 may be invoked directly from the interactive command line or run as system service in the background\&. In this mode each container instance runs as its own service instance; a default template unit file
75 systemd\-nspawn@\&.service
76 is provided to make this easy, taking the container name as instance identifier\&. Note that different default options apply when
77 \fBsystemd\-nspawn\fR
78 is invoked by the template unit file than interactively on the command line\&. Most importantly the template unit file makes use of the
79 \fB\-\-boot\fR
80 option which is not the default in case
81 \fBsystemd\-nspawn\fR
82 is invoked from the interactive command line\&. Further differences with the defaults are documented along with the various supported options below\&.
83 .PP
84 The
85 \fBmachinectl\fR(1)
86 tool may be used to execute a number of operations on containers\&. In particular it provides easy\-to\-use commands to run containers as system services using the
87 systemd\-nspawn@\&.service
88 template unit file\&.
89 .PP
90 Along with each container a settings file with the
91 \&.nspawn
92 suffix may exist, containing additional settings to apply when running the container\&. See
93 \fBsystemd.nspawn\fR(5)
94 for details\&. Settings files override the default options used by the
95 systemd\-nspawn@\&.service
96 template unit file, making it usually unnecessary to alter this template file directly\&.
97 .PP
98 Note that
99 \fBsystemd\-nspawn\fR
100 will mount file systems private to the container to
101 /dev/,
102 /run/, and similar\&. These will not be visible outside of the container, and their contents will be lost when the container exits\&.
103 .PP
104 Note that running two
105 \fBsystemd\-nspawn\fR
106 containers from the same directory tree will not make processes in them see each other\&. The PID namespace separation of the two containers is complete and the containers will share very few runtime objects except for the underlying file system\&. Rather use
107 \fBmachinectl\fR(1)\*(Aqs
108 \fBlogin\fR
109 or
110 \fBshell\fR
111 commands to request an additional login session in a running container\&.
112 .PP
113 \fBsystemd\-nspawn\fR
114 implements the
115 \m[blue]\fBContainer Interface\fR\m[]\&\s-2\u[1]\d\s+2
116 specification\&.
117 .PP
118 While running, containers invoked with
119 \fBsystemd\-nspawn\fR
120 are registered with the
121 \fBsystemd-machined\fR(8)
122 service that keeps track of running containers, and provides programming interfaces to interact with them\&.
123 .SH "UNPRIVILEGED OPERATION"
124 .PP
125 \fBsystemd\-nspawn\fR
126 may be invoked with or without privileges\&. The full functionality is currently only available when invoked with privileges\&. When invoked without privileges, various limitations apply, including, but not limited to:
127 .sp
128 .RS 4
129 .ie n \{\
130 \h'-04'\(bu\h'+03'\c
131 .\}
132 .el \{\
133 .sp -1
134 .IP \(bu 2.3
135 .\}
136 Only disk image based containers are supported (i\&.e\&.
137 \fB\-\-image=\fR)\&. Directory based ones (i\&.e\&.
138 \fB\-\-directory=\fR) are not supported\&.
139 .RE
140 .sp
141 .RS 4
142 .ie n \{\
143 \h'-04'\(bu\h'+03'\c
144 .\}
145 .el \{\
146 .sp -1
147 .IP \(bu 2.3
148 .\}
149 Machine registration via
150 \fB\-\-machine=\fR
151 is not supported\&.
152 .RE
153 .sp
154 .RS 4
155 .ie n \{\
156 \h'-04'\(bu\h'+03'\c
157 .\}
158 .el \{\
159 .sp -1
160 .IP \(bu 2.3
161 .\}
162 Only
163 \fB\-\-private\-network\fR
164 and
165 \fB\-\-network\-veth\fR
166 networking modes are supported\&.
167 .RE
168 .PP
169 When running in unprivileged mode, some needed functionality is provided via
170 \fBsystemd-mountfsd.service\fR(8)
171 and
172 \fBsystemd-nsresourced.service\fR(8)\&.
173 .SH "OPTIONS"
174 .PP
175 If option
176 \fB\-\-boot\fR
177 is specified, the arguments are used as arguments for the init program\&. Otherwise,
178 \fICOMMAND\fR
179 specifies the program to launch in the container, and the remaining arguments are used as arguments for this program\&. If
180 \fB\-\-boot\fR
181 is not used and no arguments are specified, a shell is launched in the container\&.
182 .PP
183 The following options are understood:
184 .PP
185 \fB\-q\fR, \fB\-\-quiet\fR
186 .RS 4
187 Turns off any status output by the tool itself\&. When this switch is used, the only output from nspawn will be the console output of the container OS itself\&.
188 .sp
189 Added in version 209\&.
190 .RE
191 .PP
192 \fB\-\-settings=\fR\fB\fIMODE\fR\fR
193 .RS 4
194 Controls whether
195 \fBsystemd\-nspawn\fR
196 shall search for and use additional per\-container settings from
197 \&.nspawn
198 files\&. Takes a boolean or the special values
199 \fBoverride\fR
200 or
201 \fBtrusted\fR\&.
202 .sp
203 If enabled (the default), a settings file named after the machine (as specified with the
204 \fB\-\-machine=\fR
205 setting, or derived from the directory or image file name) with the suffix
206 \&.nspawn
207 is searched in
208 /etc/systemd/nspawn/
209 and
210 /run/systemd/nspawn/\&. If it is found there, its settings are read and used\&. If it is not found there, it is subsequently searched in the same directory as the image file or in the immediate parent of the root directory of the container\&. In this case, if the file is found, its settings will be also read and used, but potentially unsafe settings are ignored\&. Note that in both these cases, settings on the command line take precedence over the corresponding settings from loaded
211 \&.nspawn
212 files, if both are specified\&. Unsafe settings are considered all settings that elevate the container\*(Aqs privileges or grant access to additional resources such as files or directories of the host\&. For details about the format and contents of
213 \&.nspawn
214 files, consult
215 \fBsystemd.nspawn\fR(5)\&.
216 .sp
217 If this option is set to
218 \fBoverride\fR, the file is searched, read and used the same way, however, the order of precedence is reversed: settings read from the
219 \&.nspawn
220 file will take precedence over the corresponding command line options, if both are specified\&.
221 .sp
222 If this option is set to
223 \fBtrusted\fR, the file is searched, read and used the same way, but regardless of being found in
224 /etc/systemd/nspawn/,
225 /run/systemd/nspawn/
226 or next to the image file or container root directory, all settings will take effect, however, command line arguments still take precedence over corresponding settings\&.
227 .sp
228 If disabled, no
229 \&.nspawn
230 file is read and no settings except the ones on the command line are in effect\&.
231 .sp
232 Added in version 226\&.
233 .RE
234 .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]\fBDiscoverable 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 if 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 (\fBno\fR
696 and
697 \fByes\fR)\&. With option
698 \fBno\fR
699 systemd\-nspawn notifies systemd with a
700 "READY=1"
701 message when the init process is created\&. With option
702 \fByes\fR
703 systemd\-nspawn waits for the
704 "READY=1"
705 message from the init process in the container before sending its own to systemd\&. For more details about notifications see
706 \fBsd_notify\fR(3)\&.
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 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
897 \fB\-\-private\-users=pick\fR
898 option\&.
899 .sp
900 When user namespaces are used, the GID range assigned to each container is always chosen identical to the UID range\&.
901 .sp
902 In most cases, using
903 \fB\-\-private\-users=pick\fR
904 is the recommended option as user namespacing is required for security, and this option massively enhances container security while operating fully automatically in most cases\&.
905 .sp
906 Note that the picked UID/GID range is not written to
907 /etc/passwd
908 or
909 /etc/group\&. In fact, the allocation of the range is not stored persistently, except in the file ownership of the files and directories of the container\&.
910 .sp
911 Note that when user namespacing is used 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\&.
912 .sp
913 Added in version 220\&.
914 .RE
915 .PP
916 \fB\-\-private\-users\-ownership=\fR
917 .RS 4
918 Controls how to adjust the container image\*(Aqs UIDs and GIDs to match the UID/GID range chosen with
919 \fB\-\-private\-users=\fR, see above\&. Takes one of
920 "off"
921 (to leave the image as is),
922 "chown"
923 (to recursively
924 \fBchown()\fR
925 the container\*(Aqs directory tree as needed),
926 "map"
927 (in order to use transparent ID mapping mounts) or
928 "auto"
929 for automatically using
930 "map"
931 where available and
932 "chown"
933 where not\&.
934 .sp
935 If
936 "chown"
937 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\&.
938 .sp
939 Typically
940 "map"
941 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\&.
942 .sp
943 The
944 \fB\-\-private\-users\-ownership=auto\fR
945 option is implied if
946 \fB\-\-private\-users=pick\fR
947 is used\&. This option has no effect if user namespacing is not used\&.
948 .sp
949 Added in version 230\&.
950 .RE
951 .PP
952 \fB\-U\fR
953 .RS 4
954 If the kernel supports the user namespaces feature, equivalent to
955 \fB\-\-private\-users=pick \-\-private\-users\-ownership=auto\fR, otherwise equivalent to
956 \fB\-\-private\-users=no\fR\&.
957 .sp
958 Note that
959 \fB\-U\fR
960 is the default if the
961 systemd\-nspawn@\&.service
962 template unit file is used\&.
963 .sp
964 Note: it is possible to undo the effect of
965 \fB\-\-private\-users\-ownership=chown\fR
966 (or
967 \fB\-U\fR) on the file system by redoing the operation with the first UID of 0:
968 .sp
969 .if n \{\
970 .RS 4
971 .\}
972 .nf
973 systemd\-nspawn \&... \-\-private\-users=0 \-\-private\-users\-ownership=chown
974 .fi
975 .if n \{\
976 .RE
977 .\}
978 .sp
979 Added in version 230\&.
980 .RE
981 .SS "Networking Options"
982 .PP
983 \fB\-\-private\-network\fR
984 .RS 4
985 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
986 \fB\-\-network\-interface=\fR
987 and configured with
988 \fB\-\-network\-veth\fR\&. If this option is specified, the
989 \fBCAP_NET_ADMIN\fR
990 capability will be added to the set of capabilities the container retains\&. The latter may be disabled by using
991 \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\&.
992 .RE
993 .PP
994 \fB\-\-network\-interface=\fR
995 .RS 4
996 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
997 \fB\-\-network\-interface=\fR
998 implies
999 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1000 .sp
1001 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
1002 systemd\-nspawn@\&.service
1003 unit file instance, it might hence make sense to add a unit file drop\-in to the service instance (e\&.g\&.
1004 /etc/systemd/system/systemd\-nspawn@foobar\&.service\&.d/50\-network\&.conf) with contents like the following:
1005 .sp
1006 .if n \{\
1007 .RS 4
1008 .\}
1009 .nf
1010 [Unit]
1011 Wants=sys\-subsystem\-net\-devices\-ens1\&.device
1012 After=sys\-subsystem\-net\-devices\-ens1\&.device
1013 .fi
1014 .if n \{\
1015 .RE
1016 .\}
1017 .sp
1018 This will make sure that activation of the container service will be delayed until the
1019 "ens1"
1020 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\&.
1021 .sp
1022 Added in version 209\&.
1023 .RE
1024 .PP
1025 \fB\-\-network\-macvlan=\fR
1026 .RS 4
1027 Create a
1028 "macvlan"
1029 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
1030 "macvlan"
1031 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
1032 "mv\-"\&. Note that
1033 \fB\-\-network\-macvlan=\fR
1034 implies
1035 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1036 .sp
1037 As with
1038 \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\&.
1039 .sp
1040 Added in version 211\&.
1041 .RE
1042 .PP
1043 \fB\-\-network\-ipvlan=\fR
1044 .RS 4
1045 Create an
1046 "ipvlan"
1047 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
1048 "ipvlan"
1049 interface is a virtual interface, similar to a
1050 "macvlan"
1051 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
1052 "iv\-"\&. Note that
1053 \fB\-\-network\-ipvlan=\fR
1054 implies
1055 \fB\-\-private\-network\fR\&. This option may be used more than once to add multiple network interfaces to the container\&.
1056 .sp
1057 As with
1058 \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\&.
1059 .sp
1060 Added in version 219\&.
1061 .RE
1062 .PP
1063 \fB\-n\fR, \fB\-\-network\-veth\fR
1064 .RS 4
1065 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
1066 \fB\-\-machine=\fR), prefixed with
1067 "ve\-"\&. The container side of the Ethernet link will be named
1068 "host0"\&. The
1069 \fB\-\-network\-veth\fR
1070 option implies
1071 \fB\-\-private\-network\fR\&.
1072 .sp
1073 Note that
1074 \fBsystemd-networkd.service\fR(8)
1075 includes by default a network file
1076 /usr/lib/systemd/network/80\-container\-ve\&.network
1077 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
1078 /usr/lib/systemd/network/80\-container\-host0\&.network
1079 matching the container\-side interface created this way, containing settings to enable client side address assignment via DHCP\&. In case
1080 systemd\-networkd
1081 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\&.
1082 .sp
1083 Note that
1084 \fB\-\-network\-veth\fR
1085 is the default if the
1086 systemd\-nspawn@\&.service
1087 template unit file is used\&.
1088 .sp
1089 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,
1090 \fBsystemd\-nspawn\fR
1091 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
1092 \fBsystemd.net-naming-scheme\fR(7)
1093 for details on older naming algorithms for this interface)\&. Alternatively, the
1094 \fB\-\-network\-veth\-extra=\fR
1095 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
1096 \fB\-\-network\-bridge=\fR
1097 is desired\&.
1098 .sp
1099 Added in version 209\&.
1100 .RE
1101 .PP
1102 \fB\-\-network\-veth\-extra=\fR
1103 .RS 4
1104 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
1105 \fB\-\-network\-veth\fR, and \(em in contrast \(em may be used multiple times, and allows configuration of the network interface names\&. Note that
1106 \fB\-\-network\-bridge=\fR
1107 has no effect on interfaces created with
1108 \fB\-\-network\-veth\-extra=\fR\&.
1109 .sp
1110 Added in version 228\&.
1111 .RE
1112 .PP
1113 \fB\-\-network\-bridge=\fR
1114 .RS 4
1115 Adds the host side of the Ethernet link created with
1116 \fB\-\-network\-veth\fR
1117 to the specified Ethernet bridge interface\&. Expects a valid network interface name of a bridge device as argument\&. Note that
1118 \fB\-\-network\-bridge=\fR
1119 implies
1120 \fB\-\-network\-veth\fR\&. If this option is used, the host side of the Ethernet link will use the
1121 "vb\-"
1122 prefix instead of
1123 "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)\&.
1124 .sp
1125 As with
1126 \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\&.
1127 .sp
1128 Added in version 209\&.
1129 .RE
1130 .PP
1131 \fB\-\-network\-zone=\fR
1132 .RS 4
1133 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
1134 "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
1135 \fB\-\-network\-bridge=\fR, besides this automatic creation/removal of the bridge device\&.
1136 .sp
1137 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
1138 "vz\-"), and it is sufficient to pass the same name to the
1139 \fB\-\-network\-zone=\fR
1140 switch of the various concurrently running containers to join them in one zone\&.
1141 .sp
1142 Note that
1143 \fBsystemd-networkd.service\fR(8)
1144 includes by default a network file
1145 /usr/lib/systemd/network/80\-container\-vz\&.network
1146 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
1147 \fB\-\-network\-zone=\fR
1148 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\&.
1149 .sp
1150 Added in version 230\&.
1151 .RE
1152 .PP
1153 \fB\-\-network\-namespace\-path=\fR
1154 .RS 4
1155 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
1156 /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
1157 /run/netns
1158 created by
1159 \fBip-netns\fR(8), for example,
1160 \fB\-\-network\-namespace\-path=/run/netns/foo\fR\&. Note that this option cannot be used together with other network\-related options, such as
1161 \fB\-\-private\-network\fR
1162 or
1163 \fB\-\-network\-interface=\fR\&.
1164 .sp
1165 Added in version 236\&.
1166 .RE
1167 .PP
1168 \fB\-p\fR, \fB\-\-port=\fR
1169 .RS 4
1170 If private networking is enabled, maps an IP port on the host onto an IP port on the container\&. Takes a protocol specifier (either
1171 "tcp"
1172 or
1173 "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
1174 "tcp"
1175 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
1176 \fB\-\-network\-veth\fR,
1177 \fB\-\-network\-zone=\fR
1178 \fB\-\-network\-bridge=\fR\&.
1179 .sp
1180 Added in version 219\&.
1181 .RE
1182 .SS "Security Options"
1183 .PP
1184 \fB\-\-capability=\fR
1185 .RS 4
1186 List one or more additional capabilities to grant the container\&. Takes a comma\-separated list of capability names, see
1187 \fBcapabilities\fR(7)
1188 for more information\&. Note that the following capabilities will be granted in any way:
1189 \fBCAP_AUDIT_CONTROL\fR,
1190 \fBCAP_AUDIT_WRITE\fR,
1191 \fBCAP_CHOWN\fR,
1192 \fBCAP_DAC_OVERRIDE\fR,
1193 \fBCAP_DAC_READ_SEARCH\fR,
1194 \fBCAP_FOWNER\fR,
1195 \fBCAP_FSETID\fR,
1196 \fBCAP_IPC_OWNER\fR,
1197 \fBCAP_KILL\fR,
1198 \fBCAP_LEASE\fR,
1199 \fBCAP_LINUX_IMMUTABLE\fR,
1200 \fBCAP_MKNOD\fR,
1201 \fBCAP_NET_BIND_SERVICE\fR,
1202 \fBCAP_NET_BROADCAST\fR,
1203 \fBCAP_NET_RAW\fR,
1204 \fBCAP_SETFCAP\fR,
1205 \fBCAP_SETGID\fR,
1206 \fBCAP_SETPCAP\fR,
1207 \fBCAP_SETUID\fR,
1208 \fBCAP_SYS_ADMIN\fR,
1209 \fBCAP_SYS_BOOT\fR,
1210 \fBCAP_SYS_CHROOT\fR,
1211 \fBCAP_SYS_NICE\fR,
1212 \fBCAP_SYS_PTRACE\fR,
1213 \fBCAP_SYS_RESOURCE\fR,
1214 \fBCAP_SYS_TTY_CONFIG\fR\&. Also
1215 \fBCAP_NET_ADMIN\fR
1216 is retained if
1217 \fB\-\-private\-network\fR
1218 is specified\&. If the special value
1219 "all"
1220 is passed, all capabilities are retained\&.
1221 .sp
1222 If the special value of
1223 "help"
1224 is passed, the program will print known capability names and exit\&.
1225 .sp
1226 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1227 \fB\-\-ambient\-capability=\fR\&.
1228 .sp
1229 Added in version 186\&.
1230 .RE
1231 .PP
1232 \fB\-\-drop\-capability=\fR
1233 .RS 4
1234 Specify one or more additional capabilities to drop for the container\&. This allows running the container with fewer capabilities than the default (see above)\&.
1235 .sp
1236 If the special value of
1237 "help"
1238 is passed, the program will print known capability names and exit\&.
1239 .sp
1240 This option sets the bounding set of capabilities which also limits the ambient capabilities as given with the
1241 \fB\-\-ambient\-capability=\fR\&.
1242 .sp
1243 Added in version 209\&.
1244 .RE
1245 .PP
1246 \fB\-\-ambient\-capability=\fR
1247 .RS 4
1248 Specify one or more additional capabilities to pass in the inheritable and ambient set to the program started within the container\&. The value
1249 "all"
1250 is not supported for this setting\&.
1251 .sp
1252 All capabilities specified here must be in the set allowed with the
1253 \fB\-\-capability=\fR
1254 and
1255 \fB\-\-drop\-capability=\fR
1256 options\&. Otherwise, an error message will be shown\&.
1257 .sp
1258 This option cannot be combined with the boot mode of the container (as requested via
1259 \fB\-\-boot\fR)\&.
1260 .sp
1261 If the special value of
1262 "help"
1263 is passed, the program will print known capability names and exit\&.
1264 .sp
1265 Added in version 248\&.
1266 .RE
1267 .PP
1268 \fB\-\-no\-new\-privileges=\fR
1269 .RS 4
1270 Takes a boolean argument\&. Specifies the value of the
1271 \fBPR_SET_NO_NEW_PRIVS\fR
1272 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
1273 \fBprctl\fR(2)
1274 for details about this flag\&.
1275 .sp
1276 Added in version 239\&.
1277 .RE
1278 .PP
1279 \fB\-\-system\-call\-filter=\fR
1280 .RS 4
1281 Alter the system call filter applied to containers\&. Takes a space\-separated list of system call names or group names (the latter prefixed with
1282 "@", as listed by the
1283 \fBsyscall\-filter\fR
1284 command of
1285 \fBsystemd-analyze\fR(1))\&. Passed system calls will be permitted\&. The list may optionally be prefixed by
1286 "~", 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
1287 "~"
1288 prefix) are configured, the negative list takes precedence over the positive list\&. Note that
1289 \fBsystemd\-nspawn\fR
1290 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
1291 "~"
1292 prefix\&. Note that the applied system call filter is also altered implicitly if additional capabilities are passed using the
1293 \fB\-\-capabilities=\fR\&.
1294 .sp
1295 Added in version 235\&.
1296 .RE
1297 .PP
1298 \fB\-Z\fR, \fB\-\-selinux\-context=\fR
1299 .RS 4
1300 Sets the SELinux security context to be used to label processes in the container\&.
1301 .sp
1302 Added in version 209\&.
1303 .RE
1304 .PP
1305 \fB\-L\fR, \fB\-\-selinux\-apifs\-context=\fR
1306 .RS 4
1307 Sets the SELinux security context to be used to label files in the virtual API file systems in the container\&.
1308 .sp
1309 Added in version 209\&.
1310 .RE
1311 .SS "Resource Options"
1312 .PP
1313 \fB\-\-rlimit=\fR
1314 .RS 4
1315 Sets the specified POSIX resource limit for the container payload\&. Expects an assignment of the form
1316 "\fILIMIT\fR=\fISOFT\fR:\fIHARD\fR"
1317 or
1318 "\fILIMIT\fR=\fIVALUE\fR", where
1319 \fILIMIT\fR
1320 should refer to a resource limit type, such as
1321 \fBRLIMIT_NOFILE\fR
1322 or
1323 \fBRLIMIT_NICE\fR\&. The
1324 \fISOFT\fR
1325 and
1326 \fIHARD\fR
1327 fields should refer to the numeric soft and hard resource limit values\&. If the second form is used,
1328 \fIVALUE\fR
1329 may specify a value that is used both as soft and hard limit\&. In place of a numeric value the special string
1330 "infinity"
1331 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
1332 \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
1333 \fBRLIMIT_NPROC\fR\&. This means that unless user namespacing is deployed (i\&.e\&.
1334 \fB\-\-private\-users=\fR
1335 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:
1336 "\-\-rlimit=RLIMIT_NOFILE=8192:16384"\&.
1337 .sp
1338 Added in version 239\&.
1339 .RE
1340 .PP
1341 \fB\-\-oom\-score\-adjust=\fR
1342 .RS 4
1343 Changes the OOM ("Out Of Memory") score adjustment value for the container payload\&. This controls
1344 /proc/self/oom_score_adj
1345 which influences the preference with which this container is terminated when memory becomes scarce\&. For details see
1346 \fBproc\fR(5)\&. Takes an integer in the range \-1000\&...1000\&.
1347 .sp
1348 Added in version 239\&.
1349 .RE
1350 .PP
1351 \fB\-\-cpu\-affinity=\fR
1352 .RS 4
1353 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
1354 \fBsched_setaffinity\fR(2)
1355 for details\&.
1356 .sp
1357 Added in version 239\&.
1358 .RE
1359 .PP
1360 \fB\-\-personality=\fR
1361 .RS 4
1362 Control the architecture ("personality") reported by
1363 \fBuname\fR(2)
1364 in the container\&. Currently, only
1365 "x86"
1366 and
1367 "x86\-64"
1368 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\&.
1369 .sp
1370 Added in version 209\&.
1371 .RE
1372 .SS "Integration Options"
1373 .PP
1374 \fB\-\-resolv\-conf=\fR
1375 .RS 4
1376 Configures how
1377 /etc/resolv\&.conf
1378 inside of the container shall be handled (i\&.e\&. DNS configuration synchronization from host to container)\&. Takes one of
1379 "off",
1380 "copy\-host",
1381 "copy\-static",
1382 "copy\-uplink",
1383 "copy\-stub",
1384 "replace\-host",
1385 "replace\-static",
1386 "replace\-uplink",
1387 "replace\-stub",
1388 "bind\-host",
1389 "bind\-static",
1390 "bind\-uplink",
1391 "bind\-stub",
1392 "delete"
1393 or
1394 "auto"\&.
1395 .sp
1396 If set to
1397 "off"
1398 the
1399 /etc/resolv\&.conf
1400 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&.
1401 .sp
1402 If set to
1403 "copy\-host", the
1404 /etc/resolv\&.conf
1405 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
1406 "replace\-host"
1407 is used the file is copied, replacing any existing inode, including symlinks\&. Similarly, if
1408 "bind\-host"
1409 is used, the file is bind mounted from the host into the container\&.
1410 .sp
1411 If set to
1412 "copy\-static",
1413 "replace\-static"
1414 or
1415 "bind\-static"
1416 the static
1417 resolv\&.conf
1418 file supplied with
1419 \fBsystemd-resolved.service\fR(8)
1420 (specifically:
1421 /usr/lib/systemd/resolv\&.conf) is copied or bind mounted into the container\&.
1422 .sp
1423 If set to
1424 "copy\-uplink",
1425 "replace\-uplink"
1426 or
1427 "bind\-uplink"
1428 the uplink
1429 resolv\&.conf
1430 file managed by
1431 systemd\-resolved\&.service
1432 (specifically:
1433 /run/systemd/resolve/resolv\&.conf) is copied or bind mounted into the container\&.
1434 .sp
1435 If set to
1436 "copy\-stub",
1437 "replace\-stub"
1438 or
1439 "bind\-stub"
1440 the stub
1441 resolv\&.conf
1442 file managed by
1443 systemd\-resolved\&.service
1444 (specifically:
1445 /run/systemd/resolve/stub\-resolv\&.conf) is copied or bind mounted into the container\&.
1446 .sp
1447 If set to
1448 "delete"
1449 the
1450 /etc/resolv\&.conf
1451 file in the container is deleted if it exists\&.
1452 .sp
1453 Finally, if set to
1454 "auto"
1455 the file is left as it is if private networking is turned on (see
1456 \fB\-\-private\-network\fR)\&. Otherwise, if
1457 systemd\-resolved\&.service
1458 is running its stub
1459 resolv\&.conf
1460 file is used, and if not the host\*(Aqs
1461 /etc/resolv\&.conf
1462 file\&. In the latter cases the file is copied if the image is writable, and bind mounted otherwise\&.
1463 .sp
1464 It\*(Aqs recommended to use
1465 "copy\-\&..."
1466 or
1467 "replace\-\&..."
1468 if the container shall be able to make changes to the DNS configuration on its own, deviating from the host\*(Aqs settings\&. Otherwise,
1469 "bind"
1470 is preferable, as it means direct changes to
1471 /etc/resolv\&.conf
1472 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
1473 "auto"\&.
1474 .sp
1475 Added in version 239\&.
1476 .RE
1477 .PP
1478 \fB\-\-timezone=\fR
1479 .RS 4
1480 Configures how
1481 /etc/localtime
1482 inside of the container (i\&.e\&. local timezone synchronization from host to container) shall be handled\&. Takes one of
1483 "off",
1484 "copy",
1485 "bind",
1486 "symlink",
1487 "delete"
1488 or
1489 "auto"\&. If set to
1490 "off"
1491 the
1492 /etc/localtime
1493 file in the container is left as it is included in the image, and neither modified nor bind mounted over\&. If set to
1494 "copy"
1495 the
1496 /etc/localtime
1497 file of the host is copied into the container\&. Similarly, if
1498 "bind"
1499 is used, the file is bind mounted from the host into the container\&. If set to
1500 "symlink", a symlink is created pointing from
1501 /etc/localtime
1502 in the container to the timezone file in the container that matches the timezone setting on the host\&. If set to
1503 "delete", the file in the container is deleted, should it exist\&. If set to
1504 "auto"
1505 and the
1506 /etc/localtime
1507 file of the host is a symlink, then
1508 "symlink"
1509 mode is used, and
1510 "copy"
1511 otherwise, except if the image is read\-only in which case
1512 "bind"
1513 is used instead\&. Defaults to
1514 "auto"\&.
1515 .sp
1516 Added in version 239\&.
1517 .RE
1518 .PP
1519 \fB\-\-link\-journal=\fR
1520 .RS 4
1521 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
1522 "no",
1523 "host",
1524 "try\-host",
1525 "guest",
1526 "try\-guest",
1527 "auto"\&. If
1528 "no", the journal is not linked\&. If
1529 "host", the journal files are stored on the host file system (beneath
1530 /var/log/journal/\fImachine\-id\fR) and the subdirectory is bind\-mounted into the container at the same location\&. If
1531 "guest", the journal files are stored on the guest file system (beneath
1532 /var/log/journal/\fImachine\-id\fR) and the subdirectory is symlinked into the host at the same location\&.
1533 "try\-host"
1534 and
1535 "try\-guest"
1536 do the same but do not fail if the host does not have persistent journaling enabled, or if the container is in the
1537 \fB\-\-ephemeral\fR
1538 mode\&. If
1539 "auto"
1540 (the default), and the right subdirectory of
1541 /var/log/journal
1542 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
1543 "guest"
1544 or
1545 "host"
1546 will link the journal persistently if further on the default of
1547 "auto"
1548 is used\&.
1549 .sp
1550 Note that
1551 \fB\-\-link\-journal=try\-guest\fR
1552 is the default if the
1553 systemd\-nspawn@\&.service
1554 template unit file is used\&.
1555 .sp
1556 Added in version 187\&.
1557 .RE
1558 .PP
1559 \fB\-j\fR
1560 .RS 4
1561 Equivalent to
1562 \fB\-\-link\-journal=try\-guest\fR\&.
1563 .sp
1564 Added in version 187\&.
1565 .RE
1566 .SS "Mount Options"
1567 .PP
1568 \fB\-\-bind=\fR, \fB\-\-bind\-ro=\fR
1569 .RS 4
1570 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
1571 "+"
1572 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
1573 /var/tmp/
1574 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
1575 \fB\-\-bind\-ro=\fR
1576 option creates read\-only bind mounts\&. Backslash escapes are interpreted, so
1577 "\e:"
1578 may be used to embed colons in either path\&. This option may be specified multiple times for creating multiple independent bind mount points\&.
1579 .sp
1580 Mount options are comma\-separated\&.
1581 \fBrbind\fR
1582 and
1583 \fBnorbind\fR
1584 control whether to create a recursive or a regular bind mount\&. Defaults to
1585 \fBrbind\fR\&.
1586 \fBnoidmap\fR,
1587 \fBidmap\fR,
1588 \fBrootidmap\fR
1589 and
1590 \fBowneridmap\fR
1591 control ID mapping\&.
1592 .sp
1593 Using
1594 \fBidmap\fR,
1595 \fBrootidmap\fR
1596 or
1597 \fBowneridmap\fR
1598 requires support by the source filesystem for user/group ID mapped mounts\&. Defaults to
1599 \fBnoidmap\fR\&. With
1600 \fBx\fR
1601 being the container\*(Aqs UID range offset,
1602 \fBy\fR
1603 being the length of the container\*(Aqs UID range, and
1604 \fBp\fR
1605 being the owner UID of the bind mount source inode on the host:
1606 .sp
1607 .RS 4
1608 .ie n \{\
1609 \h'-04'\(bu\h'+03'\c
1610 .\}
1611 .el \{\
1612 .sp -1
1613 .IP \(bu 2.3
1614 .\}
1615 If
1616 \fBnoidmap\fR
1617 is used, any user
1618 \fBz\fR
1619 in the range
1620 \fB0 \&... y\fR
1621 seen from inside of the container is mapped to
1622 \fBx + z\fR
1623 in the
1624 \fBx \&... x + y\fR
1625 range on the host\&. Other host users are mapped to
1626 \fBnobody\fR
1627 inside the container\&.
1628 .RE
1629 .sp
1630 .RS 4
1631 .ie n \{\
1632 \h'-04'\(bu\h'+03'\c
1633 .\}
1634 .el \{\
1635 .sp -1
1636 .IP \(bu 2.3
1637 .\}
1638 If
1639 \fBidmap\fR
1640 is used, any user
1641 \fBz\fR
1642 in the UID range
1643 \fB0 \&... y\fR
1644 as seen from inside the container is mapped to the same
1645 \fBz\fR
1646 in the same
1647 \fB0 \&... y\fR
1648 range on the host\&. Other host users are mapped to
1649 \fBnobody\fR
1650 inside the container\&.
1651 .RE
1652 .sp
1653 .RS 4
1654 .ie n \{\
1655 \h'-04'\(bu\h'+03'\c
1656 .\}
1657 .el \{\
1658 .sp -1
1659 .IP \(bu 2.3
1660 .\}
1661 If
1662 \fBrootidmap\fR
1663 is used, the user
1664 \fB0\fR
1665 seen from inside of the container is mapped to
1666 \fBp\fR
1667 on the host\&. Other host users are mapped to
1668 \fBnobody\fR
1669 inside the container\&.
1670 .RE
1671 .sp
1672 .RS 4
1673 .ie n \{\
1674 \h'-04'\(bu\h'+03'\c
1675 .\}
1676 .el \{\
1677 .sp -1
1678 .IP \(bu 2.3
1679 .\}
1680 If
1681 \fBowneridmap\fR
1682 is used, the owner of the target directory inside of the container is mapped to
1683 \fBp\fR
1684 on the host\&. Other host users are mapped to
1685 \fBnobody\fR
1686 inside the container\&.
1687 .RE
1688 .sp
1689 Whichever ID mapping option is used, the same mapping will be used for users and groups IDs\&. If
1690 \fBrootidmap\fR
1691 or
1692 \fBowneridmap\fR
1693 are used, the group owning the bind mounted directory will have no effect\&.
1694 .sp
1695 Note that when this option is used in combination with
1696 \fB\-\-private\-users\fR, the resulting mount points will be owned by the
1697 \fBnobody\fR
1698 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
1699 \fB\-\-bind\-ro=\fR\&. Alternatively you can use the "idmap" mount option to map the filesystem IDs\&.
1700 .sp
1701 Added in version 198\&.
1702 .RE
1703 .PP
1704 \fB\-\-bind\-user=\fR
1705 .RS 4
1706 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:
1707 .sp
1708 .RS 4
1709 .ie n \{\
1710 \h'-04' 1.\h'+01'\c
1711 .\}
1712 .el \{\
1713 .sp -1
1714 .IP " 1." 4.2
1715 .\}
1716 The user\*(Aqs home directory is bind mounted from the host into
1717 /run/host/home/\&.
1718 .RE
1719 .sp
1720 .RS 4
1721 .ie n \{\
1722 \h'-04' 2.\h'+01'\c
1723 .\}
1724 .el \{\
1725 .sp -1
1726 .IP " 2." 4.2
1727 .\}
1728 An additional UID/GID mapping is added that maps the host user\*(Aqs UID/GID to a container UID/GID, allocated from the 60514\&...60577 range\&.
1729 .RE
1730 .sp
1731 .RS 4
1732 .ie n \{\
1733 \h'-04' 3.\h'+01'\c
1734 .\}
1735 .el \{\
1736 .sp -1
1737 .IP " 3." 4.2
1738 .\}
1739 A JSON user and group record is generated in
1740 /run/userdb/
1741 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
1742 \fBnss-systemd\fR(8)
1743 glibc NSS module will pick up these records from there and make them available in the container\*(Aqs user/group databases\&.
1744 .RE
1745 .sp
1746 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
1747 \fB\-\-bind\-user=\fR
1748 mapping), those files and directories will be accessible to the "new" user\&.
1749 .sp
1750 The user/group record mapping only works if the container contains systemd 249 or newer, with
1751 \fBnss\-systemd\fR
1752 properly configured in
1753 nsswitch\&.conf\&. See
1754 \fBnss-systemd\fR(8)
1755 for details\&.
1756 .sp
1757 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
1758 "$y$"
1759 hash prefix)\&.
1760 .sp
1761 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
1762 /etc/passwd
1763 and
1764 /etc/group, and thus might not detect existing accounts in other databases\&.
1765 .sp
1766 This operation is only supported in combination with
1767 \fB\-\-private\-users=\fR/\fB\-U\fR\&.
1768 .sp
1769 Added in version 249\&.
1770 .RE
1771 .PP
1772 \fB\-\-inaccessible=\fR
1773 .RS 4
1774 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\&.
1775 .sp
1776 Added in version 242\&.
1777 .RE
1778 .PP
1779 \fB\-\-tmpfs=\fR
1780 .RS 4
1781 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
1782 "\e:"
1783 may be used to embed colons in the path\&.
1784 .sp
1785 Note that this option cannot be used to replace the root file system of the container with a temporary file system\&. However, the
1786 \fB\-\-volatile=\fR
1787 option described below provides similar functionality, with a focus on implementing stateless operating system images\&.
1788 .sp
1789 Added in version 214\&.
1790 .RE
1791 .PP
1792 \fB\-\-overlay=\fR, \fB\-\-overlay\-ro=\fR
1793 .RS 4
1794 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\&.
1795 .sp
1796 Backslash escapes are interpreted in the paths, so
1797 "\e:"
1798 may be used to embed colons in the paths\&.
1799 .sp
1800 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
1801 \fB\-\-overlay\-ro=\fR
1802 is used instead of
1803 \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\&.
1804 .sp
1805 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\&.
1806 .sp
1807 The source paths may optionally be prefixed with
1808 "+"
1809 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
1810 /var/tmp/
1811 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
1812 "\-\-overlay=+/var::/var"
1813 in order to automatically overlay a writable temporary directory on a read\-only
1814 /var/
1815 directory\&. If a source path is not absolute, it is resolved relative to the current working directory\&.
1816 .sp
1817 For details about overlay file systems, see
1818 \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
1819 "workdir="
1820 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
1821 "lowerdir="
1822 mount option receives the paths to stack in the opposite order of this switch\&.
1823 .sp
1824 Note that this option cannot be used to replace the root file system of the container with an overlay file system\&. However, the
1825 \fB\-\-volatile=\fR
1826 option described above provides similar functionality, with a focus on implementing stateless operating system images\&.
1827 .sp
1828 Added in version 220\&.
1829 .RE
1830 .SS "Input/Output Options"
1831 .PP
1832 \fB\-\-console=\fR\fB\fIMODE\fR\fR
1833 .RS 4
1834 Configures how to set up standard input, output and error output for the container payload, as well as the
1835 /dev/console
1836 device for the container\&. Takes one of
1837 \fBinteractive\fR,
1838 \fBread\-only\fR,
1839 \fBpassive\fR,
1840 \fBpipe\fR
1841 or
1842 \fBautopipe\fR\&. If
1843 \fBinteractive\fR, a pseudo\-TTY is allocated and made available as
1844 /dev/console
1845 in the container\&. It is then bi\-directionally connected to the standard input and output passed to
1846 \fBsystemd\-nspawn\fR\&.
1847 \fBread\-only\fR
1848 is similar but only the output of the container is propagated and no input from the caller is read\&. If
1849 \fBpassive\fR, a pseudo TTY is allocated, but it is not connected anywhere\&. In
1850 \fBpipe\fR
1851 mode no pseudo TTY is allocated, but the standard input, output and error output file descriptors passed to
1852 \fBsystemd\-nspawn\fR
1853 are passed on \(em as they are \(em to the container payload, see the following paragraph\&. Finally,
1854 \fBautopipe\fR
1855 mode operates like
1856 \fBinteractive\fR
1857 when
1858 \fBsystemd\-nspawn\fR
1859 is invoked on a terminal, and like
1860 \fBpipe\fR
1861 otherwise\&. Defaults to
1862 \fBinteractive\fR
1863 if
1864 \fBsystemd\-nspawn\fR
1865 is invoked from a terminal, and
1866 \fBread\-only\fR
1867 otherwise\&.
1868 .sp
1869 In
1870 \fBpipe\fR
1871 mode,
1872 /dev/console
1873 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
1874 /dev/console
1875 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\&.
1876 \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
1877 \fBTIOCSTI\fR
1878 may be used to synthesize input that might be used for escaping the container\&. Hence
1879 \fBpipe\fR
1880 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\&.
1881 .sp
1882 Added in version 242\&.
1883 .RE
1884 .PP
1885 \fB\-\-pipe\fR, \fB\-P\fR
1886 .RS 4
1887 Equivalent to
1888 \fB\-\-console=pipe\fR\&.
1889 .sp
1890 Added in version 242\&.
1891 .RE
1892 .PP
1893 \fB\-\-background=\fR\fB\fICOLOR\fR\fR
1894 .RS 4
1895 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
1896 "40",
1897 "41", \&...,
1898 "47",
1899 "48;2;\&...",
1900 "48;5;\&..."\&. See
1901 \m[blue]\fBANSI Escape Code (Wikipedia)\fR\m[]\&\s-2\u[6]\d\s+2
1902 for details\&. Assign an empty string to disable any coloring\&.
1903 .sp
1904 Added in version 256\&.
1905 .RE
1906 .SS "Credentials"
1907 .PP
1908 \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
1909 .RS 4
1910 Pass a credential to the container\&. These two options correspond to the
1911 \fILoadCredential=\fR
1912 and
1913 \fISetCredential=\fR
1914 settings in unit files\&. See
1915 \fBsystemd.exec\fR(5)
1916 for details about these concepts, as well as the syntax of the option\*(Aqs arguments\&.
1917 .sp
1918 Note: when
1919 \fBsystemd\-nspawn\fR
1920 runs as systemd system service it can propagate the credentials it received via
1921 \fILoadCredential=\fR/\fISetCredential=\fR
1922 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\&.
1923 .sp
1924 In order to embed binary data into the credential data for
1925 \fB\-\-set\-credential=\fR, use C\-style escaping (i\&.e\&.
1926 "\en"
1927 to embed a newline, or
1928 "\ex00"
1929 to embed a
1930 \fBNUL\fR
1931 byte)\&. Note that the invoking shell might already apply unescaping once, hence this might require double escaping!
1932 .sp
1933 The
1934 \fBsystemd-sysusers.service\fR(8)
1935 and
1936 \fBsystemd-firstboot\fR(1)
1937 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
1938 \fB\-\-volatile=yes\fR
1939 where every single boot appears as first boot, since configuration applied to
1940 /etc/
1941 is lost on container reboot cycles\&. See the respective man pages for details\&. Example:
1942 .sp
1943 .if n \{\
1944 .RS 4
1945 .\}
1946 .nf
1947 # systemd\-nspawn \-i image\&.raw \e
1948 \-\-volatile=yes \e
1949 \-\-set\-credential=firstboot\&.locale:de_DE\&.UTF\-8 \e
1950 \-\-set\-credential=passwd\&.hashed\-password\&.root:\*(Aq$y$j9T$yAuRJu1o5HioZAGDYPU5d\&.$F64ni6J2y2nNQve90M/p0ZP0ECP/qqzipNyaY9fjGpC\*(Aq \e
1951 \-b
1952 .fi
1953 .if n \{\
1954 .RE
1955 .\}
1956 .sp
1957 The above command line will invoke the specified image file
1958 image\&.raw
1959 in volatile mode, i\&.e\&. with empty
1960 /etc/
1961 and
1962 /var/\&. The container payload will recognize this as a first boot, and will invoke
1963 systemd\-firstboot\&.service, which then reads the two passed credentials to configure the system\*(Aqs initial locale and root password\&.
1964 .sp
1965 Added in version 247\&.
1966 .RE
1967 .SS "Other"
1968 .PP
1969 \fB\-\-no\-pager\fR
1970 .RS 4
1971 Do not pipe output into a pager\&.
1972 .RE
1973 .PP
1974 \fB\-h\fR, \fB\-\-help\fR
1975 .RS 4
1976 Print a short help text and exit\&.
1977 .RE
1978 .PP
1979 \fB\-\-version\fR
1980 .RS 4
1981 Print a short version string and exit\&.
1982 .RE
1983 .SH "ENVIRONMENT"
1984 .PP
1985 \fI$SYSTEMD_LOG_LEVEL\fR
1986 .RS 4
1987 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)
1988 \fBemerg\fR,
1989 \fBalert\fR,
1990 \fBcrit\fR,
1991 \fBerr\fR,
1992 \fBwarning\fR,
1993 \fBnotice\fR,
1994 \fBinfo\fR,
1995 \fBdebug\fR, or an integer in the range 0\&...7\&. See
1996 \fBsyslog\fR(3)
1997 for more information\&. Each value may optionally be prefixed with one of
1998 \fBconsole\fR,
1999 \fBsyslog\fR,
2000 \fBkmsg\fR
2001 or
2002 \fBjournal\fR
2003 followed by a colon to set the maximum log level for that specific log target (e\&.g\&.
2004 \fBSYSTEMD_LOG_LEVEL=debug,console:info\fR
2005 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\&.
2006 .RE
2007 .PP
2008 \fI$SYSTEMD_LOG_COLOR\fR
2009 .RS 4
2010 A boolean\&. If true, messages written to the tty will be colored according to priority\&.
2011 .sp
2012 This setting is only useful when messages are written directly to the terminal, because
2013 \fBjournalctl\fR(1)
2014 and other tools that display logs will color messages based on the log level on their own\&.
2015 .RE
2016 .PP
2017 \fI$SYSTEMD_LOG_TIME\fR
2018 .RS 4
2019 A boolean\&. If true, console log messages will be prefixed with a timestamp\&.
2020 .sp
2021 This setting is only useful when messages are written directly to the terminal or a file, because
2022 \fBjournalctl\fR(1)
2023 and other tools that display logs will attach timestamps based on the entry metadata on their own\&.
2024 .RE
2025 .PP
2026 \fI$SYSTEMD_LOG_LOCATION\fR
2027 .RS 4
2028 A boolean\&. If true, messages will be prefixed with a filename and line number in the source code where the message originates\&.
2029 .sp
2030 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\&.
2031 .RE
2032 .PP
2033 \fI$SYSTEMD_LOG_TID\fR
2034 .RS 4
2035 A boolean\&. If true, messages will be prefixed with the current numerical thread ID (TID)\&.
2036 .sp
2037 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\&.
2038 .RE
2039 .PP
2040 \fI$SYSTEMD_LOG_TARGET\fR
2041 .RS 4
2042 The destination for log messages\&. One of
2043 \fBconsole\fR
2044 (log to the attached tty),
2045 \fBconsole\-prefixed\fR
2046 (log to the attached tty but with prefixes encoding the log level and "facility", see
2047 \fBsyslog\fR(3),
2048 \fBkmsg\fR
2049 (log to the kernel circular log buffer),
2050 \fBjournal\fR
2051 (log to the journal),
2052 \fBjournal\-or\-kmsg\fR
2053 (log to the journal if available, and to kmsg otherwise),
2054 \fBauto\fR
2055 (determine the appropriate log target automatically, the default),
2056 \fBnull\fR
2057 (disable log output)\&.
2058 .RE
2059 .PP
2060 \fI$SYSTEMD_LOG_RATELIMIT_KMSG\fR
2061 .RS 4
2062 Whether to ratelimit kmsg or not\&. Takes a boolean\&. Defaults to
2063 "true"\&. If disabled, systemd will not ratelimit messages written to kmsg\&.
2064 .RE
2065 .PP
2066 \fI$SYSTEMD_PAGER\fR, \fI$PAGER\fR
2067 .RS 4
2068 Pager to use when
2069 \fB\-\-no\-pager\fR
2070 is not given\&.
2071 \fI$SYSTEMD_PAGER\fR
2072 is used if set; otherwise
2073 \fI$PAGER\fR
2074 is used\&. If neither
2075 \fI$SYSTEMD_PAGER\fR
2076 nor
2077 \fI$PAGER\fR
2078 are set, a set of well\-known pager implementations is tried in turn, including
2079 \fBless\fR(1)
2080 and
2081 \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
2082 "cat"
2083 is equivalent to passing
2084 \fB\-\-no\-pager\fR\&.
2085 .sp
2086 Note: if
2087 \fI$SYSTEMD_PAGERSECURE\fR
2088 is not set,
2089 \fI$SYSTEMD_PAGER\fR
2090 and
2091 \fI$PAGER\fR
2092 can only be used to disable the pager (with
2093 "cat"
2094 or
2095 ""), and are otherwise ignored\&.
2096 .RE
2097 .PP
2098 \fI$SYSTEMD_LESS\fR
2099 .RS 4
2100 Override the options passed to
2101 \fBless\fR
2102 (by default
2103 "FRSXMK")\&.
2104 .sp
2105 Users might want to change two options in particular:
2106 .PP
2107 \fBK\fR
2108 .RS 4
2109 This option instructs the pager to exit immediately when
2110 Ctrl+C
2111 is pressed\&. To allow
2112 \fBless\fR
2113 to handle
2114 Ctrl+C
2115 itself to switch back to the pager command prompt, unset this option\&.
2116 .sp
2117 If the value of
2118 \fI$SYSTEMD_LESS\fR
2119 does not include
2120 "K", and the pager that is invoked is
2121 \fBless\fR,
2122 Ctrl+C
2123 will be ignored by the executable, and needs to be handled by the pager\&.
2124 .RE
2125 .PP
2126 \fBX\fR
2127 .RS 4
2128 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\&.
2129 .RE
2130 .sp
2131 Note that setting the regular
2132 \fI$LESS\fR
2133 environment variable has no effect for
2134 \fBless\fR
2135 invocations by systemd tools\&.
2136 .sp
2137 See
2138 \fBless\fR(1)
2139 for more discussion\&.
2140 .RE
2141 .PP
2142 \fI$SYSTEMD_LESSCHARSET\fR
2143 .RS 4
2144 Override the charset passed to
2145 \fBless\fR
2146 (by default
2147 "utf\-8", if the invoking terminal is determined to be UTF\-8 compatible)\&.
2148 .sp
2149 Note that setting the regular
2150 \fI$LESSCHARSET\fR
2151 environment variable has no effect for
2152 \fBless\fR
2153 invocations by systemd tools\&.
2154 .RE
2155 .PP
2156 \fI$SYSTEMD_PAGERSECURE\fR
2157 .RS 4
2158 Common pager commands like
2159 \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
2160 \fBsudo\fR(8)
2161 or
2162 \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,
2163 \fIif the pager supports that\fR
2164 (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
2165 \fB\-\-no\-pager\fR
2166 or
2167 \fIPAGER=cat\fR
2168 when allowing untrusted users to execute commands with elevated privileges\&.
2169 .sp
2170 This option takes a boolean argument\&. When set to true, the "secure mode" of the pager is enabled\&. In "secure mode",
2171 \fBLESSSECURE=1\fR
2172 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
2173 \fBless\fR(1)
2174 is known to understand this variable and implement "secure mode"\&.
2175 .sp
2176 When set to false, no limitation is placed on the pager\&. Setting
2177 \fISYSTEMD_PAGERSECURE=0\fR
2178 or not removing it from the inherited environment may allow the user to invoke arbitrary commands\&.
2179 .sp
2180 When
2181 \fI$SYSTEMD_PAGERSECURE\fR
2182 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
2183 \fBgeteuid\fR(2)
2184 and
2185 \fBsd_pid_get_owner_uid\fR(3), or when running under
2186 \fBsudo\fR(8)
2187 or similar tools (\fI$SUDO_UID\fR
2188 is set
2189 \&\s-2\u[7]\d\s+2)\&. In those cases,
2190 \fISYSTEMD_PAGERSECURE=1\fR
2191 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
2192 \fI$SYSTEMD_PAGERSECURE\fR
2193 or disable the pager\&.
2194 .sp
2195 Note that if the
2196 \fI$SYSTEMD_PAGER\fR
2197 or
2198 \fI$PAGER\fR
2199 variables are to be honoured, other than to disable the pager,
2200 \fI$SYSTEMD_PAGERSECURE\fR
2201 must be set too\&.
2202 .RE
2203 .PP
2204 \fI$SYSTEMD_COLORS\fR
2205 .RS 4
2206 Takes a boolean argument\&. When true,
2207 \fBsystemd\fR
2208 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:
2209 "16",
2210 "256"
2211 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
2212 \fI$TERM\fR
2213 and what the console is connected to\&.
2214 .RE
2215 .PP
2216 \fI$SYSTEMD_URLIFY\fR
2217 .RS 4
2218 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
2219 \fBsystemd\fR
2220 makes based on
2221 \fI$TERM\fR
2222 and other conditions\&.
2223 .RE
2224 .SH "EXAMPLES"
2225 .PP
2226 \fBExample\ \&1.\ \&Download an Ubuntu TAR image and open a shell in it\fR
2227 .sp
2228 .if n \{\
2229 .RS 4
2230 .\}
2231 .nf
2232 # importctl pull\-tar \-mN https://cloud\-images\&.ubuntu\&.com/jammy/current/jammy\-server\-cloudimg\-amd64\-root\&.tar\&.xz
2233 # systemd\-nspawn \-M jammy\-server\-cloudimg\-amd64\-root
2234 .fi
2235 .if n \{\
2236 .RE
2237 .\}
2238 .PP
2239 This downloads and verifies the specified
2240 \&.tar
2241 image, and then uses
2242 \fBsystemd-nspawn\fR(1)
2243 to open a shell in it\&.
2244 .PP
2245 \fBExample\ \&2.\ \&Build and boot a minimal Fedora distribution in a container\fR
2246 .sp
2247 .if n \{\
2248 .RS 4
2249 .\}
2250 .nf
2251 # dnf \-y \-\-releasever=43 \-\-installroot=/var/lib/machines/f43 \e
2252 \-\-use\-host\-config \-\-setopt=install_weak_deps=0 \e
2253 \-\-repo=fedora \-\-repo=updates install \e
2254 passwd dnf fedora\-release nano util\-linux systemd systemd\-networkd
2255 # systemd\-nspawn \-bD /var/lib/machines/f43
2256 .fi
2257 .if n \{\
2258 .RE
2259 .\}
2260 .PP
2261 (Omit
2262 \fI\-\-use\-host\-config\fR
2263 when using
2264 \fBdnf\fR
2265 <= 4\&.) This installs a minimal Fedora distribution into the directory
2266 /var/lib/machines/f43
2267 and then boots that OS in a namespace container\&. Because the installation is located underneath the standard
2268 /var/lib/machines/
2269 directory, it is also possible to start the machine using
2270 \fBsystemd\-nspawn \-M f43\fR\&.
2271 .PP
2272 \fBExample\ \&3.\ \&Spawn a shell in a container of a minimal Debian unstable distribution\fR
2273 .sp
2274 .if n \{\
2275 .RS 4
2276 .\}
2277 .nf
2278 # debootstrap unstable ~/debian\-tree/
2279 # systemd\-nspawn \-D ~/debian\-tree/
2280 .fi
2281 .if n \{\
2282 .RE
2283 .\}
2284 .PP
2285 This installs a minimal Debian unstable distribution into the directory
2286 ~/debian\-tree/
2287 and then spawns a shell from this image in a namespace container\&.
2288 .PP
2289 \fBdebootstrap\fR
2290 supports
2291 \m[blue]\fBDebian\fR\m[]\&\s-2\u[8]\d\s+2, and
2292 \m[blue]\fBUbuntu\fR\m[]\&\s-2\u[9]\d\s+2
2293 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
2294 \fBdebootstrap\fR(8)\&.
2295 .PP
2296 \fBExample\ \&4.\ \&Boot a minimal Arch Linux distribution in a container\fR
2297 .sp
2298 .if n \{\
2299 .RS 4
2300 .\}
2301 .nf
2302 # pacstrap \-c ~/arch\-tree/ base
2303 # systemd\-nspawn \-bD ~/arch\-tree/
2304 .fi
2305 .if n \{\
2306 .RE
2307 .\}
2308 .PP
2309 This installs a minimal Arch Linux distribution into the directory
2310 ~/arch\-tree/
2311 and then boots an OS in a namespace container in it\&.
2312 .PP
2313 \fBExample\ \&5.\ \&Install the OpenSUSE Tumbleweed rolling distribution\fR
2314 .sp
2315 .if n \{\
2316 .RS 4
2317 .\}
2318 .nf
2319 # zypper \-\-root=/var/lib/machines/tumbleweed ar \-c \e
2320 https://download\&.opensuse\&.org/tumbleweed/repo/oss tumbleweed
2321 # zypper \-\-root=/var/lib/machines/tumbleweed refresh
2322 # zypper \-\-root=/var/lib/machines/tumbleweed install \-\-no\-recommends \e
2323 systemd shadow zypper openSUSE\-release vim
2324 # systemd\-nspawn \-M tumbleweed passwd root
2325 # systemd\-nspawn \-M tumbleweed \-b
2326 .fi
2327 .if n \{\
2328 .RE
2329 .\}
2330 .PP
2331 \fBExample\ \&6.\ \&Boot into an ephemeral snapshot of the host system\fR
2332 .sp
2333 .if n \{\
2334 .RS 4
2335 .\}
2336 .nf
2337 # systemd\-nspawn \-D / \-xb
2338 .fi
2339 .if n \{\
2340 .RE
2341 .\}
2342 .PP
2343 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\&.
2344 .PP
2345 \fBExample\ \&7.\ \&Run a container with SELinux sandbox security contexts\fR
2346 .sp
2347 .if n \{\
2348 .RS 4
2349 .\}
2350 .nf
2351 # chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \-R /srv/container
2352 # systemd\-nspawn \-L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \e
2353 \-Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 \-D /srv/container /bin/sh
2354 .fi
2355 .if n \{\
2356 .RE
2357 .\}
2358 .PP
2359 \fBExample\ \&8.\ \&Run a container with an OSTree deployment\fR
2360 .sp
2361 .if n \{\
2362 .RS 4
2363 .\}
2364 .nf
2365 # systemd\-nspawn \-b \-i ~/image\&.raw \e
2366 \-\-pivot\-root=/ostree/deploy/$OS/deploy/$CHECKSUM:/sysroot \e
2367 \-\-bind=+/sysroot/ostree/deploy/$OS/var:/var
2368 .fi
2369 .if n \{\
2370 .RE
2371 .\}
2372 .SH "EXIT STATUS"
2373 .PP
2374 The exit code of the program executed in the container is returned\&.
2375 .SH "SEE ALSO"
2376 .PP
2377 \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)
2378 .SH "NOTES"
2379 .IP " 1." 4
2380 Container Interface
2381 .RS 4
2382 \%https://systemd.io/CONTAINER_INTERFACE
2383 .RE
2384 .IP " 2." 4
2385 Discoverable Partitions Specification
2386 .RS 4
2387 \%https://uapi-group.org/specifications/specs/discoverable_partitions_specification
2388 .RE
2389 .IP " 3." 4
2390 OCI Runtime Specification
2391 .RS 4
2392 \%https://github.com/opencontainers/runtime-spec/blob/master/spec.md
2393 .RE
2394 .IP " 4." 4
2395 OSTree
2396 .RS 4
2397 \%https://ostree.readthedocs.io/en/latest/
2398 .RE
2399 .IP " 5." 4
2400 Overlay Filesystem
2401 .RS 4
2402 \%https://docs.kernel.org/filesystems/overlayfs.html
2403 .RE
2404 .IP " 6." 4
2405 ANSI Escape Code (Wikipedia)
2406 .RS 4
2407 \%https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
2408 .RE
2409 .IP " 7." 4
2410 It is recommended for other tools to set and check
2411 \fI$SUDO_UID\fR
2412 as appropriate, treating it is a common interface.
2413 .IP " 8." 4
2414 Debian
2415 .RS 4
2416 \%https://www.debian.org
2417 .RE
2418 .IP " 9." 4
2419 Ubuntu
2420 .RS 4
2421 \%https://www.ubuntu.com
2422 .RE
2423 .IP "10." 4
2424 Arch Linux
2425 .RS 4
2426 \%https://www.archlinux.org
2427 .RE
2428 .IP "11." 4
2429 OpenSUSE Tumbleweed
2430 .RS 4
2431 \%https://software.opensuse.org/distributions/tumbleweed
2432 .RE