| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 4 |
<!ENTITY % entities SYSTEM "custom-entities.ent" > |
| 5 |
%entities; |
| 6 |
]> |
| 7 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 8 |
|
| 9 |
<refentry id="systemd-nspawn" conditional="ENABLE_NSPAWN" |
| 10 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 11 |
|
| 12 |
<refentryinfo> |
| 13 |
<title>systemd-nspawn</title> |
| 14 |
<productname>systemd</productname> |
| 15 |
</refentryinfo> |
| 16 |
|
| 17 |
<refmeta> |
| 18 |
<refentrytitle>systemd-nspawn</refentrytitle> |
| 19 |
<manvolnum>1</manvolnum> |
| 20 |
</refmeta> |
| 21 |
|
| 22 |
<refnamediv> |
| 23 |
<refname>systemd-nspawn</refname> |
| 24 |
<refpurpose>Spawn a command or OS in a lightweight container</refpurpose> |
| 25 |
</refnamediv> |
| 26 |
|
| 27 |
<refsynopsisdiv> |
| 28 |
<cmdsynopsis> |
| 29 |
<command>systemd-nspawn</command> |
| 30 |
<arg choice="opt" rep="repeat">OPTIONS</arg> |
| 31 |
<arg choice="opt"><replaceable>COMMAND</replaceable> |
| 32 |
<arg choice="opt" rep="repeat">ARGS</arg> |
| 33 |
</arg> |
| 34 |
</cmdsynopsis> |
| 35 |
<cmdsynopsis> |
| 36 |
<command>systemd-nspawn</command> |
| 37 |
<arg choice="plain">--boot</arg> |
| 38 |
<arg choice="opt" rep="repeat">OPTIONS</arg> |
| 39 |
<arg choice="opt" rep="repeat">ARGS</arg> |
| 40 |
</cmdsynopsis> |
| 41 |
</refsynopsisdiv> |
| 42 |
|
| 43 |
<refsect1> |
| 44 |
<title>Description</title> |
| 45 |
|
| 46 |
<para><command>systemd-nspawn</command> may be used to run a command or OS in a lightweight namespace |
| 47 |
container. In many ways it is similar to <citerefentry |
| 48 |
project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry>, but more powerful |
| 49 |
since it virtualizes the file system hierarchy, as well as the process tree, the various IPC subsystems, and |
| 50 |
the host and domain names.</para> |
| 51 |
|
| 52 |
<para><command>systemd-nspawn</command> may be invoked on any directory tree containing an operating system tree, |
| 53 |
using the <option>--directory=</option> command line option. By using the <option>--machine=</option> option an OS |
| 54 |
tree is automatically searched for in a couple of locations, most importantly in |
| 55 |
<filename>/var/lib/machines/</filename>, the suggested directory to place OS container images installed on the |
| 56 |
system.</para> |
| 57 |
|
| 58 |
<para>In contrast to <citerefentry |
| 59 |
project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry> <command>systemd-nspawn</command> |
| 60 |
may be used to boot full Linux-based operating systems in a container.</para> |
| 61 |
|
| 62 |
<para><command>systemd-nspawn</command> limits access to various kernel interfaces in the container to |
| 63 |
read-only, such as <filename>/sys/</filename>, <filename>/proc/sys/</filename>, or |
| 64 |
<filename>/sys/fs/selinux/</filename>. The host's network interfaces and the system clock may not be |
| 65 |
changed from within the container. Device nodes may not be created. The host system cannot be rebooted |
| 66 |
and kernel modules may not be loaded from within the container. <emphasis>This sandbox can easily be |
| 67 |
circumvented from within the container if user namespaces are not used</emphasis>. This means that |
| 68 |
untrusted code must always be run in a user namespace, see the discussion of the |
| 69 |
<option>--private-users=</option> option below.</para> |
| 70 |
|
| 71 |
<para>Use a tool like <citerefentry |
| 72 |
project='mankier'><refentrytitle>dnf</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry |
| 73 |
project='die-net'><refentrytitle>debootstrap</refentrytitle><manvolnum>8</manvolnum></citerefentry>, or |
| 74 |
<citerefentry project='archlinux'><refentrytitle>pacman</refentrytitle><manvolnum>8</manvolnum></citerefentry> to |
| 75 |
set up an OS directory tree suitable as file system hierarchy for <command>systemd-nspawn</command> containers. See |
| 76 |
the Examples section below for details on suitable invocation of these commands.</para> |
| 77 |
|
| 78 |
<para>As a safety check <command>systemd-nspawn</command> will verify the existence of |
| 79 |
<filename>/usr/lib/os-release</filename> or <filename>/etc/os-release</filename> in the container tree before |
| 80 |
booting a container (see |
| 81 |
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>). It might be |
| 82 |
necessary to add this file to the container tree manually if the OS of the container is too old to contain this |
| 83 |
file out-of-the-box.</para> |
| 84 |
|
| 85 |
<para><command>systemd-nspawn</command> may be invoked directly from the interactive command line or run as system |
| 86 |
service in the background. In this mode each container instance runs as its own service instance; a default |
| 87 |
template unit file <filename>[email protected]</filename> is provided to make this easy, taking the container |
| 88 |
name as instance identifier. Note that different default options apply when <command>systemd-nspawn</command> is |
| 89 |
invoked by the template unit file than interactively on the command line. Most importantly the template unit file |
| 90 |
makes use of the <option>--boot</option> option which is not the default in case <command>systemd-nspawn</command> |
| 91 |
is invoked from the interactive command line. Further differences with the defaults are documented along with the |
| 92 |
various supported options below.</para> |
| 93 |
|
| 94 |
<para>The <citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> tool may |
| 95 |
be used to execute a number of operations on containers. In particular it provides easy-to-use commands to run |
| 96 |
containers as system services using the <filename>[email protected]</filename> template unit |
| 97 |
file.</para> |
| 98 |
|
| 99 |
<para>Along with each container a settings file with the <filename>.nspawn</filename> suffix may exist, containing |
| 100 |
additional settings to apply when running the container. See |
| 101 |
<citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 102 |
details. Settings files override the default options used by the <filename>[email protected]</filename> |
| 103 |
template unit file, making it usually unnecessary to alter this template file directly.</para> |
| 104 |
|
| 105 |
<para>Note that <command>systemd-nspawn</command> will mount file systems private to the container to |
| 106 |
<filename>/dev/</filename>, <filename>/run/</filename>, and similar. These will not be visible outside of |
| 107 |
the container, and their contents will be lost when the container exits.</para> |
| 108 |
|
| 109 |
<para>Note that running two <command>systemd-nspawn</command> containers from the same directory tree will not make |
| 110 |
processes in them see each other. The PID namespace separation of the two containers is complete and the containers |
| 111 |
will share very few runtime objects except for the underlying file system. Rather use |
| 112 |
<citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 113 |
<command>login</command> or <command>shell</command> commands to request an additional login session in a running |
| 114 |
container.</para> |
| 115 |
|
| 116 |
<para><command>systemd-nspawn</command> implements the <ulink |
| 117 |
url="https://systemd.io/CONTAINER_INTERFACE">Container Interface</ulink> specification.</para> |
| 118 |
|
| 119 |
<para>While running, containers invoked with <command>systemd-nspawn</command> are registered with the |
| 120 |
<citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry> service that |
| 121 |
keeps track of running containers, and provides programming interfaces to interact with them.</para> |
| 122 |
</refsect1> |
| 123 |
|
| 124 |
<refsect1> |
| 125 |
<title>Unprivileged Operation</title> |
| 126 |
|
| 127 |
<para><command>systemd-nspawn</command> may be invoked with or without privileges. The full functionality |
| 128 |
is currently only available when invoked with privileges. When invoked without privileges, various |
| 129 |
limitations apply, including, but not limited to:</para> |
| 130 |
|
| 131 |
<itemizedlist> |
| 132 |
<listitem><para>Only disk image based containers are supported (i.e. <option>--image=</option>). |
| 133 |
Directory based ones (i.e. <option>--directory=</option>) are only supported if owned by the "foreign" |
| 134 |
UID range.</para></listitem> |
| 135 |
|
| 136 |
<listitem><para>Only <option>--private-network</option> and <option>--network-veth</option> networking |
| 137 |
modes are supported.</para></listitem> |
| 138 |
</itemizedlist> |
| 139 |
|
| 140 |
<para>When running in unprivileged mode, some needed functionality is provided via |
| 141 |
<citerefentry><refentrytitle>systemd-mountfsd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 142 |
and |
| 143 |
<citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> |
| 144 |
</refsect1> |
| 145 |
|
| 146 |
<refsect1> |
| 147 |
<title>Options</title> |
| 148 |
|
| 149 |
<para>If option <option>--boot</option> is specified, the arguments |
| 150 |
are used as arguments for the init program. Otherwise, |
| 151 |
<replaceable>COMMAND</replaceable> specifies the program to launch |
| 152 |
in the container, and the remaining arguments are used as |
| 153 |
arguments for this program. If <option>--boot</option> is not used and |
| 154 |
no arguments are specified, a shell is launched in the |
| 155 |
container.</para> |
| 156 |
|
| 157 |
<para>The following options are understood:</para> |
| 158 |
|
| 159 |
<variablelist> |
| 160 |
|
| 161 |
<varlistentry> |
| 162 |
<term><option>-q</option></term> |
| 163 |
<term><option>--quiet</option></term> |
| 164 |
|
| 165 |
<listitem><para>Turns off any status output by the tool |
| 166 |
itself. When this switch is used, the only output from nspawn |
| 167 |
will be the console output of the container OS |
| 168 |
itself.</para> |
| 169 |
|
| 170 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 171 |
</varlistentry> |
| 172 |
|
| 173 |
<varlistentry> |
| 174 |
<term><option>--settings=<replaceable>MODE</replaceable></option></term> |
| 175 |
|
| 176 |
<listitem><para>Controls whether |
| 177 |
<command>systemd-nspawn</command> shall search for and use |
| 178 |
additional per-container settings from |
| 179 |
<filename>.nspawn</filename> files. Takes a boolean or the |
| 180 |
special values <option>override</option> or |
| 181 |
<option>trusted</option>.</para> |
| 182 |
|
| 183 |
<para>If enabled (the default), a settings file named after the |
| 184 |
machine (as specified with the <option>--machine=</option> |
| 185 |
setting, or derived from the directory or image file name) |
| 186 |
with the suffix <filename>.nspawn</filename> is searched in |
| 187 |
<filename>/etc/systemd/nspawn/</filename> and |
| 188 |
<filename>/run/systemd/nspawn/</filename>. If it is found |
| 189 |
there, its settings are read and used. If it is not found |
| 190 |
there, it is subsequently searched in the same directory as the |
| 191 |
image file or in the immediate parent of the root directory of |
| 192 |
the container. In this case, if the file is found, its settings |
| 193 |
will be also read and used, but potentially unsafe settings |
| 194 |
are ignored. Note that in both these cases, settings on the |
| 195 |
command line take precedence over the corresponding settings |
| 196 |
from loaded <filename>.nspawn</filename> files, if both are |
| 197 |
specified. Unsafe settings are considered all settings that |
| 198 |
elevate the container's privileges or grant access to |
| 199 |
additional resources such as files or directories of the |
| 200 |
host. For details about the format and contents of |
| 201 |
<filename>.nspawn</filename> files, consult |
| 202 |
<citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 203 |
|
| 204 |
<para>If this option is set to <option>override</option>, the |
| 205 |
file is searched, read and used the same way, however, the order of |
| 206 |
precedence is reversed: settings read from the |
| 207 |
<filename>.nspawn</filename> file will take precedence over |
| 208 |
the corresponding command line options, if both are |
| 209 |
specified.</para> |
| 210 |
|
| 211 |
<para>If this option is set to <option>trusted</option>, the |
| 212 |
file is searched, read and used the same way, but regardless |
| 213 |
of being found in <filename>/etc/systemd/nspawn/</filename>, |
| 214 |
<filename>/run/systemd/nspawn/</filename> or next to the image |
| 215 |
file or container root directory, all settings will take |
| 216 |
effect, however, command line arguments still take precedence |
| 217 |
over corresponding settings.</para> |
| 218 |
|
| 219 |
<para>If disabled, no <filename>.nspawn</filename> file is read |
| 220 |
and no settings except the ones on the command line are in |
| 221 |
effect.</para> |
| 222 |
|
| 223 |
<xi:include href="version-info.xml" xpointer="v226"/></listitem> |
| 224 |
</varlistentry> |
| 225 |
|
| 226 |
<varlistentry> |
| 227 |
<term><option>--cleanup</option></term> |
| 228 |
|
| 229 |
<listitem> |
| 230 |
<para>Clean up left-over mounts and underlying mount points used by the container, and exit without |
| 231 |
invoking any containers. This may be useful when the previous invocation of |
| 232 |
<command>systemd-nspawn</command> was unexpectedly terminated. This requires at least one of |
| 233 |
<option>-M/--machine=</option>, <option>-D/--directory=</option>, or <option>-i/--image=</option> |
| 234 |
to determine the mounts to be cleaned up.</para> |
| 235 |
|
| 236 |
<xi:include href="version-info.xml" xpointer="v257"/> |
| 237 |
</listitem> |
| 238 |
</varlistentry> |
| 239 |
|
| 240 |
</variablelist> |
| 241 |
|
| 242 |
<refsect2> |
| 243 |
<title>Image Options</title> |
| 244 |
|
| 245 |
<variablelist> |
| 246 |
|
| 247 |
<varlistentry> |
| 248 |
<term><option>-D</option></term> |
| 249 |
<term><option>--directory=</option></term> |
| 250 |
|
| 251 |
<listitem><para>Directory to use as file system root for the container.</para> |
| 252 |
|
| 253 |
<para>If neither <option>--directory=</option>, nor <option>--image=</option> is specified the |
| 254 |
directory is determined by searching for a directory named the same as the machine name specified |
| 255 |
with <option>--machine=</option>. See |
| 256 |
<citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 257 |
section "Files and Directories" for the precise search path.</para> |
| 258 |
|
| 259 |
<xi:include href="vpick.xml" xpointer="directory"/> |
| 260 |
|
| 261 |
<para>If neither <option>--directory=</option>, <option>--image=</option>, nor |
| 262 |
<option>--machine=</option> are specified, the current directory will be used. May not be specified |
| 263 |
together with <option>--image=</option>.</para></listitem> |
| 264 |
</varlistentry> |
| 265 |
|
| 266 |
<varlistentry> |
| 267 |
<term><option>--template=</option></term> |
| 268 |
|
| 269 |
<listitem><para>Directory or <literal>btrfs</literal> subvolume to use as template for the |
| 270 |
container's root directory. If this is specified and the container's root directory (as configured by |
| 271 |
<option>--directory=</option>) does not yet exist it is created as <literal>btrfs</literal> snapshot |
| 272 |
(if supported) or plain directory (otherwise) and populated from this template tree. Ideally, the |
| 273 |
specified template path refers to the root of a <literal>btrfs</literal> subvolume, in which case a |
| 274 |
simple copy-on-write snapshot is taken, and populating the root directory is instant. If the |
| 275 |
specified template path does not refer to the root of a <literal>btrfs</literal> subvolume (or not |
| 276 |
even to a <literal>btrfs</literal> file system at all), the tree is copied (though possibly in a |
| 277 |
'reflink' copy-on-write scheme — if the file system supports that), which can be substantially more |
| 278 |
time-consuming. Note that the snapshot taken is of the specified directory or subvolume, including |
| 279 |
all subdirectories and subvolumes below it, but excluding any sub-mounts. May not be specified |
| 280 |
together with <option>--image=</option> or <option>--ephemeral</option>.</para> |
| 281 |
|
| 282 |
<para>Note that this switch leaves hostname, machine ID and |
| 283 |
all other settings that could identify the instance |
| 284 |
unmodified.</para> |
| 285 |
|
| 286 |
<xi:include href="version-info.xml" xpointer="v219"/></listitem> |
| 287 |
</varlistentry> |
| 288 |
|
| 289 |
<varlistentry> |
| 290 |
<term><option>-x</option></term> |
| 291 |
<term><option>--ephemeral</option></term> |
| 292 |
|
| 293 |
<listitem><para>If specified, the container is run with a temporary snapshot of its file system that is removed |
| 294 |
immediately when the container terminates. May not be specified together with |
| 295 |
<option>--template=</option>.</para> |
| 296 |
<para>Note that this switch leaves hostname, machine ID and all other settings that could identify |
| 297 |
the instance unmodified. Please note that — as with <option>--template=</option> — taking the |
| 298 |
temporary snapshot is more efficient on file systems that support subvolume snapshots or 'reflinks' |
| 299 |
natively (<literal>btrfs</literal> or new <literal>xfs</literal>) than on more traditional file |
| 300 |
systems that do not (<literal>ext4</literal>). Note that the snapshot taken is of the specified |
| 301 |
directory or subvolume, including all subdirectories and subvolumes below it, but excluding any |
| 302 |
sub-mounts.</para> |
| 303 |
|
| 304 |
<para>With this option no modifications of the container image are retained. Use |
| 305 |
<option>--volatile=</option> (described below) for other mechanisms to restrict persistency of |
| 306 |
container images during runtime.</para> |
| 307 |
|
| 308 |
<xi:include href="version-info.xml" xpointer="v219"/> |
| 309 |
</listitem> |
| 310 |
</varlistentry> |
| 311 |
|
| 312 |
<varlistentry> |
| 313 |
<term><option>-i</option></term> |
| 314 |
<term><option>--image=</option></term> |
| 315 |
|
| 316 |
<listitem><para>Disk image to mount the root directory for the |
| 317 |
container from. Takes a path to a regular file or to a block |
| 318 |
device node. The file or block device must contain |
| 319 |
either:</para> |
| 320 |
|
| 321 |
<itemizedlist> |
| 322 |
<listitem><para>An MBR partition table with a single |
| 323 |
partition of type 0x83 that is marked |
| 324 |
bootable.</para></listitem> |
| 325 |
|
| 326 |
<listitem><para>A GUID partition table (GPT) with a single |
| 327 |
partition of type |
| 328 |
0fc63daf-8483-4772-8e79-3d69d8477de4.</para></listitem> |
| 329 |
|
| 330 |
<listitem><para>A GUID partition table (GPT) with a marked root partition which is mounted as the |
| 331 |
root directory of the container. Optionally, GPT images may contain a home and/or a server data |
| 332 |
partition which are mounted to the appropriate places in the container. All these partitions must |
| 333 |
be identified by the partition types defined by the <ulink |
| 334 |
url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">UAPI.2 |
| 335 |
Discoverable Partitions Specification</ulink>.</para></listitem> |
| 336 |
|
| 337 |
<listitem><para>No partition table, and a single file system spanning the whole image.</para></listitem> |
| 338 |
</itemizedlist> |
| 339 |
|
| 340 |
<para>On GPT images, if an EFI System Partition (ESP) is discovered, it is automatically mounted to |
| 341 |
<filename>/efi</filename> (or <filename>/boot</filename> as fallback) in case a directory by this name exists |
| 342 |
and is empty.</para> |
| 343 |
|
| 344 |
<para>Partitions encrypted with LUKS are automatically decrypted. Also, on GPT images dm-verity data integrity |
| 345 |
hash partitions are set up if the root hash for them is specified using the <option>--root-hash=</option> |
| 346 |
option.</para> |
| 347 |
|
| 348 |
<para>Single file system images (i.e. file systems without a surrounding partition table) can be opened using |
| 349 |
dm-verity if the integrity data is passed using the <option>--root-hash=</option> and |
| 350 |
<option>--verity-data=</option> (and optionally <option>--root-hash-sig=</option>) options.</para> |
| 351 |
|
| 352 |
<para>Any other partitions, such as foreign partitions or swap partitions are not mounted. May not be specified |
| 353 |
together with <option>--directory=</option>, <option>--template=</option>.</para> |
| 354 |
|
| 355 |
<xi:include href="vpick.xml" xpointer="image"/> |
| 356 |
|
| 357 |
<xi:include href="version-info.xml" xpointer="v211"/></listitem> |
| 358 |
</varlistentry> |
| 359 |
|
| 360 |
<varlistentry> |
| 361 |
<term><option>--image-policy=<replaceable>policy</replaceable></option></term> |
| 362 |
|
| 363 |
<listitem><para>Takes an image policy string as argument, as per |
| 364 |
<citerefentry><refentrytitle>systemd.image-policy</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The |
| 365 |
policy is enforced when operating on the disk image specified via <option>--image=</option>, see |
| 366 |
above. If not specified, defaults to |
| 367 |
<literal>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</literal>, |
| 368 |
i.e. all recognized file systems in the image are used, but not the swap partition.</para> |
| 369 |
|
| 370 |
<xi:include href="version-info.xml" xpointer="v254"/></listitem> |
| 371 |
</varlistentry> |
| 372 |
|
| 373 |
<varlistentry> |
| 374 |
<term><option>--mstack=</option></term> |
| 375 |
|
| 376 |
<listitem><para>Mount stack to mount the root directory for the container from. Takes a path to a |
| 377 |
directory implementing |
| 378 |
<citerefentry><refentrytitle>systemd.mstack</refentrytitle><manvolnum>7</manvolnum></citerefentry>. This |
| 379 |
may be used to run a container of an <literal>overlayfs</literal> assembled from a number of layers, |
| 380 |
possibly writable and augmented with additional bind mounts.</para> |
| 381 |
|
| 382 |
<xi:include href="version-info.xml" xpointer="v260"/></listitem> |
| 383 |
</varlistentry> |
| 384 |
|
| 385 |
<varlistentry> |
| 386 |
<term><option>--oci-bundle=</option></term> |
| 387 |
|
| 388 |
<listitem><para>Takes the path to an OCI runtime bundle to invoke, as specified in the <ulink |
| 389 |
url="https://github.com/opencontainers/runtime-spec/blob/master/spec.md">OCI Runtime Specification</ulink>. In |
| 390 |
this case, no <filename>.nspawn</filename> file is loaded, and the root directory and various settings are read |
| 391 |
from the OCI runtime JSON data (but data passed on the command line takes precedence).</para> |
| 392 |
|
| 393 |
<xi:include href="version-info.xml" xpointer="v242"/></listitem> |
| 394 |
</varlistentry> |
| 395 |
|
| 396 |
<varlistentry> |
| 397 |
<term><option>--read-only</option></term> |
| 398 |
|
| 399 |
<listitem><para>Mount the container's root file system (and any other file systems contained in the container |
| 400 |
image) read-only. This has no effect on additional mounts made with <option>--bind=</option>, |
| 401 |
<option>--tmpfs=</option> and similar options. This mode is implied if the container image file or directory is |
| 402 |
marked read-only itself. It is also implied if <option>--volatile=</option> is used. In this case, the container |
| 403 |
image on disk is strictly read-only, while changes are permitted but kept non-persistently in memory only. For |
| 404 |
further details, see below.</para></listitem> |
| 405 |
</varlistentry> |
| 406 |
|
| 407 |
<varlistentry> |
| 408 |
<term><option>--volatile</option></term> |
| 409 |
<term><option>--volatile=<replaceable>MODE</replaceable></option></term> |
| 410 |
|
| 411 |
<listitem><para>Boots the container in volatile mode. When no mode parameter is passed or when mode is |
| 412 |
specified as <option>yes</option>, full volatile mode is enabled. This means the root directory is mounted as a |
| 413 |
mostly unpopulated <literal>tmpfs</literal> instance, and <filename>/usr/</filename> from the OS tree is |
| 414 |
mounted into it in read-only mode (the system thus starts up with read-only OS image, but pristine state and |
| 415 |
configuration, any changes are lost on shutdown). When the mode parameter is specified as |
| 416 |
<option>state</option>, the OS tree is mounted read-only, but <filename>/var/</filename> is mounted as a |
| 417 |
writable <literal>tmpfs</literal> instance into it (the system thus starts up with read-only OS resources and |
| 418 |
configuration, but pristine state, and any changes to the latter are lost on shutdown). When the mode parameter |
| 419 |
is specified as <option>overlay</option> the read-only root file system is combined with a writable |
| 420 |
<filename>tmpfs</filename> instance through <literal>overlayfs</literal>, so that it appears at it normally |
| 421 |
would, but any changes are applied to the temporary file system only and lost when the container is |
| 422 |
terminated. When the mode parameter is specified as <option>no</option> (the default), the whole OS tree is |
| 423 |
made available writable (unless <option>--read-only</option> is specified, see above).</para> |
| 424 |
|
| 425 |
<para>Note that if one of the volatile modes is chosen, its effect is limited to the root file system |
| 426 |
(or <filename>/var/</filename> in case of <option>state</option>), and any other mounts placed in the |
| 427 |
hierarchy are unaffected — regardless of whether they are established automatically (e.g. the EFI system |
| 428 |
partition that might be mounted to <filename>/efi/</filename> or <filename>/boot/</filename>) or |
| 429 |
explicitly (e.g. through an additional command line option such as <option>--bind=</option>, see |
| 430 |
below). This means, even if <option>--volatile=overlay</option> is used changes to |
| 431 |
<filename>/efi/</filename> or <filename>/boot/</filename> are prohibited in case such a partition |
| 432 |
exists in the container image operated on, and even if <option>--volatile=state</option> is used the |
| 433 |
hypothetical file <filename index="false">/etc/foobar</filename> is potentially writable if |
| 434 |
<option>--bind=/etc/foobar</option> is used to mount it from outside the read-only container |
| 435 |
<filename>/etc/</filename> directory.</para> |
| 436 |
|
| 437 |
<para>The <option>--ephemeral</option> option is closely related to this setting, and provides similar |
| 438 |
behaviour by making a temporary, ephemeral copy of the whole OS image and executing that. For further details, |
| 439 |
see above.</para> |
| 440 |
|
| 441 |
<para>The <option>--tmpfs=</option> and <option>--overlay=</option> options provide similar functionality, but |
| 442 |
for specific sub-directories of the OS image only. For details, see below.</para> |
| 443 |
|
| 444 |
<para>This option provides similar functionality for containers as the <literal>systemd.volatile=</literal> |
| 445 |
kernel command line switch provides for host systems. See |
| 446 |
<citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry> for |
| 447 |
details.</para> |
| 448 |
|
| 449 |
<para>Note that setting this option to <option>yes</option> or <option>state</option> will only work |
| 450 |
correctly with operating systems in the container that can boot up with only |
| 451 |
<filename>/usr/</filename> mounted, and are able to automatically populate <filename>/var/</filename> |
| 452 |
(and <filename>/etc/</filename> in case of <literal>--volatile=yes</literal>). Specifically, this |
| 453 |
means that operating systems that follow the historic split of <filename>/bin/</filename> and |
| 454 |
<filename>/lib/</filename> (and related directories) from <filename>/usr/</filename> (i.e. where the |
| 455 |
former are not symlinks into the latter) are not supported by <literal>--volatile=yes</literal> as |
| 456 |
container payload. The <option>overlay</option> option does not require any particular preparations |
| 457 |
in the OS, but do note that <literal>overlayfs</literal> behaviour differs from regular file systems |
| 458 |
in a number of ways, and hence compatibility is limited.</para> |
| 459 |
|
| 460 |
<xi:include href="version-info.xml" xpointer="v216"/></listitem> |
| 461 |
</varlistentry> |
| 462 |
|
| 463 |
<varlistentry> |
| 464 |
<term><option>--root-hash=</option></term> |
| 465 |
|
| 466 |
<listitem><para>Takes a data integrity (dm-verity) root hash specified in hexadecimal. This option enables data |
| 467 |
integrity checks using dm-verity, if the used image contains the appropriate integrity data (see above). The |
| 468 |
specified hash must match the root hash of integrity data, and is usually at least 256 bits (and hence 64 |
| 469 |
formatted hexadecimal characters) long (in case of SHA256 for example). If this option is not specified, but |
| 470 |
the image file carries the <literal>user.verity.roothash</literal> extended file attribute (see <citerefentry |
| 471 |
project='man-pages'><refentrytitle>xattr</refentrytitle><manvolnum>7</manvolnum></citerefentry>), then the root |
| 472 |
hash is read from it, also as formatted hexadecimal characters. If the extended file attribute is not found (or |
| 473 |
is not supported by the underlying file system), but a file with the <filename>.roothash</filename> suffix is |
| 474 |
found next to the image file, bearing otherwise the same name (except if the image has the |
| 475 |
<filename>.raw</filename> suffix, in which case the root hash file must not have it in its name), the root hash |
| 476 |
is read from it and automatically used, also as formatted hexadecimal characters.</para> |
| 477 |
|
| 478 |
<para>Note that this configures the root hash for the root file system. Disk images may also contain |
| 479 |
separate file systems for the <filename>/usr/</filename> hierarchy, which may be Verity protected as |
| 480 |
well. The root hash for this protection may be configured via the |
| 481 |
<literal>user.verity.usrhash</literal> extended file attribute or via a <filename>.usrhash</filename> |
| 482 |
file adjacent to the disk image, following the same format and logic as for the root hash for the |
| 483 |
root file system described here. Note that there's currently no switch to configure the root hash for |
| 484 |
the <filename>/usr/</filename> from the command line.</para> |
| 485 |
|
| 486 |
<para>Also see the <varname>RootHash=</varname> option in |
| 487 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 488 |
|
| 489 |
<xi:include href="version-info.xml" xpointer="v233"/> |
| 490 |
</listitem> |
| 491 |
</varlistentry> |
| 492 |
|
| 493 |
<varlistentry> |
| 494 |
<term><option>--root-hash-sig=</option></term> |
| 495 |
|
| 496 |
<listitem><para>Takes a PKCS7 signature of the <option>--root-hash=</option> option. |
| 497 |
The semantics are the same as for the <varname>RootHashSignature=</varname> option, see |
| 498 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 499 |
</para> |
| 500 |
|
| 501 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 502 |
</varlistentry> |
| 503 |
|
| 504 |
<varlistentry> |
| 505 |
<term><option>--verity-data=</option></term> |
| 506 |
|
| 507 |
<listitem><para>Takes the path to a data integrity (dm-verity) file. This option enables data integrity checks |
| 508 |
using dm-verity, if a root-hash is passed and if the used image itself does not contain the integrity data. |
| 509 |
The integrity data must be matched by the root hash. If this option is not specified, but a file with the |
| 510 |
<filename>.verity</filename> suffix is found next to the image file, bearing otherwise the same name (except if |
| 511 |
the image has the <filename>.raw</filename> suffix, in which case the verity data file must not have it in its name), |
| 512 |
the verity data is read from it and automatically used.</para> |
| 513 |
|
| 514 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 515 |
</varlistentry> |
| 516 |
|
| 517 |
<varlistentry> |
| 518 |
<term><option>--pivot-root=</option></term> |
| 519 |
|
| 520 |
<listitem><para>Pivot the specified directory to <filename>/</filename> inside the container, and either unmount the |
| 521 |
container's old root, or pivot it to another specified directory. Takes one of: a path argument — in which case the |
| 522 |
specified path will be pivoted to <filename>/</filename> and the old root will be unmounted; or a colon-separated pair |
| 523 |
of new root path and pivot destination for the old root. The new root path will be pivoted to <filename>/</filename>, |
| 524 |
and the old <filename>/</filename> will be pivoted to the other directory. Both paths must be absolute, and are resolved |
| 525 |
in the container's file system namespace.</para> |
| 526 |
|
| 527 |
<para>This is for containers which have several bootable directories in them; for example, several |
| 528 |
<citerefentry><refentrytitle>ostree</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 529 |
deployments. It emulates the behavior of the boot loader and the initrd which normally select which |
| 530 |
directory to mount as the root and start the container's PID 1 in.</para> |
| 531 |
|
| 532 |
<xi:include href="version-info.xml" xpointer="v233"/></listitem> |
| 533 |
</varlistentry> |
| 534 |
</variablelist> |
| 535 |
|
| 536 |
</refsect2><refsect2> |
| 537 |
<title>Execution Options</title> |
| 538 |
|
| 539 |
<variablelist> |
| 540 |
<varlistentry> |
| 541 |
<term><option>-a</option></term> |
| 542 |
<term><option>--as-pid2</option></term> |
| 543 |
|
| 544 |
<listitem><para>Invoke the shell or specified program as process ID (PID) 2 instead of PID 1 (init). By |
| 545 |
default, if neither this option nor <option>--boot</option> is used, the selected program is run as the process |
| 546 |
with PID 1, a mode only suitable for programs that are aware of the special semantics that the process with |
| 547 |
PID 1 has on UNIX. For example, it needs to reap all processes reparented to it, and should implement |
| 548 |
<command>sysvinit</command> compatible signal handling (specifically: it needs to reboot on SIGINT, reexecute |
| 549 |
on SIGTERM, reload configuration on SIGHUP, and so on). With <option>--as-pid2</option> a minimal stub init |
| 550 |
process is run as PID 1 and the selected program is executed as PID 2 (and hence does not need to implement any |
| 551 |
special semantics). The stub init process will reap processes as necessary and react appropriately to |
| 552 |
signals. It is recommended to use this mode to invoke arbitrary commands in containers, unless they have been |
| 553 |
modified to run correctly as PID 1. Or in other words: this switch should be used for pretty much all commands, |
| 554 |
except when the command refers to an init or shell implementation, as these are generally capable of running |
| 555 |
correctly as PID 1. This option may not be combined with <option>--boot</option>.</para> |
| 556 |
|
| 557 |
<xi:include href="version-info.xml" xpointer="v229"/> |
| 558 |
</listitem> |
| 559 |
</varlistentry> |
| 560 |
|
| 561 |
<varlistentry> |
| 562 |
<term><option>-b</option></term> |
| 563 |
<term><option>--boot</option></term> |
| 564 |
|
| 565 |
<listitem><para>Automatically search for an init program and invoke it as PID 1, instead of a shell or a user |
| 566 |
supplied program. If this option is used, arguments specified on the command line are used as arguments for the |
| 567 |
init program. This option may not be combined with <option>--as-pid2</option>.</para> |
| 568 |
|
| 569 |
<para>The following table explains the different modes of invocation and relationship to |
| 570 |
<option>--as-pid2</option> (see above):</para> |
| 571 |
|
| 572 |
<table> |
| 573 |
<title>Invocation Mode</title> |
| 574 |
<tgroup cols='2' align='left' colsep='1' rowsep='1'> |
| 575 |
<colspec colname="switch" /> |
| 576 |
<colspec colname="explanation" /> |
| 577 |
<thead> |
| 578 |
<row> |
| 579 |
<entry>Switch</entry> |
| 580 |
<entry>Explanation</entry> |
| 581 |
</row> |
| 582 |
</thead> |
| 583 |
<tbody> |
| 584 |
<row> |
| 585 |
<entry>Neither <option>--as-pid2</option> nor <option>--boot</option> specified</entry> |
| 586 |
<entry>The passed parameters are interpreted as the command line, which is executed as PID 1 in the container.</entry> |
| 587 |
</row> |
| 588 |
|
| 589 |
<row> |
| 590 |
<entry><option>--as-pid2</option> specified</entry> |
| 591 |
<entry>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.</entry> |
| 592 |
</row> |
| 593 |
|
| 594 |
<row> |
| 595 |
<entry><option>--boot</option> specified</entry> |
| 596 |
<entry>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.</entry> |
| 597 |
</row> |
| 598 |
|
| 599 |
</tbody> |
| 600 |
</tgroup> |
| 601 |
</table> |
| 602 |
|
| 603 |
<para>Note that <option>--boot</option> is the default mode of operation if the |
| 604 |
<filename>[email protected]</filename> template unit file is used.</para> |
| 605 |
|
| 606 |
<para>When <option>--boot</option> is used, the passed parameters are processed the same way the |
| 607 |
kernel processes its command line before handing it to PID 1: any <literal>KEY=VALUE</literal> |
| 608 |
assignment whose <literal>KEY</literal> does not contain a <literal>.</literal> is exported as |
| 609 |
an environment variable for PID 1 (with <literal>-</literal> in the key replaced by |
| 610 |
<literal>_</literal>, as if specified via <option>--setenv=</option>), while all other |
| 611 |
parameters (including <literal>systemd.*=</literal> assignments) are passed as arguments to the |
| 612 |
init program.</para> |
| 613 |
</listitem> |
| 614 |
</varlistentry> |
| 615 |
|
| 616 |
<varlistentry> |
| 617 |
<term><option>--chdir=</option></term> |
| 618 |
|
| 619 |
<listitem><para>Change to the specified working directory before invoking the process in the container. Expects |
| 620 |
an absolute path in the container's file system namespace.</para> |
| 621 |
|
| 622 |
<xi:include href="version-info.xml" xpointer="v229"/></listitem> |
| 623 |
</varlistentry> |
| 624 |
|
| 625 |
<varlistentry> |
| 626 |
<term><option>-E <replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> |
| 627 |
<term><option>--setenv=<replaceable>NAME</replaceable>[=<replaceable>VALUE</replaceable>]</option></term> |
| 628 |
|
| 629 |
<listitem><para>Specifies an environment variable to pass to the init process in the container. This |
| 630 |
may be used to override the default variables or to set additional variables. It may be used more |
| 631 |
than once to set multiple variables. When <literal>=</literal> and <replaceable>VALUE</replaceable> |
| 632 |
are omitted, the value of the variable with the same name in the program environment will be used. |
| 633 |
</para> |
| 634 |
|
| 635 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 636 |
</varlistentry> |
| 637 |
|
| 638 |
<varlistentry> |
| 639 |
<term><option>-u</option></term> |
| 640 |
<term><option>--uid=</option></term> |
| 641 |
|
| 642 |
<listitem><para>After transitioning into the container, change to the specified user defined in the |
| 643 |
container's user database. Like all other systemd-nspawn features, this is not a security feature and |
| 644 |
provides protection against accidental destructive operations only. This option was previously named |
| 645 |
<option>--user=</option>. The old name is still accepted but deprecated. The short option |
| 646 |
<option>-u</option> is compatible with both old and new versions of |
| 647 |
<command>systemd-nspawn</command>.</para> |
| 648 |
|
| 649 |
<para>Note that if credentials are used in combination with a non-root <option>--uid=</option> |
| 650 |
(e.g.: <option>--set-credential=</option> or <option>--load-credential=</option>), then |
| 651 |
<option>--no-new-privileges=yes</option> must be used, and <option>--boot</option> or |
| 652 |
<option>--as-pid2</option> must not be used, as the credentials would otherwise be unreadable |
| 653 |
by the container due to missing privileges after switching to the specified user.</para></listitem> |
| 654 |
</varlistentry> |
| 655 |
|
| 656 |
<varlistentry> |
| 657 |
<term><option>--kill-signal=</option></term> |
| 658 |
|
| 659 |
<listitem><para>Specify the process signal to send to the container's PID 1 when nspawn itself receives |
| 660 |
<constant>SIGTERM</constant>, in order to trigger an orderly shutdown of the container. Defaults to |
| 661 |
<constant>SIGRTMIN+3</constant> if <option>--boot</option> is used (on systemd-compatible init systems |
| 662 |
<constant>SIGRTMIN+3</constant> triggers an orderly shutdown). If <option>--boot</option> is not used and this |
| 663 |
option is not specified, the container's processes are terminated abruptly via <constant>SIGKILL</constant>. For |
| 664 |
a list of valid signals, see <citerefentry |
| 665 |
project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para> |
| 666 |
|
| 667 |
<xi:include href="version-info.xml" xpointer="v220"/></listitem> |
| 668 |
</varlistentry> |
| 669 |
|
| 670 |
<varlistentry> |
| 671 |
<term><option>--notify-ready=</option></term> |
| 672 |
|
| 673 |
<listitem><para>Configures support for notifications from the container's init process. |
| 674 |
<option>--notify-ready=</option> takes a boolean. If false <command>systemd-nspawn</command> |
| 675 |
notifies the calling service manager with a <literal>READY=1</literal> message when the init process is |
| 676 |
created. If true it waits for a <literal>READY=1</literal> message from the init process in the VM |
| 677 |
before sending its own to the service manager. For more details about notifications see |
| 678 |
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> |
| 679 |
|
| 680 |
<para>Defaults to false. (Note that this is unlike the option of the same name to |
| 681 |
<citerefentry><refentrytitle>systemd-vmspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 682 |
that defaults to true.)</para> |
| 683 |
|
| 684 |
<para>If <command>systemd-nspawn</command> itself is invoked with a <varname>$NOTIFY_SOCKET</varname> |
| 685 |
set in its environment (i.e. it is itself supervised by a service manager that uses the |
| 686 |
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 687 |
protocol), <literal>FDSTORE=1</literal> and <literal>FDSTOREREMOVE=1</literal> messages received |
| 688 |
from the container payload (along with any accompanying file descriptors and |
| 689 |
<literal>FDNAME=</literal> tag) are forwarded one level up to the enveloping service manager. This |
| 690 |
allows the file descriptor store of services running inside the container to be preserved across |
| 691 |
container restarts (and, transitively, across restarts, re-execs, soft-reboots and LUO-based kexecs |
| 692 |
of any outer service manager), provided |
| 693 |
<varname>FileDescriptorStoreMax=</varname>/<varname>FileDescriptorStorePreserve=yes</varname> are |
| 694 |
configured on the unit running <command>systemd-nspawn</command>. See the |
| 695 |
<ulink url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> documentation |
| 696 |
for details.</para> |
| 697 |
|
| 698 |
<xi:include href="version-info.xml" xpointer="v231"/></listitem> |
| 699 |
</varlistentry> |
| 700 |
|
| 701 |
<varlistentry> |
| 702 |
<term><option>--suppress-sync=</option></term> |
| 703 |
|
| 704 |
<listitem><para>Expects a boolean argument. If true, turns off any form of on-disk file system |
| 705 |
synchronization for the container payload. This means all system calls such as <citerefentry |
| 706 |
project='man-pages'><refentrytitle>sync</refentrytitle><manvolnum>2</manvolnum></citerefentry>, |
| 707 |
<function>fsync()</function>, <function>syncfs()</function>, … will execute no operation, and the |
| 708 |
<constant>O_SYNC</constant>/<constant>O_DSYNC</constant> flags to <citerefentry |
| 709 |
project='man-pages'><refentrytitle>open</refentrytitle><manvolnum>2</manvolnum></citerefentry> and |
| 710 |
related calls will be made unavailable. This is potentially dangerous, as assumed data integrity |
| 711 |
guarantees to the container payload are not actually enforced (i.e. data assumed to have been written |
| 712 |
to disk might be lost if the system is shut down abnormally). However, this can dramatically improve |
| 713 |
container runtime performance – as long as these guarantees are not required or desirable, for |
| 714 |
example because any data written by the container is of temporary, redundant nature, or just an |
| 715 |
intermediary artifact that will be further processed and finalized by a later step in a |
| 716 |
pipeline. Defaults to false.</para> |
| 717 |
|
| 718 |
<xi:include href="version-info.xml" xpointer="v250"/></listitem> |
| 719 |
</varlistentry> |
| 720 |
</variablelist> |
| 721 |
|
| 722 |
</refsect2><refsect2> |
| 723 |
<title>System Identity Options</title> |
| 724 |
|
| 725 |
<variablelist> |
| 726 |
<varlistentry> |
| 727 |
<term><option>-M</option></term> |
| 728 |
<term><option>--machine=</option></term> |
| 729 |
|
| 730 |
<listitem><para>Sets the machine name for this container. This |
| 731 |
name may be used to identify this container during its runtime |
| 732 |
(for example in tools like |
| 733 |
<citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 734 |
and similar), and is used to initialize the container's |
| 735 |
hostname (which the container can choose to override, |
| 736 |
however). If not specified, the last component of the root |
| 737 |
directory path of the container is used, possibly suffixed |
| 738 |
with a random identifier in case <option>--ephemeral</option> |
| 739 |
mode is selected. If the root directory selected is the host's |
| 740 |
root directory the host's hostname is used as default |
| 741 |
instead.</para> |
| 742 |
|
| 743 |
<xi:include href="version-info.xml" xpointer="v202"/></listitem> |
| 744 |
</varlistentry> |
| 745 |
|
| 746 |
<varlistentry> |
| 747 |
<term><option>--hostname=</option></term> |
| 748 |
|
| 749 |
<listitem><para>Controls the hostname to set within the container, if different from the machine name. Expects |
| 750 |
a valid hostname as argument. If this option is used, the kernel hostname of the container will be set to this |
| 751 |
value, otherwise it will be initialized to the machine name as controlled by the <option>--machine=</option> |
| 752 |
option described above. The machine name is used for various aspect of identification of the container from the |
| 753 |
outside, the kernel hostname configurable with this option is useful for the container to identify itself from |
| 754 |
the inside. It is usually a good idea to keep both forms of identification synchronized, in order to avoid |
| 755 |
confusion. It is hence recommended to avoid usage of this option, and use <option>--machine=</option> |
| 756 |
exclusively. Note that regardless whether the container's hostname is initialized from the name set with |
| 757 |
<option>--hostname=</option> or the one set with <option>--machine=</option>, the container can later override |
| 758 |
its kernel hostname freely on its own as well.</para> |
| 759 |
|
| 760 |
<xi:include href="version-info.xml" xpointer="v239"/> |
| 761 |
</listitem> |
| 762 |
</varlistentry> |
| 763 |
|
| 764 |
<varlistentry> |
| 765 |
<term><option>--uuid=</option></term> |
| 766 |
|
| 767 |
<listitem><para>Set the specified UUID for the container. The |
| 768 |
init system will initialize |
| 769 |
<filename>/etc/machine-id</filename> from this if this file is |
| 770 |
not set yet. Note that this option takes effect only if |
| 771 |
<filename>/etc/machine-id</filename> in the container is |
| 772 |
unpopulated.</para></listitem> |
| 773 |
</varlistentry> |
| 774 |
</variablelist> |
| 775 |
|
| 776 |
</refsect2><refsect2> |
| 777 |
<title>Property Options</title> |
| 778 |
|
| 779 |
<variablelist> |
| 780 |
<varlistentry> |
| 781 |
<term><option>-S</option></term> |
| 782 |
<term><option>--slice=</option></term> |
| 783 |
|
| 784 |
<listitem><para>Make the container part of the specified slice, instead of the default |
| 785 |
<filename>machine.slice</filename>. This applies only if the machine is run in its own scope unit, i.e. if |
| 786 |
<option>--keep-unit</option> is not used.</para> |
| 787 |
|
| 788 |
<xi:include href="version-info.xml" xpointer="v206"/> |
| 789 |
</listitem> |
| 790 |
</varlistentry> |
| 791 |
|
| 792 |
<varlistentry> |
| 793 |
<term><option>--property=</option></term> |
| 794 |
|
| 795 |
<listitem><para>Set a unit property on the scope unit to register for the machine. This applies only if the |
| 796 |
machine is run in its own scope unit, i.e. if <option>--keep-unit</option> is not used. Takes unit property |
| 797 |
assignments in the same format as <command>systemctl set-property</command>. This is useful to set memory |
| 798 |
limits and similar for the container.</para> |
| 799 |
|
| 800 |
<xi:include href="version-info.xml" xpointer="v220"/> |
| 801 |
</listitem> |
| 802 |
</varlistentry> |
| 803 |
|
| 804 |
<varlistentry> |
| 805 |
<term><option>--register=</option></term> |
| 806 |
|
| 807 |
<listitem><para>Controls whether the container is registered with |
| 808 |
<citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>. Takes a |
| 809 |
boolean argument or <literal>auto</literal>, and defaults to <literal>auto</literal>. This option should be |
| 810 |
enabled when the container runs a full Operating System (more specifically: a system and service manager as |
| 811 |
PID 1), and is useful to ensure that the container is accessible via |
| 812 |
<citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry> and shown by |
| 813 |
tools such as <citerefentry |
| 814 |
project='man-pages'><refentrytitle>ps</refentrytitle><manvolnum>1</manvolnum></citerefentry>. If the container |
| 815 |
does not run a service manager, it is recommended to set this option to <literal>no</literal>. When set to |
| 816 |
<literal>auto</literal>, registration is attempted but failures are ignored.</para> |
| 817 |
|
| 818 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 819 |
</varlistentry> |
| 820 |
|
| 821 |
<varlistentry> |
| 822 |
<term><option>--keep-unit</option></term> |
| 823 |
|
| 824 |
<listitem><para>Instead of creating a transient scope unit to run the container in, simply use the service or |
| 825 |
scope unit <command>systemd-nspawn</command> has been invoked in. If <option>--register=yes</option> is set |
| 826 |
this unit is registered with |
| 827 |
<citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>. This |
| 828 |
switch should be used if <command>systemd-nspawn</command> is invoked from within a service unit, and the |
| 829 |
service unit's sole purpose is to run a single <command>systemd-nspawn</command> container. This option is not |
| 830 |
available if run from a user session.</para> |
| 831 |
<para>Note that passing <option>--keep-unit</option> disables the effect of <option>--slice=</option> and |
| 832 |
<option>--property=</option>. Use <option>--keep-unit</option> and <option>--register=no</option> in |
| 833 |
combination to disable any kind of unit allocation or registration with |
| 834 |
<command>systemd-machined</command>.</para> |
| 835 |
|
| 836 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 837 |
</varlistentry> |
| 838 |
</variablelist> |
| 839 |
|
| 840 |
</refsect2><refsect2> |
| 841 |
<title>User Namespacing Options</title> |
| 842 |
|
| 843 |
<variablelist> |
| 844 |
<varlistentry> |
| 845 |
<term><option>--private-users=</option></term> |
| 846 |
|
| 847 |
<listitem><para>Controls user namespacing. If enabled, the container will run with its own private set of UNIX |
| 848 |
user and group ids (UIDs and GIDs). This involves mapping the private UIDs/GIDs used in the container (starting |
| 849 |
with the container's root user 0 and up) to a range of UIDs/GIDs on the host that are not used for other |
| 850 |
purposes (usually in the range beyond the host's UID/GID 65536). The parameter may be specified as follows:</para> |
| 851 |
|
| 852 |
<orderedlist> |
| 853 |
<listitem><para>If one or two colon-separated numbers are specified, user namespacing is turned on. The first |
| 854 |
parameter specifies the first host UID/GID to assign to the container, the second parameter specifies the |
| 855 |
number of host UIDs/GIDs to assign to the container. If the second parameter is omitted, 65536 UIDs/GIDs are |
| 856 |
assigned.</para></listitem> |
| 857 |
|
| 858 |
<listitem><para>If the parameter is <literal>yes</literal>, user namespacing is turned on. The |
| 859 |
UID/GID range to use is determined automatically from the file ownership of the root directory of |
| 860 |
the container's directory tree. To use this option, make sure to prepare the directory tree in |
| 861 |
advance, and ensure that all files and directories in it are owned by UIDs/GIDs in the range you'd |
| 862 |
like to use. Also, make sure that used file ACLs exclusively reference UIDs/GIDs in the appropriate |
| 863 |
range. In this mode, the number of UIDs/GIDs assigned to the container is 65536, and the owner |
| 864 |
UID/GID of the root directory must be a multiple of 65536.</para></listitem> |
| 865 |
|
| 866 |
<listitem><para>The special value <literal>pick</literal> turns on user namespacing. In this case |
| 867 |
the UID/GID range is automatically chosen. As first step, the file owner UID/GID of the root |
| 868 |
directory of the container's directory tree is read, and it is checked that no other container is |
| 869 |
currently using it. If this check is successful, the UID/GID range determined this way is used, |
| 870 |
similarly to the behavior if <literal>yes</literal> is specified. If the check is not successful |
| 871 |
(and thus the UID/GID range indicated in the root directory's file owner is already used elsewhere) |
| 872 |
a new – currently unused – UID/GID range of 65536 UIDs/GIDs is randomly chosen between the host |
| 873 |
UID/GIDs of 524288 and 1878982656, always starting at a multiple of 65536, and, if possible, |
| 874 |
consistently hashed from the machine name. This setting implies |
| 875 |
<option>--private-users-ownership=auto</option> (see below), which possibly has the effect that the |
| 876 |
files and directories in the container's directory tree will be owned by the appropriate users of |
| 877 |
the range picked. Using this option makes user namespace behavior fully automatic. Note that the |
| 878 |
first invocation of a previously unused container image might result in picking a new UID/GID range |
| 879 |
for it, and thus in the (possibly expensive) file ownership adjustment operation. However, |
| 880 |
subsequent invocations of the container will be cheap (unless of course the picked UID/GID range is |
| 881 |
assigned to a different use by then).</para></listitem> |
| 882 |
|
| 883 |
<listitem><para>If the parameter is <literal>no</literal>, user namespacing is turned off. This is |
| 884 |
the default when <command>systemd-nspawn</command> is invoked directly. (Note that the |
| 885 |
<filename>[email protected]</filename> unit enables private users.) This option is not |
| 886 |
secure and must not be used to run untrusted code.</para></listitem> |
| 887 |
|
| 888 |
<listitem><para>If the parameter is <literal>identity</literal>, user namespacing is employed with |
| 889 |
an identity mapping for the first 65536 UIDs/GIDs. This is mostly equivalent to |
| 890 |
<option>--private-users=0:65536</option>. While it does not provide UID/GID isolation, since all |
| 891 |
host and container UIDs/GIDs are chosen identically it does provide process capability isolation, |
| 892 |
but may be useful if proper user namespacing with distinct UID maps is not possible. This option is |
| 893 |
not secure and must not be used to run untrusted code.</para></listitem> |
| 894 |
|
| 895 |
<listitem><para>If the parameter is <literal>managed</literal>, user namespacing is employed with |
| 896 |
in <emphasis>managed</emphasis> mode, i.e. allocation of a UID range is delegated to |
| 897 |
<citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. This |
| 898 |
mode is selected by default if invoked unprivileged, but can also be requested explicitly when |
| 899 |
privileged. In this mode a 64K UID range is automatically picked.</para></listitem> |
| 900 |
</orderedlist> |
| 901 |
|
| 902 |
<para>It is recommended to assign at least 65536 UIDs/GIDs to each container, so that the usable |
| 903 |
UID/GID range in the container covers 16 bits. For best security, do not assign overlapping UID/GID |
| 904 |
ranges to multiple containers. It is hence a good idea to use the upper 16 bit of the host 32-bit |
| 905 |
UIDs/GIDs as container identifier, while the lower 16 bits encode the container UID/GID used. This is |
| 906 |
in fact the behavior enforced by the <option>--private-users=pick</option> option.</para> |
| 907 |
|
| 908 |
<para>When user namespaces are used, the GID range assigned to each container is always chosen |
| 909 |
identical to the UID range.</para> |
| 910 |
|
| 911 |
<para>In most cases, <option>--private-users=managed</option> (or when privileged |
| 912 |
<option>--private-users=pick</option>, too) is the recommended option as user |
| 913 |
namespacing is advised for security, and this option massively enhances container security while |
| 914 |
operating fully automatically in most cases.</para> |
| 915 |
|
| 916 |
<para>Note that the picked UID/GID range is not written to <filename>/etc/passwd</filename> or |
| 917 |
<filename>/etc/group</filename>. In fact, the allocation of the range is not stored persistently, |
| 918 |
except possibly in the file ownership of the files and directories of the container, see |
| 919 |
<option>--private-users-ownership=</option>.</para> |
| 920 |
|
| 921 |
<para>Note that when user namespacing is used without UID mapping (see below) file ownership on disk |
| 922 |
reflects this, and all of the container's files and directories are owned by the container's |
| 923 |
effective user and group IDs. This means that copying files from and to the container image requires |
| 924 |
correction of the numeric UID/GID values, according to the UID/GID shift applied.</para> |
| 925 |
|
| 926 |
<para>Note that for fully unprivileged operation in <literal>managed</literal> mode, any directory |
| 927 |
image should be owned by the foreign UID range.</para> |
| 928 |
|
| 929 |
<xi:include href="version-info.xml" xpointer="v220"/></listitem> |
| 930 |
</varlistentry> |
| 931 |
|
| 932 |
<varlistentry> |
| 933 |
<term><option>--private-users-ownership=</option></term> |
| 934 |
|
| 935 |
<listitem><para>Controls how to adjust the container image's UIDs and GIDs to match the UID/GID range |
| 936 |
chosen with <option>--private-users=</option>, see above. Takes one of <literal>off</literal> (to |
| 937 |
leave the image as is), <literal>chown</literal> (to recursively <function>chown()</function> the |
| 938 |
container's directory tree as needed), <literal>map</literal> (in order to use transparent ID mapping |
| 939 |
mounts from UID 0 to the target UID range), <literal>foreign</literal> (the same, but from the |
| 940 |
foreign UID range base) or <literal>auto</literal> for automatically using <literal>map</literal> or |
| 941 |
<literal>foreign</literal>, where available and applicable and <literal>chown</literal> where |
| 942 |
not.</para> |
| 943 |
|
| 944 |
<para>If <literal>chown</literal> is selected, all files and directories in the container's directory |
| 945 |
tree will be adjusted so that they are owned by the appropriate UIDs/GIDs selected for the container |
| 946 |
(see above). This operation is potentially expensive, as it involves iterating through the full |
| 947 |
directory tree of the container. Besides actual file ownership, file ACLs are adjusted as |
| 948 |
well.</para> |
| 949 |
|
| 950 |
<para>Typically <literal>foreign</literal> or <literal>map</literal> is the best choice, since it |
| 951 |
transparently maps UIDs/GIDs in memory as needed without modifying the image, and without requiring |
| 952 |
an expensive recursive adjustment operation. However, it is not available for all file systems, |
| 953 |
currently.</para> |
| 954 |
|
| 955 |
<para>The <option>--private-users-ownership=auto</option> option is implied if |
| 956 |
<option>--private-users=pick</option> is used. This option has no effect if user namespacing is not |
| 957 |
used.</para> |
| 958 |
|
| 959 |
<para><citerefentry><refentrytitle>systemd-dissect</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 960 |
<option>--shift</option> switch may be used to shift UID/GID ownership from or to the 0, foreign or |
| 961 |
specific container UID/GID base outside of any <command>systemd-nspawn</command> invocation.</para> |
| 962 |
|
| 963 |
<xi:include href="version-info.xml" xpointer="v230"/></listitem> |
| 964 |
</varlistentry> |
| 965 |
|
| 966 |
<varlistentry> |
| 967 |
<term><option>--private-users-delegate=</option></term> |
| 968 |
|
| 969 |
<listitem><para>Takes a non-negative integer. Requests that the specified number of additional 64K |
| 970 |
UID/GID ranges are delegated into the container's user namespace. These delegated ranges are mapped |
| 971 |
1:1 (i.e. the same UID/GID values are used inside and outside the user namespace) and can be used by |
| 972 |
nested containers to allocate their own transient UID/GID ranges via |
| 973 |
<citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> |
| 974 |
|
| 975 |
<para>This option requires <option>--private-users=managed</option>, as the delegation is performed |
| 976 |
by |
| 977 |
<citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 978 |
as part of the user namespace allocation. The maximum number of delegated ranges is 16. Defaults to |
| 979 |
0, i.e. no delegation.</para> |
| 980 |
|
| 981 |
<para>When this option is used with a non-zero value, the |
| 982 |
<citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 983 |
Varlink socket (<filename>/run/systemd/io.systemd.NamespaceResource</filename>) is automatically |
| 984 |
bind-mounted into the container along with the necessary discovery symlinks in |
| 985 |
<filename>/run/systemd/userdb/</filename> and <filename>/run/varlink/registry/</filename>. This |
| 986 |
allows processes inside the container to contact |
| 987 |
<command>systemd-nsresourced</command> on the host in order to allocate nested user namespaces from |
| 988 |
the delegated ranges.</para> |
| 989 |
|
| 990 |
<xi:include href="version-info.xml" xpointer="v260"/></listitem> |
| 991 |
</varlistentry> |
| 992 |
|
| 993 |
<varlistentry> |
| 994 |
<term><option>-U</option></term> |
| 995 |
|
| 996 |
<listitem><para>If the kernel supports the user namespaces feature, equivalent to |
| 997 |
<option>--private-users=pick --private-users-ownership=auto</option>, otherwise equivalent to |
| 998 |
<option>--private-users=no</option>.</para> |
| 999 |
|
| 1000 |
<para>Note that <option>-U</option> is the default if the |
| 1001 |
<filename>[email protected]</filename> template unit file is used.</para> |
| 1002 |
|
| 1003 |
<para>Note: it is possible to undo the effect of <option>--private-users-ownership=chown</option> (or |
| 1004 |
<option>-U</option>) on the file system by redoing the operation with the first UID of 0:</para> |
| 1005 |
|
| 1006 |
<programlisting>systemd-nspawn … --private-users=0 --private-users-ownership=chown</programlisting> |
| 1007 |
|
| 1008 |
<xi:include href="version-info.xml" xpointer="v230"/> |
| 1009 |
</listitem> |
| 1010 |
</varlistentry> |
| 1011 |
|
| 1012 |
</variablelist> |
| 1013 |
|
| 1014 |
</refsect2><refsect2> |
| 1015 |
<title>Networking Options</title> |
| 1016 |
|
| 1017 |
<variablelist> |
| 1018 |
|
| 1019 |
<varlistentry> |
| 1020 |
<term><option>--private-network</option></term> |
| 1021 |
|
| 1022 |
<listitem><para>Disconnect networking of the container from |
| 1023 |
the host. This makes all network interfaces unavailable in the |
| 1024 |
container, with the exception of the loopback device and those |
| 1025 |
specified with <option>--network-interface=</option> and |
| 1026 |
configured with <option>--network-veth</option>. If this |
| 1027 |
option is specified, the <constant>CAP_NET_ADMIN</constant> capability will be |
| 1028 |
added to the set of capabilities the container retains. The |
| 1029 |
latter may be disabled by using <option>--drop-capability=</option>. |
| 1030 |
If this option is not specified (or implied by one of the options |
| 1031 |
listed below), the container will have full access to the host network. |
| 1032 |
</para></listitem> |
| 1033 |
</varlistentry> |
| 1034 |
|
| 1035 |
<varlistentry> |
| 1036 |
<term><option>--network-interface=</option></term> |
| 1037 |
|
| 1038 |
<listitem><para>Assign the specified network interface to the container. Either takes a single |
| 1039 |
interface name, referencing the name on the host, or a colon-separated pair of interfaces, in which |
| 1040 |
case the first one references the name on the host, and the second one the name in the container. |
| 1041 |
When the container terminates, the interface is moved back to the calling namespace and renamed to |
| 1042 |
its original name. Note that <option>--network-interface=</option> implies |
| 1043 |
<option>--private-network</option>. This option may be used more than once to add multiple network |
| 1044 |
interfaces to the container.</para> |
| 1045 |
|
| 1046 |
<para>Note that any network interface specified this way must already exist at the time the container |
| 1047 |
is started. If the container shall be started automatically at boot via a |
| 1048 |
<filename>[email protected]</filename> unit file instance, it might hence make sense to add a |
| 1049 |
unit file drop-in to the service instance |
| 1050 |
(e.g. <filename>/etc/systemd/system/[email protected]/50-network.conf</filename>) with |
| 1051 |
contents like the following:</para> |
| 1052 |
|
| 1053 |
<programlisting>[Unit] |
| 1054 |
Wants=sys-subsystem-net-devices-ens1.device |
| 1055 |
After=sys-subsystem-net-devices-ens1.device</programlisting> |
| 1056 |
|
| 1057 |
<para>This will make sure that activation of the container service will be delayed until the |
| 1058 |
<literal>ens1</literal> network interface has shown up. This is required since hardware probing is |
| 1059 |
fully asynchronous, and network interfaces might be discovered only later during the boot process, |
| 1060 |
after the container would normally be started without these explicit dependencies.</para> |
| 1061 |
|
| 1062 |
<xi:include href="version-info.xml" xpointer="v209"/> |
| 1063 |
</listitem> |
| 1064 |
</varlistentry> |
| 1065 |
|
| 1066 |
<varlistentry> |
| 1067 |
<term><option>--network-macvlan=</option></term> |
| 1068 |
|
| 1069 |
<listitem><para>Create a <literal>macvlan</literal> interface of the specified Ethernet network |
| 1070 |
interface and add it to the container. Either takes a single interface name, referencing the name |
| 1071 |
on the host, or a colon-separated pair of interfaces, in which case the first one references the name |
| 1072 |
on the host, and the second one the name in the container. A <literal>macvlan</literal> interface is |
| 1073 |
a virtual interface that adds a second MAC address to an existing physical Ethernet link. If the |
| 1074 |
container interface name is not defined, the interface in the container will be named after the |
| 1075 |
interface on the host, prefixed with <literal>mv-</literal>. Note that |
| 1076 |
<option>--network-macvlan=</option> implies <option>--private-network</option>. This option may be |
| 1077 |
used more than once to add multiple network interfaces to the container.</para> |
| 1078 |
|
| 1079 |
<para>As with <option>--network-interface=</option>, the underlying Ethernet network interface must |
| 1080 |
already exist at the time the container is started, and thus similar unit file drop-ins as described |
| 1081 |
above might be useful.</para> |
| 1082 |
|
| 1083 |
<xi:include href="version-info.xml" xpointer="v211"/></listitem> |
| 1084 |
</varlistentry> |
| 1085 |
|
| 1086 |
<varlistentry> |
| 1087 |
<term><option>--network-ipvlan=</option></term> |
| 1088 |
|
| 1089 |
<listitem><para>Create an <literal>ipvlan</literal> interface of the specified Ethernet network |
| 1090 |
interface and add it to the container. Either takes a single interface name, referencing the name on |
| 1091 |
the host, or a colon-separated pair of interfaces, in which case the first one references the name |
| 1092 |
on the host, and the second one the name in the container. An <literal>ipvlan</literal> interface is |
| 1093 |
a virtual interface, |
| 1094 |
similar to a <literal>macvlan</literal> interface, which uses the same MAC address as the underlying |
| 1095 |
interface. If the container interface name is not defined, the interface in the container will be |
| 1096 |
named after the interface on the host, prefixed |
| 1097 |
with <literal>iv-</literal>. Note that <option>--network-ipvlan=</option> implies |
| 1098 |
<option>--private-network</option>. This option may be used more than once to add multiple network |
| 1099 |
interfaces to the container.</para> |
| 1100 |
|
| 1101 |
<para>As with <option>--network-interface=</option>, the underlying Ethernet network interface must |
| 1102 |
already exist at the time the container is started, and thus similar unit file drop-ins as described |
| 1103 |
above might be useful.</para> |
| 1104 |
|
| 1105 |
<xi:include href="version-info.xml" xpointer="v219"/></listitem> |
| 1106 |
</varlistentry> |
| 1107 |
|
| 1108 |
<varlistentry> |
| 1109 |
<term><option>-n</option></term> |
| 1110 |
<term><option>--network-veth</option></term> |
| 1111 |
|
| 1112 |
<listitem><para>Create a virtual Ethernet link (<literal>veth</literal>) between host and container. The host |
| 1113 |
side of the Ethernet link will be available as a network interface named after the container's name (as |
| 1114 |
specified with <option>--machine=</option>), prefixed with <literal>ve-</literal>. The container side of the |
| 1115 |
Ethernet link will be named <literal>host0</literal>. The <option>--network-veth</option> option implies |
| 1116 |
<option>--private-network</option>.</para> |
| 1117 |
|
| 1118 |
<para>Note that |
| 1119 |
<citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1120 |
includes by default a network file <filename>/usr/lib/systemd/network/80-container-ve.network</filename> |
| 1121 |
matching the host-side interfaces created this way, which contains settings to enable automatic address |
| 1122 |
provisioning on the created virtual link via DHCP, as well as automatic IP routing onto the host's external |
| 1123 |
network interfaces. It also contains <filename>/usr/lib/systemd/network/80-container-host0.network</filename> |
| 1124 |
matching the container-side interface created this way, containing settings to enable client side address |
| 1125 |
assignment via DHCP. In case <filename>systemd-networkd</filename> is running on both the host and inside the |
| 1126 |
container, automatic IP communication from the container to the host is thus available, with further |
| 1127 |
connectivity to the external network.</para> |
| 1128 |
|
| 1129 |
<para>Note that <option>--network-veth</option> is the default if the |
| 1130 |
<filename>[email protected]</filename> template unit file is used.</para> |
| 1131 |
|
| 1132 |
<para>Note that on Linux network interface names may have a length of 15 characters at maximum, while |
| 1133 |
container names may have a length up to 64 characters. As this option derives the host-side interface |
| 1134 |
name from the container name the name is possibly truncated. Thus, care needs to be taken to ensure |
| 1135 |
that interface names remain unique in this case, or even better container names are generally not |
| 1136 |
chosen longer than 12 characters, to avoid the truncation. If the name is truncated, |
| 1137 |
<command>systemd-nspawn</command> will automatically append a 4-digit hash value to the name to |
| 1138 |
reduce the chance of collisions. However, the hash algorithm is not collision-free. (See |
| 1139 |
<citerefentry><refentrytitle>systemd.net-naming-scheme</refentrytitle><manvolnum>7</manvolnum></citerefentry> |
| 1140 |
for details on older naming algorithms for this interface). Alternatively, the |
| 1141 |
<option>--network-veth-extra=</option> option may be used, which allows free configuration of the |
| 1142 |
host-side interface name independently of the container name — but might require a bit more |
| 1143 |
additional configuration in case bridging in a fashion similar to <option>--network-bridge=</option> |
| 1144 |
is desired.</para> |
| 1145 |
|
| 1146 |
<xi:include href="version-info.xml" xpointer="v209"/> |
| 1147 |
</listitem> |
| 1148 |
</varlistentry> |
| 1149 |
|
| 1150 |
<varlistentry> |
| 1151 |
<term><option>--network-veth-extra=</option></term> |
| 1152 |
|
| 1153 |
<listitem><para>Adds an additional virtual Ethernet link |
| 1154 |
between host and container. Takes a colon-separated pair of |
| 1155 |
host interface name and container interface name. The latter |
| 1156 |
may be omitted in which case the container and host sides will |
| 1157 |
be assigned the same name. This switch is independent of |
| 1158 |
<option>--network-veth</option>, and — in contrast — may be |
| 1159 |
used multiple times, and allows configuration of the network |
| 1160 |
interface names. Note that <option>--network-bridge=</option> |
| 1161 |
has no effect on interfaces created with |
| 1162 |
<option>--network-veth-extra=</option>.</para> |
| 1163 |
|
| 1164 |
<xi:include href="version-info.xml" xpointer="v228"/></listitem> |
| 1165 |
</varlistentry> |
| 1166 |
|
| 1167 |
<varlistentry> |
| 1168 |
<term><option>--network-bridge=</option></term> |
| 1169 |
|
| 1170 |
<listitem><para>Adds the host side of the Ethernet link created with <option>--network-veth</option> |
| 1171 |
to the specified Ethernet bridge interface. Expects a valid network interface name of a bridge device |
| 1172 |
as argument. Note that <option>--network-bridge=</option> implies <option>--network-veth</option>. If |
| 1173 |
this option is used, the host side of the Ethernet link will use the <literal>vb-</literal> prefix |
| 1174 |
instead of <literal>ve-</literal>. Regardless of the used naming prefix the same network interface |
| 1175 |
name length limits imposed by Linux apply, along with the complications this creates (for details see |
| 1176 |
above).</para> |
| 1177 |
|
| 1178 |
<para>As with <option>--network-interface=</option>, the underlying bridge network interface must |
| 1179 |
already exist at the time the container is started, and thus similar unit file drop-ins as described |
| 1180 |
above might be useful.</para> |
| 1181 |
|
| 1182 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 1183 |
</varlistentry> |
| 1184 |
|
| 1185 |
<varlistentry> |
| 1186 |
<term><option>--network-zone=</option></term> |
| 1187 |
|
| 1188 |
<listitem><para>Creates a virtual Ethernet link (<literal>veth</literal>) to the container and adds it to an |
| 1189 |
automatically managed Ethernet bridge interface. The bridge interface is named after the passed argument, |
| 1190 |
prefixed with <literal>vz-</literal>. The bridge interface is automatically created when the first container |
| 1191 |
configured for its name is started, and is automatically removed when the last container configured for its |
| 1192 |
name exits. Hence, each bridge interface configured this way exists only as long as there's at least one |
| 1193 |
container referencing it running. This option is very similar to <option>--network-bridge=</option>, besides |
| 1194 |
this automatic creation/removal of the bridge device.</para> |
| 1195 |
|
| 1196 |
<para>This setting makes it easy to place multiple related containers on a common, virtual Ethernet-based |
| 1197 |
broadcast domain, here called a "zone". Each container may only be part of one zone, but each zone may contain |
| 1198 |
any number of containers. Each zone is referenced by its name. Names may be chosen freely (as long as they form |
| 1199 |
valid network interface names when prefixed with <literal>vz-</literal>), and it is sufficient to pass the same |
| 1200 |
name to the <option>--network-zone=</option> switch of the various concurrently running containers to join |
| 1201 |
them in one zone.</para> |
| 1202 |
|
| 1203 |
<para>Note that |
| 1204 |
<citerefentry><refentrytitle>systemd-networkd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1205 |
includes by default a network file <filename>/usr/lib/systemd/network/80-container-vz.network</filename> |
| 1206 |
matching the bridge interfaces created this way, which contains settings to enable automatic address |
| 1207 |
provisioning on the created virtual network via DHCP, as well as automatic IP routing onto the host's external |
| 1208 |
network interfaces. Using <option>--network-zone=</option> is hence in most cases fully automatic and |
| 1209 |
sufficient to connect multiple local containers in a joined broadcast domain to the host, with further |
| 1210 |
connectivity to the external network.</para> |
| 1211 |
|
| 1212 |
<xi:include href="version-info.xml" xpointer="v230"/> |
| 1213 |
</listitem> |
| 1214 |
</varlistentry> |
| 1215 |
|
| 1216 |
<varlistentry> |
| 1217 |
<term><option>--network-namespace-path=</option></term> |
| 1218 |
|
| 1219 |
<listitem><para>Takes the path to a file representing a kernel |
| 1220 |
network namespace that the container shall run in. The specified path |
| 1221 |
should refer to a (possibly bind-mounted) network namespace file, as |
| 1222 |
exposed by the kernel below <filename>/proc/$PID/ns/net</filename>. |
| 1223 |
This makes the container enter the given network namespace. One of the |
| 1224 |
typical use cases is to give a network namespace under |
| 1225 |
<filename>/run/netns</filename> created by <citerefentry |
| 1226 |
project='man-pages'><refentrytitle>ip-netns</refentrytitle><manvolnum>8</manvolnum></citerefentry>, |
| 1227 |
for example, <option>--network-namespace-path=/run/netns/foo</option>. |
| 1228 |
Note that this option cannot be used together with other |
| 1229 |
network-related options, such as <option>--private-network</option> |
| 1230 |
or <option>--network-interface=</option>.</para> |
| 1231 |
|
| 1232 |
<xi:include href="version-info.xml" xpointer="v236"/></listitem> |
| 1233 |
</varlistentry> |
| 1234 |
|
| 1235 |
<varlistentry> |
| 1236 |
<term><option>-p</option></term> |
| 1237 |
<term><option>--port=</option></term> |
| 1238 |
|
| 1239 |
<listitem><para>If private networking is enabled, maps an IP |
| 1240 |
port on the host onto an IP port on the container. Takes a |
| 1241 |
protocol specifier (either <literal>tcp</literal> or |
| 1242 |
<literal>udp</literal>), separated by a colon from a host port |
| 1243 |
number in the range 1 to 65535, separated by a colon from a |
| 1244 |
container port number in the range from 1 to 65535. The |
| 1245 |
protocol specifier and its separating colon may be omitted, in |
| 1246 |
which case <literal>tcp</literal> is assumed. The container |
| 1247 |
port number and its colon may be omitted, in which case the |
| 1248 |
same port as the host port is implied. This option is only |
| 1249 |
supported if private networking is used, such as with |
| 1250 |
<option>--network-veth</option>, <option>--network-zone=</option> |
| 1251 |
<option>--network-bridge=</option>.</para> |
| 1252 |
|
| 1253 |
<xi:include href="version-info.xml" xpointer="v219"/></listitem> |
| 1254 |
</varlistentry> |
| 1255 |
</variablelist> |
| 1256 |
|
| 1257 |
</refsect2><refsect2> |
| 1258 |
<title>Security Options</title> |
| 1259 |
|
| 1260 |
<variablelist> |
| 1261 |
<varlistentry> |
| 1262 |
<term><option>--capability=</option></term> |
| 1263 |
|
| 1264 |
<listitem><para>List one or more additional capabilities to grant the container. Takes a |
| 1265 |
comma-separated list of capability names, see <citerefentry |
| 1266 |
project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry> |
| 1267 |
for more information. Note that the following capabilities will be granted in any way: |
| 1268 |
<constant>CAP_AUDIT_CONTROL</constant>, <constant>CAP_AUDIT_WRITE</constant>, |
| 1269 |
<constant>CAP_CHOWN</constant>, <constant>CAP_DAC_OVERRIDE</constant>, |
| 1270 |
<constant>CAP_DAC_READ_SEARCH</constant>, <constant>CAP_FOWNER</constant>, |
| 1271 |
<constant>CAP_FSETID</constant>, <constant>CAP_IPC_OWNER</constant>, <constant>CAP_KILL</constant>, |
| 1272 |
<constant>CAP_LEASE</constant>, <constant>CAP_LINUX_IMMUTABLE</constant>, |
| 1273 |
<constant>CAP_MKNOD</constant>, <constant>CAP_NET_BIND_SERVICE</constant>, |
| 1274 |
<constant>CAP_NET_BROADCAST</constant>, <constant>CAP_NET_RAW</constant>, |
| 1275 |
<constant>CAP_SETFCAP</constant>, <constant>CAP_SETGID</constant>, <constant>CAP_SETPCAP</constant>, |
| 1276 |
<constant>CAP_SETUID</constant>, <constant>CAP_SYS_ADMIN</constant>, |
| 1277 |
<constant>CAP_SYS_BOOT</constant>, <constant>CAP_SYS_CHROOT</constant>, |
| 1278 |
<constant>CAP_SYS_NICE</constant>, <constant>CAP_SYS_PTRACE</constant>, |
| 1279 |
<constant>CAP_SYS_RESOURCE</constant>, <constant>CAP_SYS_TTY_CONFIG</constant>. Also |
| 1280 |
<constant>CAP_NET_ADMIN</constant> is retained if <option>--private-network</option> is specified. |
| 1281 |
If the special value <literal>all</literal> is passed, all capabilities are retained.</para> |
| 1282 |
|
| 1283 |
<para>If the special value of <literal>help</literal> is passed, the program will print known |
| 1284 |
capability names and exit.</para> |
| 1285 |
|
| 1286 |
<para>This option sets the bounding set of capabilities which |
| 1287 |
also limits the ambient capabilities as given with the |
| 1288 |
<option>--ambient-capability=</option>.</para> |
| 1289 |
|
| 1290 |
<xi:include href="version-info.xml" xpointer="v186"/></listitem> |
| 1291 |
</varlistentry> |
| 1292 |
|
| 1293 |
<varlistentry> |
| 1294 |
<term><option>--drop-capability=</option></term> |
| 1295 |
|
| 1296 |
<listitem><para>Specify one or more additional capabilities to |
| 1297 |
drop for the container. This allows running the container with |
| 1298 |
fewer capabilities than the default (see |
| 1299 |
above).</para> |
| 1300 |
|
| 1301 |
<para>If the special value of <literal>help</literal> is passed, the program will print known |
| 1302 |
capability names and exit.</para> |
| 1303 |
|
| 1304 |
<para>This option sets the bounding set of capabilities which |
| 1305 |
also limits the ambient capabilities as given with the |
| 1306 |
<option>--ambient-capability=</option>.</para> |
| 1307 |
|
| 1308 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 1309 |
</varlistentry> |
| 1310 |
|
| 1311 |
<varlistentry> |
| 1312 |
<term><option>--ambient-capability=</option></term> |
| 1313 |
|
| 1314 |
<listitem><para>Specify one or more additional capabilities to |
| 1315 |
pass in the inheritable and ambient set to the program started |
| 1316 |
within the container. The value <literal>all</literal> is not |
| 1317 |
supported for this setting.</para> |
| 1318 |
|
| 1319 |
<para>All capabilities specified here must be in the set |
| 1320 |
allowed with the <option>--capability=</option> and |
| 1321 |
<option>--drop-capability=</option> options. Otherwise, an |
| 1322 |
error message will be shown.</para> |
| 1323 |
|
| 1324 |
<para>This option cannot be combined with the boot mode of the |
| 1325 |
container (as requested via <option>--boot</option>).</para> |
| 1326 |
|
| 1327 |
<para>If the special value of <literal>help</literal> is |
| 1328 |
passed, the program will print known capability names and |
| 1329 |
exit.</para> |
| 1330 |
|
| 1331 |
<xi:include href="version-info.xml" xpointer="v248"/></listitem> |
| 1332 |
</varlistentry> |
| 1333 |
|
| 1334 |
<varlistentry> |
| 1335 |
<term><option>--no-new-privileges=</option></term> |
| 1336 |
|
| 1337 |
<listitem><para>Takes a boolean argument. Specifies the value of the |
| 1338 |
<constant>PR_SET_NO_NEW_PRIVS</constant> flag for the container payload. Defaults to off. When turned |
| 1339 |
on the payload code of the container cannot acquire new privileges, i.e. the "setuid" file bit as |
| 1340 |
well as file system capabilities will not have an effect anymore. See <citerefentry |
| 1341 |
project='man-pages'><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> for |
| 1342 |
details about this flag. </para> |
| 1343 |
|
| 1344 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1345 |
</varlistentry> |
| 1346 |
|
| 1347 |
<varlistentry> |
| 1348 |
<term><option>--system-call-filter=</option></term> <listitem><para>Alter the system call filter |
| 1349 |
applied to containers. Takes a space-separated list of system call names or group names (the latter |
| 1350 |
prefixed with <literal>@</literal>, as listed by the <command>syscall-filter</command> command of |
| 1351 |
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>). Passed |
| 1352 |
system calls will be permitted. The list may optionally be prefixed by <literal>~</literal>, in which |
| 1353 |
case all listed system calls are prohibited. If this command line option is used multiple times the |
| 1354 |
configured lists are combined. If both a positive and a negative list (that is one system call list |
| 1355 |
without and one with the <literal>~</literal> prefix) are configured, the negative list takes |
| 1356 |
precedence over the positive list. Note that <command>systemd-nspawn</command> always implements a |
| 1357 |
system call allow list (as opposed to a deny list!), and this command line option hence adds or |
| 1358 |
removes entries from the default allow list, depending on the <literal>~</literal> prefix. Note that |
| 1359 |
the applied system call filter is also altered implicitly if additional capabilities are passed using |
| 1360 |
the <command>--capabilities=</command>.</para> |
| 1361 |
|
| 1362 |
<xi:include href="version-info.xml" xpointer="v235"/></listitem> |
| 1363 |
</varlistentry> |
| 1364 |
|
| 1365 |
<varlistentry> |
| 1366 |
<term><option>--restrict-address-families=</option></term> |
| 1367 |
|
| 1368 |
<listitem><para>Restrict the socket address families accessible to the container. Takes a |
| 1369 |
space-separated list of address family names, such as <constant>AF_INET</constant>, |
| 1370 |
<constant>AF_INET6</constant> or <constant>AF_UNIX</constant>. When prefixed with |
| 1371 |
<literal>~</literal> the listed address families will be prohibited, otherwise they will be permitted |
| 1372 |
(allowlisted). Use the special value <literal>none</literal> to prohibit all address families. This |
| 1373 |
option may be specified more than once, in which case the configured lists are combined. If both a |
| 1374 |
positive and a negative list are configured, the negative list takes precedence over the positive |
| 1375 |
list.</para> |
| 1376 |
|
| 1377 |
<para>Note that currently this option defaults to no restrictions, i.e. all address families are |
| 1378 |
accessible. In a future version of systemd, the default will be changed to restrict address families to |
| 1379 |
<constant>AF_INET</constant>, <constant>AF_INET6</constant> and <constant>AF_UNIX</constant>. Use |
| 1380 |
<option>--restrict-address-families=</option> (with an empty argument) or set |
| 1381 |
<varname>RestrictAddressFamilies=</varname> in a <filename>.nspawn</filename> file to opt out of |
| 1382 |
filtering explicitly.</para> |
| 1383 |
|
| 1384 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 1385 |
</varlistentry> |
| 1386 |
|
| 1387 |
<varlistentry> |
| 1388 |
<term><option>-Z</option></term> |
| 1389 |
<term><option>--selinux-context=</option></term> |
| 1390 |
|
| 1391 |
<listitem><para>Sets the SELinux security context to be used |
| 1392 |
to label processes in the container.</para> |
| 1393 |
|
| 1394 |
<xi:include href="version-info.xml" xpointer="v209"/> |
| 1395 |
</listitem> |
| 1396 |
</varlistentry> |
| 1397 |
|
| 1398 |
<varlistentry> |
| 1399 |
<term><option>-L</option></term> |
| 1400 |
<term><option>--selinux-apifs-context=</option></term> |
| 1401 |
|
| 1402 |
<listitem><para>Sets the SELinux security context to be used |
| 1403 |
to label files in the virtual API file systems in the |
| 1404 |
container.</para> |
| 1405 |
|
| 1406 |
<xi:include href="version-info.xml" xpointer="v209"/> |
| 1407 |
</listitem> |
| 1408 |
</varlistentry> |
| 1409 |
</variablelist> |
| 1410 |
|
| 1411 |
</refsect2><refsect2> |
| 1412 |
<title>Resource Options</title> |
| 1413 |
|
| 1414 |
<variablelist> |
| 1415 |
|
| 1416 |
<varlistentry> |
| 1417 |
<term><option>--rlimit=</option></term> |
| 1418 |
|
| 1419 |
<listitem><para>Sets the specified POSIX resource limit for the container payload. Expects an assignment of the |
| 1420 |
form |
| 1421 |
<literal><replaceable>LIMIT</replaceable>=<replaceable>SOFT</replaceable>:<replaceable>HARD</replaceable></literal> |
| 1422 |
or <literal><replaceable>LIMIT</replaceable>=<replaceable>VALUE</replaceable></literal>, where |
| 1423 |
<replaceable>LIMIT</replaceable> should refer to a resource limit type, such as |
| 1424 |
<constant>RLIMIT_NOFILE</constant> or <constant>RLIMIT_NICE</constant>. The <replaceable>SOFT</replaceable> and |
| 1425 |
<replaceable>HARD</replaceable> fields should refer to the numeric soft and hard resource limit values. If the |
| 1426 |
second form is used, <replaceable>VALUE</replaceable> may specify a value that is used both as soft and hard |
| 1427 |
limit. In place of a numeric value the special string <literal>infinity</literal> may be used to turn off |
| 1428 |
resource limiting for the specific type of resource. This command line option may be used multiple times to |
| 1429 |
control limits on multiple limit types. If used multiple times for the same limit type, the last use |
| 1430 |
wins. For details about resource limits see <citerefentry |
| 1431 |
project='man-pages'><refentrytitle>setrlimit</refentrytitle><manvolnum>2</manvolnum></citerefentry>. By default |
| 1432 |
resource limits for the container's init process (PID 1) are set to the same values the Linux kernel originally |
| 1433 |
passed to the host init system. Note that some resource limits are enforced on resources counted per user, in |
| 1434 |
particular <constant>RLIMIT_NPROC</constant>. This means that unless user namespacing is deployed |
| 1435 |
(i.e. <option>--private-users=</option> is used, see above), any limits set will be applied to the resource |
| 1436 |
usage of the same user on all local containers as well as the host. This means particular care needs to be |
| 1437 |
taken with these limits as they might be triggered by possibly less trusted code. Example: |
| 1438 |
<literal>--rlimit=RLIMIT_NOFILE=8192:16384</literal>.</para> |
| 1439 |
|
| 1440 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1441 |
</varlistentry> |
| 1442 |
|
| 1443 |
<varlistentry> |
| 1444 |
<term><option>--oom-score-adjust=</option></term> |
| 1445 |
|
| 1446 |
<listitem><para>Changes the OOM ("Out Of Memory") score adjustment value for the container payload. This controls |
| 1447 |
<filename>/proc/self/oom_score_adj</filename> which influences the preference with which this container is |
| 1448 |
terminated when memory becomes scarce. For details see <citerefentry |
| 1449 |
project='man-pages'><refentrytitle>proc</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Takes an |
| 1450 |
integer in the range -1000…1000.</para> |
| 1451 |
|
| 1452 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1453 |
</varlistentry> |
| 1454 |
|
| 1455 |
<varlistentry> |
| 1456 |
<term><option>--cpu-affinity=</option></term> |
| 1457 |
|
| 1458 |
<listitem><para>Controls the CPU affinity of the container payload. Takes a comma separated list of CPU numbers |
| 1459 |
or number ranges (the latter's start and end value separated by dashes). See <citerefentry |
| 1460 |
project='man-pages'><refentrytitle>sched_setaffinity</refentrytitle><manvolnum>2</manvolnum></citerefentry> for |
| 1461 |
details.</para> |
| 1462 |
|
| 1463 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1464 |
</varlistentry> |
| 1465 |
|
| 1466 |
<varlistentry> |
| 1467 |
<term><option>--personality=</option></term> |
| 1468 |
|
| 1469 |
<listitem><para>Control the architecture ("personality") |
| 1470 |
reported by |
| 1471 |
<citerefentry project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry> |
| 1472 |
in the container. Currently, only <literal>x86</literal> and |
| 1473 |
<literal>x86-64</literal> are supported. This is useful when |
| 1474 |
running a 32-bit container on a 64-bit host. If this setting |
| 1475 |
is not used, the personality reported in the container is the |
| 1476 |
same as the one reported on the host.</para> |
| 1477 |
|
| 1478 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 1479 |
</varlistentry> |
| 1480 |
</variablelist> |
| 1481 |
|
| 1482 |
</refsect2><refsect2> |
| 1483 |
<title>Integration Options</title> |
| 1484 |
|
| 1485 |
<variablelist> |
| 1486 |
<varlistentry> |
| 1487 |
<term><option>--resolv-conf=</option></term> |
| 1488 |
|
| 1489 |
<listitem><para>Configures how <filename>/etc/resolv.conf</filename> inside of the container shall be |
| 1490 |
handled (i.e. DNS configuration synchronization from host to container). Takes one of |
| 1491 |
<literal>off</literal>, <literal>copy-host</literal>, <literal>copy-static</literal>, |
| 1492 |
<literal>copy-uplink</literal>, <literal>copy-stub</literal>, <literal>replace-host</literal>, |
| 1493 |
<literal>replace-static</literal>, <literal>replace-uplink</literal>, |
| 1494 |
<literal>replace-stub</literal>, <literal>bind-host</literal>, <literal>bind-static</literal>, |
| 1495 |
<literal>bind-uplink</literal>, <literal>bind-stub</literal>, <literal>delete</literal> or |
| 1496 |
<literal>auto</literal>.</para> |
| 1497 |
|
| 1498 |
<para>If set to <literal>off</literal> the <filename>/etc/resolv.conf</filename> file in the |
| 1499 |
container is left as it is included in the image, and neither modified nor bind mounted over.</para> |
| 1500 |
|
| 1501 |
<para>If set to <literal>copy-host</literal>, the <filename>/etc/resolv.conf</filename> file from the |
| 1502 |
host is copied into the container, unless the file exists already and is not a regular file (e.g. a |
| 1503 |
symlink). Similarly, if <literal>replace-host</literal> is used the file is copied, replacing any |
| 1504 |
existing inode, including symlinks. Similarly, if <literal>bind-host</literal> is used, the file is |
| 1505 |
bind mounted from the host into the container.</para> |
| 1506 |
|
| 1507 |
<para>If set to <literal>copy-static</literal>, <literal>replace-static</literal> or |
| 1508 |
<literal>bind-static</literal> the static <filename>resolv.conf</filename> file supplied with |
| 1509 |
<citerefentry><refentrytitle>systemd-resolved.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1510 |
(specifically: <filename>/usr/lib/systemd/resolv.conf</filename>) is copied or bind mounted into the |
| 1511 |
container.</para> |
| 1512 |
|
| 1513 |
<para>If set to <literal>copy-uplink</literal>, <literal>replace-uplink</literal> or |
| 1514 |
<literal>bind-uplink</literal> the uplink <filename>resolv.conf</filename> file managed by |
| 1515 |
<filename>systemd-resolved.service</filename> (specifically: |
| 1516 |
<filename>/run/systemd/resolve/resolv.conf</filename>) is copied or bind mounted into the |
| 1517 |
container.</para> |
| 1518 |
|
| 1519 |
<para>If set to <literal>copy-stub</literal>, <literal>replace-stub</literal> or |
| 1520 |
<literal>bind-stub</literal> the stub <filename>resolv.conf</filename> file managed by |
| 1521 |
<filename>systemd-resolved.service</filename> (specifically: |
| 1522 |
<filename>/run/systemd/resolve/stub-resolv.conf</filename>) is copied or bind mounted into the |
| 1523 |
container.</para> |
| 1524 |
|
| 1525 |
<para>If set to <literal>delete</literal> the <filename>/etc/resolv.conf</filename> file in the |
| 1526 |
container is deleted if it exists.</para> |
| 1527 |
|
| 1528 |
<para>Finally, if set to <literal>auto</literal> the file is left as it is if private networking is |
| 1529 |
turned on (see <option>--private-network</option>). Otherwise, if |
| 1530 |
<filename>systemd-resolved.service</filename> is running its stub <filename>resolv.conf</filename> |
| 1531 |
file is used, and if not the host's <filename>/etc/resolv.conf</filename> file. In the latter cases |
| 1532 |
the file is copied if the image is writable, and bind mounted otherwise.</para> |
| 1533 |
|
| 1534 |
<para>It's recommended to use <literal>copy-…</literal> or <literal>replace-…</literal> if the |
| 1535 |
container shall be able to make changes to the DNS configuration on its own, deviating from the |
| 1536 |
host's settings. Otherwise, <literal>bind</literal> is preferable, as it means direct changes to |
| 1537 |
<filename>/etc/resolv.conf</filename> in the container are not allowed, as it is a read-only bind |
| 1538 |
mount (but note that if the container has enough privileges, it might simply go ahead and unmount the |
| 1539 |
bind mount anyway). Note that both if the file is bind mounted and if it is copied no further |
| 1540 |
propagation of configuration is generally done after the one-time early initialization (this is |
| 1541 |
because the file is usually updated through copying and renaming). Defaults to |
| 1542 |
<literal>auto</literal>.</para> |
| 1543 |
|
| 1544 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1545 |
</varlistentry> |
| 1546 |
|
| 1547 |
<varlistentry> |
| 1548 |
<term><option>--timezone=</option></term> |
| 1549 |
|
| 1550 |
<listitem><para>Configures how <filename>/etc/localtime</filename> inside of the container |
| 1551 |
(i.e. local timezone synchronization from host to container) shall be handled. Takes one of |
| 1552 |
<literal>off</literal>, <literal>copy</literal>, <literal>bind</literal>, <literal>symlink</literal>, |
| 1553 |
<literal>delete</literal> or <literal>auto</literal>. If set to <literal>off</literal> the |
| 1554 |
<filename>/etc/localtime</filename> file in the container is left as it is included in the image, and |
| 1555 |
neither modified nor bind mounted over. If set to <literal>copy</literal> the |
| 1556 |
<filename>/etc/localtime</filename> file of the host is copied into the container. Similarly, if |
| 1557 |
<literal>bind</literal> is used, the file is bind mounted from the host into the container. If set to |
| 1558 |
<literal>symlink</literal>, a symlink is created pointing from <filename>/etc/localtime</filename> in |
| 1559 |
the container to the timezone file in the container that matches the timezone setting on the host. If |
| 1560 |
set to <literal>delete</literal>, the file in the container is deleted, should it exist. If set to |
| 1561 |
<literal>auto</literal> and the <filename>/etc/localtime</filename> file of the host is a symlink, |
| 1562 |
then <literal>symlink</literal> mode is used, and <literal>copy</literal> otherwise, except if the |
| 1563 |
image is read-only in which case <literal>bind</literal> is used instead. Defaults to |
| 1564 |
<literal>auto</literal>.</para> |
| 1565 |
|
| 1566 |
<xi:include href="version-info.xml" xpointer="v239"/></listitem> |
| 1567 |
</varlistentry> |
| 1568 |
|
| 1569 |
<varlistentry> |
| 1570 |
<term><option>--link-journal=</option></term> |
| 1571 |
|
| 1572 |
<listitem><para>Control whether the container's journal shall |
| 1573 |
be made visible to the host system. If enabled, allows viewing |
| 1574 |
the container's journal files from the host (but not vice |
| 1575 |
versa). Takes one of <literal>no</literal>, |
| 1576 |
<literal>host</literal>, <literal>try-host</literal>, |
| 1577 |
<literal>guest</literal>, <literal>try-guest</literal>, |
| 1578 |
<literal>auto</literal>. If <literal>no</literal>, the journal |
| 1579 |
is not linked. If <literal>host</literal>, the journal files |
| 1580 |
are stored on the host file system (beneath |
| 1581 |
<filename>/var/log/journal/<replaceable>machine-id</replaceable></filename>) |
| 1582 |
and the subdirectory is bind-mounted into the container at the |
| 1583 |
same location. If <literal>guest</literal>, the journal files |
| 1584 |
are stored on the guest file system (beneath |
| 1585 |
<filename>/var/log/journal/<replaceable>machine-id</replaceable></filename>) |
| 1586 |
and the subdirectory is symlinked into the host at the same |
| 1587 |
location. <literal>try-host</literal> and |
| 1588 |
<literal>try-guest</literal> do the same but do not fail if |
| 1589 |
the host does not have persistent journaling enabled, or if |
| 1590 |
the container is in the <option>--ephemeral</option> mode. If |
| 1591 |
<literal>auto</literal> (the default), and the right |
| 1592 |
subdirectory of <filename>/var/log/journal</filename> exists, |
| 1593 |
it will be bind mounted into the container. If the |
| 1594 |
subdirectory does not exist, no linking is performed. |
| 1595 |
Effectively, booting a container once with |
| 1596 |
<literal>guest</literal> or <literal>host</literal> will link |
| 1597 |
the journal persistently if further on the default of |
| 1598 |
<literal>auto</literal> is used.</para> |
| 1599 |
|
| 1600 |
<para>Note that <option>--link-journal=try-guest</option> is the default if the |
| 1601 |
<filename>[email protected]</filename> template unit file is used.</para> |
| 1602 |
|
| 1603 |
<xi:include href="version-info.xml" xpointer="v187"/></listitem> |
| 1604 |
</varlistentry> |
| 1605 |
|
| 1606 |
<varlistentry> |
| 1607 |
<term><option>-j</option></term> |
| 1608 |
|
| 1609 |
<listitem><para>Equivalent to |
| 1610 |
<option>--link-journal=try-guest</option>.</para> |
| 1611 |
|
| 1612 |
<xi:include href="version-info.xml" xpointer="v187"/></listitem> |
| 1613 |
</varlistentry> |
| 1614 |
|
| 1615 |
<varlistentry> |
| 1616 |
<term><option>--forward-journal=</option></term> |
| 1617 |
|
| 1618 |
<listitem><para>Forward the container's journal to the host by starting |
| 1619 |
<citerefentry><refentrytitle>systemd-journal-remote</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1620 |
listening on a Unix socket that is bind-mounted into the container. The container's |
| 1621 |
<citerefentry><refentrytitle>systemd-journald</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1622 |
connects to the socket via the <varname>journal.forward_to_socket</varname> credential and streams |
| 1623 |
journal entries to the host in real-time. Takes a path to a journal file or directory where the received |
| 1624 |
entries will be stored. If the path ends in <literal>.journal</literal>, entries are written to a single |
| 1625 |
file; otherwise, entries are split per host into the specified directory.</para> |
| 1626 |
|
| 1627 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 1628 |
</varlistentry> |
| 1629 |
|
| 1630 |
<varlistentry> |
| 1631 |
<term><option>--forward-journal-max-use=<replaceable>BYTES</replaceable></option></term> |
| 1632 |
<term><option>--forward-journal-keep-free=<replaceable>BYTES</replaceable></option></term> |
| 1633 |
<term><option>--forward-journal-max-file-size=<replaceable>BYTES</replaceable></option></term> |
| 1634 |
<term><option>--forward-journal-max-files=<replaceable>N</replaceable></option></term> |
| 1635 |
|
| 1636 |
<listitem><para>These options configure the corresponding settings of |
| 1637 |
<citerefentry><refentrytitle>systemd-journal-remote</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1638 |
when forwarding journal entries from the container. See |
| 1639 |
<citerefentry><refentrytitle>journal-remote.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 1640 |
for the descriptions of these settings.</para> |
| 1641 |
|
| 1642 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 1643 |
</varlistentry> |
| 1644 |
|
| 1645 |
</variablelist> |
| 1646 |
|
| 1647 |
</refsect2><refsect2> |
| 1648 |
<title>Mount Options</title> |
| 1649 |
|
| 1650 |
<variablelist> |
| 1651 |
|
| 1652 |
<varlistentry> |
| 1653 |
<term><option>--bind=</option></term> |
| 1654 |
<term><option>--bind-ro=</option></term> |
| 1655 |
|
| 1656 |
<listitem><para>Bind mount a file or directory from the host into the container. Takes one of: a path |
| 1657 |
argument — in which case the specified path will be mounted from the host to the same path in the container, or |
| 1658 |
a colon-separated pair of paths — in which case the first specified path is the source in the host, and the |
| 1659 |
second path is the destination in the container, or a colon-separated triple of source path, destination path |
| 1660 |
and mount options. The source path may optionally be prefixed with a <literal>+</literal> character. If so, the |
| 1661 |
source path is taken relative to the image's root directory. This permits setting up bind mounts within the |
| 1662 |
container image. The source path may be specified as empty string, in which case a temporary directory below |
| 1663 |
the host's <filename>/var/tmp/</filename> directory is used. It is automatically removed when the container is |
| 1664 |
shut down. If the source path is not absolute, it is resolved relative to the current working directory. |
| 1665 |
The <option>--bind-ro=</option> option creates read-only bind mounts. Backslash escapes are interpreted, |
| 1666 |
so <literal>\:</literal> may be used to embed colons in either path. This option may be specified |
| 1667 |
multiple times for creating multiple independent bind mount points.</para> |
| 1668 |
|
| 1669 |
<para>Mount options are comma-separated. <option>rbind</option> and <option>norbind</option> control whether |
| 1670 |
to create a recursive or a regular bind mount. Defaults to <option>rbind</option>. <option>noidmap</option>, |
| 1671 |
<option>idmap</option>, <option>rootidmap</option> and <option>owneridmap</option> control ID mapping.</para> |
| 1672 |
|
| 1673 |
<para>Using <option>idmap</option>, <option>rootidmap</option> or <option>owneridmap</option> requires support |
| 1674 |
by the source filesystem for user/group ID mapped mounts. Defaults to <option>noidmap</option>. With |
| 1675 |
<option>x</option> being the container's UID range offset, <option>y</option> being the length of the |
| 1676 |
container's UID range, and <option>p</option> being the owner UID of the bind mount source inode on the host: |
| 1677 |
|
| 1678 |
<itemizedlist> |
| 1679 |
<listitem><para>If <option>noidmap</option> is used, any user <option>z</option> in the range |
| 1680 |
<option>0 … y</option> seen from inside of the container is mapped to <option>x + z</option> in the |
| 1681 |
<option>x … x + y</option> range on the host. Other host users are mapped to |
| 1682 |
<option>nobody</option> inside the container.</para></listitem> |
| 1683 |
|
| 1684 |
<listitem><para>If <option>idmap</option> is used, any user <option>z</option> in the UID range |
| 1685 |
<option>0 … y</option> as seen from inside the container is mapped to the same <option>z</option> |
| 1686 |
in the same <option>0 … y</option> range on the host. Other host users are mapped to |
| 1687 |
<option>nobody</option> inside the container.</para></listitem> |
| 1688 |
|
| 1689 |
<listitem><para>If <option>rootidmap</option> is used, the user <option>0</option> seen from inside |
| 1690 |
of the container is mapped to <option>p</option> on the host. Other host users are mapped to |
| 1691 |
<option>nobody</option> inside the container.</para></listitem> |
| 1692 |
|
| 1693 |
<listitem><para>If <option>owneridmap</option> is used, the owner of the target directory inside of the |
| 1694 |
container is mapped to <option>p</option> on the host. Other host users are mapped to |
| 1695 |
<option>nobody</option> inside the container.</para></listitem> |
| 1696 |
</itemizedlist></para> |
| 1697 |
|
| 1698 |
<para>Whichever ID mapping option is used, the same mapping will be used for users and groups IDs. If |
| 1699 |
<option>rootidmap</option> or <option>owneridmap</option> are used, the group owning the bind mounted directory |
| 1700 |
will have no effect.</para> |
| 1701 |
|
| 1702 |
<para>Note that when this option is used in combination with <option>--private-users</option>, the resulting |
| 1703 |
mount points will be owned by the <constant>nobody</constant> user. That's because the mount and its files and |
| 1704 |
directories continue to be owned by the relevant host users and groups, which do not exist in the container, |
| 1705 |
and thus show up under the wildcard UID 65534 (nobody). If such bind mounts are created, it is recommended to |
| 1706 |
make them read-only, using <option>--bind-ro=</option>. Alternatively you can use the "idmap" mount option to |
| 1707 |
map the filesystem IDs.</para> |
| 1708 |
|
| 1709 |
<xi:include href="version-info.xml" xpointer="v198"/></listitem> |
| 1710 |
</varlistentry> |
| 1711 |
|
| 1712 |
<varlistentry> |
| 1713 |
<term><option>--bind-user=</option></term> |
| 1714 |
|
| 1715 |
<listitem><para>Binds the home directory of the specified user on the host into the container. Takes |
| 1716 |
the name of an existing user on the host as argument. May be used multiple times to bind multiple |
| 1717 |
users into the container. This does two things:</para> |
| 1718 |
|
| 1719 |
<orderedlist> |
| 1720 |
<listitem><para>The user's home directory is bind mounted from the host into |
| 1721 |
<filename>/run/host/home/</filename>, using an idmapped mount to map the host user's UID/GID to its |
| 1722 |
assigned UID/GID in the container.</para></listitem> |
| 1723 |
|
| 1724 |
<listitem><para>A JSON user and group record is generated in <filename>/run/userdb/</filename> that |
| 1725 |
describes the mapped user. It contains a minimized representation of the host's user record, |
| 1726 |
adjusted to the UID/GID and home directory path assigned to the user in the container. The |
| 1727 |
<citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1728 |
glibc NSS module will pick up these records from there and make them available in the container's |
| 1729 |
user/group databases.</para></listitem> |
| 1730 |
</orderedlist> |
| 1731 |
|
| 1732 |
<para>The combination of the two operations above ensures that it is possible to log into the |
| 1733 |
container using the same account information as on the host. The user is only mapped transiently, |
| 1734 |
while the container is running, and the mapping itself does not result in persistent changes to the |
| 1735 |
container (except maybe for log messages generated at login time, and similar). Note that in |
| 1736 |
particular the UID/GID assignment in the container is not made persistently. If the user is mapped |
| 1737 |
transiently, it is best to not allow the user to make persistent changes to the container. If the |
| 1738 |
user leaves files or directories owned by the user, and those UIDs/GIDs are reused during later |
| 1739 |
container invocations (possibly with a different <option>--bind-user=</option> mapping), those files |
| 1740 |
and directories will be accessible to the "new" user.</para> |
| 1741 |
|
| 1742 |
<para>The user/group record mapping only works if the container contains systemd 249 or newer, with |
| 1743 |
<command>nss-systemd</command> properly configured in <filename>nsswitch.conf</filename>. See |
| 1744 |
<citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for |
| 1745 |
details.</para> |
| 1746 |
|
| 1747 |
<para>Note that the user record propagated from the host into the container will contain the UNIX |
| 1748 |
password hash of the user, so that seamless logins in the container are possible. If the container is |
| 1749 |
less trusted than the host it is hence important to use a strong UNIX password hash function |
| 1750 |
(e.g. yescrypt or similar, with the <literal>$y$</literal> hash prefix).</para> |
| 1751 |
|
| 1752 |
<para>When binding a user from the host into the container checks are executed to ensure that the |
| 1753 |
username is not yet known in the container. Moreover, it is checked that the UID/GID allocated for it |
| 1754 |
is not currently defined in the user/group databases of the container. Both checks directly access |
| 1755 |
the container's <filename>/etc/passwd</filename> and <filename>/etc/group</filename>, and thus might |
| 1756 |
not detect existing accounts in other databases.</para> |
| 1757 |
|
| 1758 |
<xi:include href="version-info.xml" xpointer="v249"/></listitem> |
| 1759 |
</varlistentry> |
| 1760 |
|
| 1761 |
<varlistentry> |
| 1762 |
<term><option>--bind-user-shell=</option></term> |
| 1763 |
|
| 1764 |
<listitem><para>When used with <option>--bind-user=</option>, includes the specified shell in the |
| 1765 |
user records of users bound into the container. Takes either a boolean or an absolute path.</para> |
| 1766 |
|
| 1767 |
<itemizedlist> |
| 1768 |
<listitem><para>If false (the default), no shell is passed in the user records for users bound into |
| 1769 |
the container. This causes bound users to the use the container's default shell.</para></listitem> |
| 1770 |
|
| 1771 |
<listitem><para>If true, the shells specified by the host user records are included in the user records of all users bound into the container.</para></listitem> |
| 1772 |
|
| 1773 |
<listitem><para>If passed an absolute path, sets that path as the shell for user records of all users bound into the container.</para></listitem> |
| 1774 |
</itemizedlist> |
| 1775 |
|
| 1776 |
<para>Note: This will not check whether the specified shells exist in the container.</para> |
| 1777 |
|
| 1778 |
<para>This operation is only supported in combination with <option>--bind-user=</option>.</para> |
| 1779 |
|
| 1780 |
<xi:include href="version-info.xml" xpointer="v258"/></listitem> |
| 1781 |
</varlistentry> |
| 1782 |
|
| 1783 |
<varlistentry> |
| 1784 |
<term><option>--bind-user-group=<replaceable>NAME</replaceable></option></term> |
| 1785 |
|
| 1786 |
<listitem><para>When used with <option>--bind-user=</option>, includes the specified group as an |
| 1787 |
auxiliary group in the user records of users bound into the container. Takes a group name.</para> |
| 1788 |
|
| 1789 |
<para>Note: This will not check whether the specified groups exist in the container.</para> |
| 1790 |
|
| 1791 |
<para>This operation is only supported in combination with <option>--bind-user=</option>.</para> |
| 1792 |
|
| 1793 |
<xi:include href="version-info.xml" xpointer="v259"/></listitem> |
| 1794 |
</varlistentry> |
| 1795 |
|
| 1796 |
<varlistentry> |
| 1797 |
<term><option>--inaccessible=</option></term> |
| 1798 |
|
| 1799 |
<listitem><para>Make the specified path inaccessible in the container. This over-mounts the specified path |
| 1800 |
(which must exist in the container) with a file node of the same type that is empty and has the most |
| 1801 |
restrictive access mode supported. This is an effective way to mask files, directories and other file system |
| 1802 |
objects from the container payload. This option may be used more than once in case all specified paths are |
| 1803 |
masked.</para> |
| 1804 |
|
| 1805 |
<xi:include href="version-info.xml" xpointer="v242"/></listitem> |
| 1806 |
</varlistentry> |
| 1807 |
|
| 1808 |
<varlistentry> |
| 1809 |
<term><option>--tmpfs=</option></term> |
| 1810 |
|
| 1811 |
<listitem><para>Mount a tmpfs file system into the container. Takes a single absolute path argument that |
| 1812 |
specifies where to mount the tmpfs instance to (in which case the directory access mode will be chosen as 0755, |
| 1813 |
owned by root/root), or optionally a colon-separated pair of path and mount option string that is used for |
| 1814 |
mounting (in which case the kernel default for access mode and owner will be chosen, unless otherwise |
| 1815 |
specified). Backslash escapes are interpreted in the path, so <literal>\:</literal> may be used to embed colons |
| 1816 |
in the path.</para> |
| 1817 |
|
| 1818 |
<para>Note that this option cannot be used to replace the root file system of the container with a temporary |
| 1819 |
file system. However, the <option>--volatile=</option> option described below provides similar |
| 1820 |
functionality, with a focus on implementing stateless operating system images.</para> |
| 1821 |
|
| 1822 |
<xi:include href="version-info.xml" xpointer="v214"/></listitem> |
| 1823 |
</varlistentry> |
| 1824 |
|
| 1825 |
<varlistentry> |
| 1826 |
<term><option>--overlay=</option></term> |
| 1827 |
<term><option>--overlay-ro=</option></term> |
| 1828 |
|
| 1829 |
<listitem><para>Combine multiple directory trees into one overlay file system and mount it into the |
| 1830 |
container. Takes a list of colon-separated paths to the directory trees to combine and the |
| 1831 |
destination mount point.</para> |
| 1832 |
|
| 1833 |
<para>Backslash escapes are interpreted in the paths, so <literal>\:</literal> may be used to embed |
| 1834 |
colons in the paths.</para> |
| 1835 |
|
| 1836 |
<para>If three or more paths are specified, then the last specified path is the destination mount |
| 1837 |
point in the container, all paths specified before refer to directory trees on the host and are |
| 1838 |
combined in the specified order into one overlay file system. The left-most path is hence the lowest |
| 1839 |
directory tree, the second-to-last path the highest directory tree in the stacking order. If |
| 1840 |
<option>--overlay-ro=</option> is used instead of <option>--overlay=</option>, a read-only overlay |
| 1841 |
file system is created. If a writable overlay file system is created, all changes made to it are |
| 1842 |
written to the highest directory tree in the stacking order, i.e. the second-to-last specified. |
| 1843 |
</para> |
| 1844 |
|
| 1845 |
<para>If only two paths are specified, then the second specified path is used both as the top-level |
| 1846 |
directory tree in the stacking order as seen from the host, as well as the mount point for the |
| 1847 |
overlay file system in the container. At least two paths have to be specified.</para> |
| 1848 |
|
| 1849 |
<para>The source paths may optionally be prefixed with <literal>+</literal> character. If so they are |
| 1850 |
taken relative to the image's root directory. The uppermost source path may also be specified as an |
| 1851 |
empty string, in which case a temporary directory below the host's <filename>/var/tmp/</filename> is |
| 1852 |
used. The directory is removed automatically when the container is shut down. This behaviour is |
| 1853 |
useful in order to make read-only container directories writable while the container is running. For |
| 1854 |
example, use <literal>--overlay=+/var::/var</literal> in order to automatically overlay a writable |
| 1855 |
temporary directory on a read-only <filename>/var/</filename> directory. If a source path is not |
| 1856 |
absolute, it is resolved relative to the current working directory.</para> |
| 1857 |
|
| 1858 |
<para>For details about overlay file systems, see <ulink |
| 1859 |
url="https://docs.kernel.org/filesystems/overlayfs.html">Overlay Filesystem</ulink>. |
| 1860 |
Note that the semantics of overlay file systems are substantially different from normal file systems, |
| 1861 |
in particular regarding reported device and inode information. Device and inode information may |
| 1862 |
change for a file while it is being written to, and processes might see out-of-date versions of files |
| 1863 |
at times. Note that this switch automatically derives the <literal>workdir=</literal> mount option |
| 1864 |
for the overlay file system from the top-level directory tree, making it a sibling of it. It is hence |
| 1865 |
essential that the top-level directory tree is not a mount point itself (since the working directory |
| 1866 |
must be on the same file system as the top-most directory tree). Also note that the |
| 1867 |
<literal>lowerdir=</literal> mount option receives the paths to stack in the opposite order of this |
| 1868 |
switch.</para> |
| 1869 |
|
| 1870 |
<para>Note that this option cannot be used to replace the root file system of the container with an overlay |
| 1871 |
file system. However, the <option>--volatile=</option> option described above provides similar functionality, |
| 1872 |
with a focus on implementing stateless operating system images.</para> |
| 1873 |
|
| 1874 |
<xi:include href="version-info.xml" xpointer="v220"/></listitem> |
| 1875 |
</varlistentry> |
| 1876 |
</variablelist> |
| 1877 |
</refsect2> |
| 1878 |
|
| 1879 |
<refsect2> |
| 1880 |
<title>Input/Output Options</title> |
| 1881 |
|
| 1882 |
<variablelist> |
| 1883 |
<varlistentry> |
| 1884 |
<term><option>--console=<replaceable>MODE</replaceable></option></term> |
| 1885 |
|
| 1886 |
<listitem><para>Configures how to set up standard input, output and error output for the container |
| 1887 |
payload, as well as the <filename>/dev/console</filename> device for the container. Takes one of |
| 1888 |
<option>interactive</option>, <option>read-only</option>, <option>passive</option>, |
| 1889 |
<option>pipe</option> or <option>autopipe</option>. If <option>interactive</option>, a pseudo-TTY is |
| 1890 |
allocated and made available as <filename>/dev/console</filename> in the container. It is then |
| 1891 |
bi-directionally connected to the standard input and output passed to |
| 1892 |
<command>systemd-nspawn</command>. <option>read-only</option> is similar but only the output of the |
| 1893 |
container is propagated and no input from the caller is read. If <option>passive</option>, a pseudo |
| 1894 |
TTY is allocated, but it is not connected anywhere. In <option>pipe</option> mode no pseudo TTY is |
| 1895 |
allocated, but the standard input, output and error output file descriptors passed to |
| 1896 |
<command>systemd-nspawn</command> are passed on — as they are — to the container payload, see the |
| 1897 |
following paragraph. Finally, <option>autopipe</option> mode operates like |
| 1898 |
<option>interactive</option> when <command>systemd-nspawn</command> is invoked on a terminal, and |
| 1899 |
like <option>pipe</option> otherwise. Defaults to <option>interactive</option> if |
| 1900 |
<command>systemd-nspawn</command> is invoked from a terminal, and <option>read-only</option> |
| 1901 |
otherwise.</para> |
| 1902 |
|
| 1903 |
<para>In <option>pipe</option> mode, <filename>/dev/console</filename> will not exist in the |
| 1904 |
container. This means that the container payload generally cannot be a full init system as init |
| 1905 |
systems tend to require <filename>/dev/console</filename> to be available. On the other hand, in this |
| 1906 |
mode container invocations can be used within shell pipelines. This is because intermediary pseudo |
| 1907 |
TTYs do not permit independent bidirectional propagation of the end-of-file (EOF) condition, which is |
| 1908 |
necessary for shell pipelines to work correctly. <emphasis>Note that the <option>pipe</option> mode |
| 1909 |
should be used carefully</emphasis>, as passing arbitrary file descriptors to less trusted container |
| 1910 |
payloads might open up unwanted interfaces for access by the container payload. For example, if a |
| 1911 |
passed file descriptor refers to a TTY of some form, APIs such as <constant>TIOCSTI</constant> may be |
| 1912 |
used to synthesize input that might be used for escaping the container. Hence <option>pipe</option> |
| 1913 |
mode should only be used if the payload is sufficiently trusted or when the standard |
| 1914 |
input/output/error output file descriptors are known safe, for example pipes.</para> |
| 1915 |
|
| 1916 |
<xi:include href="version-info.xml" xpointer="v242"/></listitem> |
| 1917 |
</varlistentry> |
| 1918 |
|
| 1919 |
<varlistentry> |
| 1920 |
<term><option>--pipe</option></term> |
| 1921 |
<term><option>-P</option></term> |
| 1922 |
|
| 1923 |
<listitem><para>Equivalent to <option>--console=pipe</option>.</para> |
| 1924 |
|
| 1925 |
<xi:include href="version-info.xml" xpointer="v242"/></listitem> |
| 1926 |
</varlistentry> |
| 1927 |
|
| 1928 |
<varlistentry> |
| 1929 |
<term><option>--background=<replaceable>COLOR</replaceable></option></term> |
| 1930 |
|
| 1931 |
<listitem><para>Change the terminal background color to the specified ANSI color as long as the |
| 1932 |
container runs. The color specified should be an ANSI X3.64 SGR background color, i.e. strings such |
| 1933 |
as <literal>40</literal>, <literal>41</literal>, …, <literal>47</literal>, <literal>48;2;…</literal>, |
| 1934 |
<literal>48;5;…</literal>. See <ulink |
| 1935 |
url="https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters">ANSI |
| 1936 |
Escape Code (Wikipedia)</ulink> for details. Assign an empty string to disable any coloring.</para> |
| 1937 |
|
| 1938 |
<xi:include href="version-info.xml" xpointer="v256"/> |
| 1939 |
</listitem> |
| 1940 |
</varlistentry> |
| 1941 |
|
| 1942 |
</variablelist> |
| 1943 |
|
| 1944 |
</refsect2> |
| 1945 |
<refsect2> |
| 1946 |
<title>Credentials</title> |
| 1947 |
|
| 1948 |
<variablelist> |
| 1949 |
<varlistentry> |
| 1950 |
<term><option>--load-credential=<replaceable>ID</replaceable>:<replaceable>PATH</replaceable></option></term> |
| 1951 |
<term><option>--set-credential=<replaceable>ID</replaceable>:<replaceable>VALUE</replaceable></option></term> |
| 1952 |
|
| 1953 |
<listitem><para>Pass a credential to the container. These two options correspond to the |
| 1954 |
<varname>LoadCredential=</varname> and <varname>SetCredential=</varname> settings in unit files. See |
| 1955 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 1956 |
details about these concepts, as well as the syntax of the option's arguments.</para> |
| 1957 |
|
| 1958 |
<para>Note: when <command>systemd-nspawn</command> runs as systemd system service it can propagate |
| 1959 |
the credentials it received via <varname>LoadCredential=</varname>/<varname>SetCredential=</varname> |
| 1960 |
to the container payload. A systemd service manager running as PID 1 in the container can further |
| 1961 |
propagate them to the services it itself starts. It is thus possible to easily propagate credentials |
| 1962 |
from a parent service manager to a container manager service and from there into its payload. This |
| 1963 |
can even be done recursively.</para> |
| 1964 |
|
| 1965 |
<para>In order to embed binary data into the credential data for <option>--set-credential=</option>, |
| 1966 |
use C-style escaping (i.e. <literal>\n</literal> to embed a newline, or <literal>\x00</literal> to |
| 1967 |
embed a <constant>NUL</constant> byte). Note that the invoking shell might already apply unescaping |
| 1968 |
once, hence this might require double escaping!</para> |
| 1969 |
|
| 1970 |
<para>The |
| 1971 |
<citerefentry><refentrytitle>systemd-sysusers.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 1972 |
and |
| 1973 |
<citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 1974 |
services read credentials configured this way for the purpose of configuring the container's root |
| 1975 |
user's password and shell, as well as system locale, keymap and timezone during the first boot |
| 1976 |
process of the container. This is particularly useful in combination with |
| 1977 |
<option>--volatile=yes</option> where every single boot appears as first boot, since configuration |
| 1978 |
applied to <filename>/etc/</filename> is lost on container reboot cycles. See the respective man |
| 1979 |
pages for details. Example:</para> |
| 1980 |
|
| 1981 |
<programlisting># systemd-nspawn -i image.raw \ |
| 1982 |
--volatile=yes \ |
| 1983 |
--set-credential=firstboot.locale:de_DE.UTF-8 \ |
| 1984 |
--set-credential=passwd.hashed-password.root:'$y$j9T$yAuRJu1o5HioZAGDYPU5d.$F64ni6J2y2nNQve90M/p0ZP0ECP/qqzipNyaY9fjGpC' \ |
| 1985 |
-b</programlisting> |
| 1986 |
|
| 1987 |
<para>The above command line will invoke the specified image file <filename>image.raw</filename> in |
| 1988 |
volatile mode, i.e. with empty <filename>/etc/</filename> and <filename>/var/</filename>. The |
| 1989 |
container payload will recognize this as a first boot, and will invoke |
| 1990 |
<filename>systemd-firstboot.service</filename>, which then reads the two passed credentials to |
| 1991 |
configure the system's initial locale and root password.</para> |
| 1992 |
|
| 1993 |
<xi:include href="version-info.xml" xpointer="v247"/> |
| 1994 |
</listitem> |
| 1995 |
</varlistentry> |
| 1996 |
</variablelist> |
| 1997 |
|
| 1998 |
</refsect2><refsect2> |
| 1999 |
<title>Other</title> |
| 2000 |
|
| 2001 |
<variablelist> |
| 2002 |
<varlistentry> |
| 2003 |
<term><option>--system</option></term> |
| 2004 |
<term><option>--user</option></term> |
| 2005 |
|
| 2006 |
<listitem><para>Specify whether to run in system or user scope. This controls which service manager and |
| 2007 |
machined instance to interact with, as well as operational defaults such as user namespace mode and |
| 2008 |
private networking. If neither is specified, <option>--system</option> is implied when running as |
| 2009 |
root, <option>--user</option> otherwise.</para> |
| 2010 |
|
| 2011 |
<para>Note: for backwards compatibility, <option>--user</option> followed by a positional argument |
| 2012 |
is interpreted as the deprecated <option>--user=<replaceable>NAME</replaceable></option> form (now |
| 2013 |
<option>--uid=</option>). To use <option>--user</option> for scope selection when positional |
| 2014 |
arguments follow, separate them with <literal>--</literal>.</para> |
| 2015 |
|
| 2016 |
<xi:include href="version-info.xml" xpointer="v261"/></listitem> |
| 2017 |
</varlistentry> |
| 2018 |
|
| 2019 |
<xi:include href="standard-options.xml" xpointer="no-pager" /> |
| 2020 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 2021 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 2022 |
<xi:include href="standard-options.xml" xpointer="no-ask-password" /> |
| 2023 |
</variablelist> |
| 2024 |
</refsect2> |
| 2025 |
</refsect1> |
| 2026 |
|
| 2027 |
<refsect1> |
| 2028 |
<title>Hotkeys</title> |
| 2029 |
|
| 2030 |
<para>When invoked in interactive mode (i.e. the default <option>--console=interactive</option>), a few |
| 2031 |
special keyboard shortcuts are understood that control the container runtime. These shortcuts need to be |
| 2032 |
typed within 1s to have effect, otherwise they will be forwarded to the container as regular |
| 2033 |
keypresses.</para> |
| 2034 |
|
| 2035 |
<variablelist> |
| 2036 |
<varlistentry> |
| 2037 |
<term>Ctrl-] Ctrl-] Ctrl-]</term> |
| 2038 |
<listitem><para>Immediately terminate the container, killing all processes.</para></listitem> |
| 2039 |
</varlistentry> |
| 2040 |
|
| 2041 |
<varlistentry> |
| 2042 |
<term>Ctrl-] Ctrl-] r</term> |
| 2043 |
<listitem><para>Issue a reboot request to the container.</para> |
| 2044 |
<xi:include href="version-info.xml" xpointer="v258"/></listitem> |
| 2045 |
</varlistentry> |
| 2046 |
|
| 2047 |
<varlistentry> |
| 2048 |
<term>Ctrl-] Ctrl-] p</term> |
| 2049 |
<listitem><para>Issue a shutdown request to the container.</para> |
| 2050 |
<xi:include href="version-info.xml" xpointer="v258"/></listitem> |
| 2051 |
</varlistentry> |
| 2052 |
|
| 2053 |
</variablelist> |
| 2054 |
</refsect1> |
| 2055 |
|
| 2056 |
<xi:include href="common-variables.xml" /> |
| 2057 |
|
| 2058 |
<refsect1> |
| 2059 |
<title>Examples</title> |
| 2060 |
|
| 2061 |
<xi:include href="importctl.xml" xpointer="example-import-tar" /> |
| 2062 |
|
| 2063 |
<example> |
| 2064 |
<title>Build and boot a minimal Fedora distribution in a container</title> |
| 2065 |
|
| 2066 |
<programlisting># dnf -y --releasever=&fedora_latest_version; --installroot=/var/lib/machines/f&fedora_latest_version; \ |
| 2067 |
--use-host-config --setopt=install_weak_deps=0 \ |
| 2068 |
--repo=fedora --repo=updates install \ |
| 2069 |
passwd dnf fedora-release nano util-linux systemd systemd-networkd |
| 2070 |
# systemd-nspawn -bD /var/lib/machines/f&fedora_latest_version;</programlisting> |
| 2071 |
|
| 2072 |
<para>(Omit <parameter>--use-host-config</parameter> when using <command>dnf</command> <= 4.) |
| 2073 |
This installs a minimal Fedora distribution into the directory |
| 2074 |
<filename index="false">/var/lib/machines/f&fedora_latest_version;</filename> |
| 2075 |
and then boots that OS in a namespace container. Because the installation |
| 2076 |
is located underneath the standard <filename>/var/lib/machines/</filename> |
| 2077 |
directory, it is also possible to start the machine using |
| 2078 |
<command>systemd-nspawn -M f&fedora_latest_version;</command>.</para> |
| 2079 |
</example> |
| 2080 |
|
| 2081 |
<example> |
| 2082 |
<title>Spawn a shell in a container of a minimal Debian unstable distribution</title> |
| 2083 |
|
| 2084 |
<programlisting># debootstrap unstable ~/debian-tree/ |
| 2085 |
# systemd-nspawn -D ~/debian-tree/</programlisting> |
| 2086 |
|
| 2087 |
<para>This installs a minimal Debian unstable distribution into |
| 2088 |
the directory <filename>~/debian-tree/</filename> and then |
| 2089 |
spawns a shell from this image in a namespace container.</para> |
| 2090 |
|
| 2091 |
<para><command>debootstrap</command> supports |
| 2092 |
<ulink url="https://www.debian.org">Debian</ulink>, |
| 2093 |
and <ulink url="https://www.ubuntu.com">Ubuntu</ulink> |
| 2094 |
out of the box, so the same command can be used to install any of those. For other |
| 2095 |
distributions from the Debian family, a mirror has to be specified, see |
| 2096 |
<citerefentry project='die-net'><refentrytitle>debootstrap</refentrytitle><manvolnum>8</manvolnum></citerefentry>. |
| 2097 |
</para> |
| 2098 |
</example> |
| 2099 |
|
| 2100 |
<example> |
| 2101 |
<title>Boot a minimal |
| 2102 |
<ulink url="https://www.archlinux.org">Arch Linux</ulink> distribution in a container</title> |
| 2103 |
|
| 2104 |
<programlisting># pacstrap -c ~/arch-tree/ base |
| 2105 |
# systemd-nspawn -bD ~/arch-tree/</programlisting> |
| 2106 |
|
| 2107 |
<para>This installs a minimal Arch Linux distribution into the |
| 2108 |
directory <filename>~/arch-tree/</filename> and then boots an OS |
| 2109 |
in a namespace container in it.</para> |
| 2110 |
</example> |
| 2111 |
|
| 2112 |
<example> |
| 2113 |
<title>Install the |
| 2114 |
<ulink url="https://software.opensuse.org/distributions/tumbleweed">OpenSUSE Tumbleweed</ulink> |
| 2115 |
rolling distribution</title> |
| 2116 |
|
| 2117 |
<programlisting># zypper --root=/var/lib/machines/tumbleweed ar -c \ |
| 2118 |
https://download.opensuse.org/tumbleweed/repo/oss tumbleweed |
| 2119 |
# zypper --root=/var/lib/machines/tumbleweed refresh |
| 2120 |
# zypper --root=/var/lib/machines/tumbleweed install --no-recommends \ |
| 2121 |
systemd shadow zypper openSUSE-release vim |
| 2122 |
# systemd-nspawn -M tumbleweed passwd root |
| 2123 |
# systemd-nspawn -M tumbleweed -b</programlisting> |
| 2124 |
</example> |
| 2125 |
|
| 2126 |
<example> |
| 2127 |
<title>Boot into an ephemeral snapshot of the host system</title> |
| 2128 |
|
| 2129 |
<programlisting># systemd-nspawn -D / -xb</programlisting> |
| 2130 |
|
| 2131 |
<para>This runs a copy of the host system in a snapshot which is removed immediately when the container |
| 2132 |
exits. All file system changes made during runtime will be lost on shutdown, hence.</para> |
| 2133 |
</example> |
| 2134 |
|
| 2135 |
<example> |
| 2136 |
<title>Run a container with SELinux sandbox security contexts</title> |
| 2137 |
|
| 2138 |
<programlisting># chcon system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 -R /srv/container |
| 2139 |
# systemd-nspawn -L system_u:object_r:svirt_sandbox_file_t:s0:c0,c1 \ |
| 2140 |
-Z system_u:system_r:svirt_lxc_net_t:s0:c0,c1 -D /srv/container /bin/sh</programlisting> |
| 2141 |
</example> |
| 2142 |
|
| 2143 |
<example> |
| 2144 |
<title>Run a container with an OSTree deployment</title> |
| 2145 |
|
| 2146 |
<programlisting># systemd-nspawn -b -i ~/image.raw \ |
| 2147 |
--pivot-root=/ostree/deploy/$OS/deploy/$CHECKSUM:/sysroot \ |
| 2148 |
--bind=+/sysroot/ostree/deploy/$OS/var:/var</programlisting> |
| 2149 |
</example> |
| 2150 |
</refsect1> |
| 2151 |
|
| 2152 |
<refsect1> |
| 2153 |
<title>Exit status</title> |
| 2154 |
|
| 2155 |
<para>The exit code of the program executed in the container is |
| 2156 |
returned.</para> |
| 2157 |
</refsect1> |
| 2158 |
|
| 2159 |
<refsect1> |
| 2160 |
<title>See Also</title> |
| 2161 |
<para><simplelist type="inline"> |
| 2162 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 2163 |
<member><citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 2164 |
<member><citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 2165 |
<member><citerefentry project='mankier'><refentrytitle>dnf</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2166 |
<member><citerefentry project='die-net'><refentrytitle>debootstrap</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2167 |
<member><citerefentry project='archlinux'><refentrytitle>pacman</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2168 |
<member><citerefentry project='mankier'><refentrytitle>zypper</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2169 |
<member><citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 2170 |
<member><citerefentry><refentrytitle>machinectl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 2171 |
<member><citerefentry><refentrytitle>importctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 2172 |
<member><citerefentry><refentrytitle>systemd-mountfsd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2173 |
<member><citerefentry><refentrytitle>systemd-nsresourced.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2174 |
<member><citerefentry><refentrytitle>systemd.mstack</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 2175 |
<member><citerefentry project='url'><refentrytitle url='https://btrfs.readthedocs.io/en/latest/btrfs.html'>btrfs</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 2176 |
</simplelist></para> |
| 2177 |
</refsect1> |
| 2178 |
|
| 2179 |
</refentry> |