2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % entities SYSTEM
"custom-entities.ent" >
7 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
9 <refentry id=
"systemd.nspawn">
12 <title>systemd.nspawn
</title>
13 <productname>systemd
</productname>
17 <refentrytitle>systemd.nspawn
</refentrytitle>
18 <manvolnum>5</manvolnum>
22 <refname>systemd.nspawn
</refname>
23 <refpurpose>Container settings
</refpurpose>
27 <para><filename>/etc/systemd/nspawn/
<replaceable>machine
</replaceable>.nspawn
</filename></para>
28 <para><filename>/run/systemd/nspawn/
<replaceable>machine
</replaceable>.nspawn
</filename></para>
29 <para><filename>/var/lib/machines/
<replaceable>machine
</replaceable>.nspawn
</filename></para>
33 <title>Description
</title>
35 <para>An nspawn container settings file (suffix
<filename>.nspawn
</filename>) contains runtime
36 configuration for a local container, and is used used by
37 <citerefentry><refentrytitle>systemd-nspawn
</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
38 Files of this type are named after the containers they define settings for. They are optional, and only
39 required for containers whose execution environment shall differ from the defaults. Files of this type
40 mostly contain settings that may also be set on the
<command>systemd-nspawn
</command> command line, and
41 make it easier to persistently attach specific settings to specific containers. The syntax of these files
42 is inspired by
<filename>.desktop
</filename> files, similarly to other configuration files supported by
43 the systemd project. See
44 <citerefentry><refentrytitle>systemd.syntax
</refentrytitle><manvolnum>7</manvolnum></citerefentry> for an
49 <title><filename>.nspawn
</filename> File Discovery
</title>
51 <para>Files are searched for by appending the
<filename>.nspawn
</filename> suffix to the machine name of
52 the container, as specified with the
<option>--machine=
</option> switch of
53 <command>systemd-nspawn
</command>, or derived from the directory or image file name. This file is first
54 searched for in
<filename>/etc/systemd/nspawn/
</filename> and
55 <filename>/run/systemd/nspawn/
</filename>. If found there, the settings are read and all of them take
56 full effect (but may still be overridden by corresponding command line arguments). Otherwise, the file
57 will then be searched for next to the image file or in the immediate parent of the root directory of the
58 container. If the file is found there, only a subset of the settings will take effect however. All
59 settings that possibly elevate privileges or grant additional access to resources of the host (such as
60 files or directories) are ignored. To which options this applies is documented below.
</para>
62 <para>Persistent settings files created and maintained by the
63 administrator (and thus trusted) should be placed in
64 <filename>/etc/systemd/nspawn/
</filename>, while automatically
65 downloaded (and thus potentially untrusted) settings files are
66 placed in
<filename>/var/lib/machines/
</filename> instead (next to
67 the container images), where their security impact is limited. In
68 order to add privileged settings to
<filename>.nspawn
</filename>
69 files acquired from the image vendor, it is recommended to copy the
70 settings files into
<filename>/etc/systemd/nspawn/
</filename> and
71 edit them there, so that the privileged options become
72 available. The precise algorithm for how the files are searched and
73 interpreted may be configured with
74 <command>systemd-nspawn
</command>'s
<option>--settings=
</option>
76 <citerefentry><refentrytitle>systemd-nspawn
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
81 <title>[Exec] Section Options
</title>
83 <para>Settings files may include an
<literal>[Exec]
</literal>
84 section, which carries various execution parameters:
</para>
86 <variablelist class='nspawn-directives'
>
89 <term><varname>Boot=
</varname></term>
91 <listitem><para>Takes a boolean argument, which defaults to off. If enabled,
<command>systemd-nspawn
</command>
92 will automatically search for an
<filename>init
</filename> executable and invoke it. In this case, the
93 specified parameters using
<varname>Parameters=
</varname> are passed as additional arguments to the
94 <filename>init
</filename> process. This setting corresponds to the
<option>--boot
</option> switch on the
95 <command>systemd-nspawn
</command> command line. This option may not be combined with
96 <varname>ProcessTwo=yes
</varname>. This option is specified by default in the
97 <filename>systemd-nspawn@.service
</filename> template unit.
</para></listitem>
101 <term><varname>Ephemeral=
</varname></term>
103 <listitem><para>Takes a boolean argument, which defaults to off, If enabled, the container is run with
104 a temporary snapshot of its file system that is removed immediately when the container terminates.
105 This is equivalent to the
<option>--ephemeral
</option> command line switch. See
106 <citerefentry><refentrytitle>systemd-nspawn
</refentrytitle><manvolnum>1</manvolnum></citerefentry> for details
107 about the specific options supported.
</para></listitem>
111 <term><varname>ProcessTwo=
</varname></term>
113 <listitem><para>Takes a boolean argument, which defaults to off. If enabled, the specified program is run as
114 PID
2. A stub init process is run as PID
1. This setting corresponds to the
<option>--as-pid2
</option> switch
115 on the
<command>systemd-nspawn
</command> command line. This option may not be combined with
116 <varname>Boot=yes
</varname>.
</para></listitem>
120 <term><varname>Parameters=
</varname></term>
122 <listitem><para>Takes a whitespace-separated list of arguments. Single (
<literal>'
</literal>) and
123 double (
<literal>"</literal>) quotes may be used around arguments with whitespace. This is either a
124 command line, beginning with the binary name to execute, or – if <varname>Boot=</varname> is enabled
125 – the list of arguments to pass to the init process. This setting corresponds to the command line
126 parameters passed on the <command>systemd-nspawn</command> command line.</para>
128 <para>Note: <option>Boot=no</option>, <option>Parameters=a b "c c
"</option> is the same as
129 <command>systemd-nspawn a b "c c
"</command>, and <option>Boot=yes</option>, <option>Parameters=b 'c c'</option>
130 is the same as <command>systemd-nspawn --boot b 'c c'</command>.</para></listitem>
134 <term><varname>Environment=</varname></term>
136 <listitem><para>Takes an environment variable assignment
137 consisting of key and value, separated by
138 <literal>=</literal>. Sets an environment variable for the
139 main process invoked in the container. This setting may be
140 used multiple times to set multiple environment variables. It
141 corresponds to the <option>--setenv=</option> command line
142 switch.</para></listitem>
146 <term><varname>User=</varname></term>
148 <listitem><para>Takes a UNIX user name. Specifies the user
149 name to invoke the main process of the container as. This user
150 must be known in the container's user database. This
151 corresponds to the <option>--user=</option> command line
152 switch.</para></listitem>
156 <term><varname>WorkingDirectory=</varname></term>
158 <listitem><para>Selects the working directory for the process invoked in the container. Expects an absolute
159 path in the container's file system namespace. This corresponds to the <option>--chdir=</option> command line
160 switch.</para></listitem>
164 <term><varname>PivotRoot=</varname></term>
166 <listitem><para>Selects a directory to pivot to <filename>/</filename> inside the container when starting up.
167 Takes a single path, or a pair of two paths separated by a colon. Both paths must be absolute, and are resolved
168 in the container's file system namespace. This corresponds to the <option>--pivot-root=</option> command line
169 switch.</para></listitem>
173 <term><varname>Capability=</varname></term>
174 <term><varname>DropCapability=</varname></term>
176 <listitem><para>Takes a space-separated list of Linux process
178 <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
179 for details). The <varname>Capability=</varname> setting
180 specifies additional capabilities to pass on top of the
181 default set of capabilities. The
182 <varname>DropCapability=</varname> setting specifies
183 capabilities to drop from the default set. These settings
184 correspond to the <option>--capability=</option> and
185 <option>--drop-capability=</option> command line
186 switches. Note that <varname>Capability=</varname> is a
187 privileged setting, and only takes effect in
188 <filename>.nspawn</filename> files in
189 <filename>/etc/systemd/nspawn/</filename> and
190 <filename>/run/system/nspawn/</filename> (see above). On the
191 other hand, <varname>DropCapability=</varname> takes effect in
192 all cases.</para></listitem>
196 <term><varname>NoNewPrivileges=</varname></term>
198 <listitem><para>Takes a boolean argument that controls the <constant>PR_SET_NO_NEW_PRIVS</constant> flag for
199 the container payload. This is equivalent to the
200 <option>--no-new-privileges=</option> command line switch. See
201 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
207 <term><varname>KillSignal=</varname></term>
209 <listitem><para>Specify the process signal to send to the
210 container's PID 1 when nspawn itself receives SIGTERM, in
211 order to trigger an orderly shutdown of the container.
212 Defaults to SIGRTMIN+3 if <option>Boot=</option> is used
213 (on systemd-compatible init systems SIGRTMIN+3 triggers an
214 orderly shutdown). For a list of valid signals, see
215 <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para></listitem>
219 <term><varname>Personality=</varname></term>
221 <listitem><para>Configures the kernel personality for the
222 container. This is equivalent to the
223 <option>--personality=</option> switch.</para></listitem>
227 <term><varname>MachineID=</varname></term>
229 <listitem><para>Configures the 128-bit machine ID (UUID) to pass to
230 the container. This is equivalent to the
231 <option>--uuid=</option> command line switch. This option is
232 privileged (see above). </para></listitem>
236 <term><varname>PrivateUsers=</varname></term>
238 <listitem><para>Configures support for usernamespacing. This is equivalent to the
239 <option>--private-users=</option> command line switch, and takes the same options. This option is privileged
240 (see above). This option is the default if the <filename>systemd-nspawn@.service</filename> template unit file
241 is used.</para></listitem>
245 <term><varname>NotifyReady=</varname></term>
247 <listitem><para>Configures support for notifications from the container's init process. This is equivalent to
248 the <option>--notify-ready=</option> command line switch, and takes the same parameters. See
249 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for details
250 about the specific options supported.</para></listitem>
254 <term><varname>SystemCallFilter=</varname></term>
256 <listitem><para>Configures the system call filter applied to containers. This is equivalent to the
257 <option>--system-call-filter=</option> command line switch, and takes the same list parameter. See
258 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
259 details.</para></listitem>
263 <term><varname>LimitCPU=</varname></term>
264 <term><varname>LimitFSIZE=</varname></term>
265 <term><varname>LimitDATA=</varname></term>
266 <term><varname>LimitSTACK=</varname></term>
267 <term><varname>LimitCORE=</varname></term>
268 <term><varname>LimitRSS=</varname></term>
269 <term><varname>LimitNOFILE=</varname></term>
270 <term><varname>LimitAS=</varname></term>
271 <term><varname>LimitNPROC=</varname></term>
272 <term><varname>LimitMEMLOCK=</varname></term>
273 <term><varname>LimitLOCKS=</varname></term>
274 <term><varname>LimitSIGPENDING=</varname></term>
275 <term><varname>LimitMSGQUEUE=</varname></term>
276 <term><varname>LimitNICE=</varname></term>
277 <term><varname>LimitRTPRIO=</varname></term>
278 <term><varname>LimitRTTIME=</varname></term>
280 <listitem><para>Configures various types of resource limits applied to containers. This is equivalent to the
281 <option>--rlimit=</option> command line switch, and takes the same arguments. See
282 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
283 details.</para></listitem>
287 <term><varname>OOMScoreAdjust=</varname></term>
289 <listitem><para>Configures the OOM score adjustment value. This is equivalent to the
290 <option>--oom-score-adjust=</option> command line switch, and takes the same argument. See
291 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
292 details.</para></listitem>
296 <term><varname>CPUAffinity=</varname></term>
298 <listitem><para>Configures the CPU affinity. This is equivalent to the <option>--cpu-affinity=</option> command
299 line switch, and takes the same argument. See
300 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
301 details.</para></listitem>
305 <term><varname>Hostname=</varname></term>
307 <listitem><para>Configures the kernel hostname set for the container. This is equivalent to the
308 <option>--hostname=</option> command line switch, and takes the same argument. See
309 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
310 details.</para></listitem>
314 <term><varname>ResolvConf=</varname></term>
316 <listitem><para>Configures how <filename>/etc/resolv.conf</filename> in the container shall be handled. This is
317 equivalent to the <option>--resolv-conf=</option> command line switch, and takes the same argument. See
318 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
319 details.</para></listitem>
323 <term><varname>Timezone=</varname></term>
325 <listitem><para>Configures how <filename>/etc/localtime</filename> in the container shall be handled. This is
326 equivalent to the <option>--timezone=</option> command line switch, and takes the same argument. See
327 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
328 details.</para></listitem>
332 <term><varname>LinkJournal=</varname></term>
334 <listitem><para>Configures how to link host and container journal setups. This is equivalent to the
335 <option>--link-journal=</option> command line switch, and takes the same parameter. See
336 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
337 details.</para></listitem>
344 <title>[Files] Section Options</title>
346 <para>Settings files may include a <literal>[Files]</literal>
347 section, which carries various parameters configuring the file
348 system of the container:</para>
350 <variablelist class='nspawn-directives'>
353 <term><varname>ReadOnly=</varname></term>
355 <listitem><para>Takes a boolean argument, which defaults to off. If
356 specified, the container will be run with a read-only file
357 system. This setting corresponds to the
358 <option>--read-only</option> command line
359 switch.</para></listitem>
363 <term><varname>Volatile=</varname></term>
365 <listitem><para>Takes a boolean argument, or the special value
366 <literal>state</literal>. This configures whether to run the
367 container with volatile state and/or configuration. This
368 option is equivalent to <option>--volatile=</option>, see
369 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>
370 for details about the specific options
371 supported.</para></listitem>
375 <term><varname>Bind=</varname></term>
376 <term><varname>BindReadOnly=</varname></term>
378 <listitem><para>Adds a bind mount from the host into the
379 container. Takes a single path, a pair of two paths separated
380 by a colon, or a triplet of two paths plus an option string
381 separated by colons. This option may be used multiple times to
382 configure multiple bind mounts. This option is equivalent to
383 the command line switches <option>--bind=</option> and
384 <option>--bind-ro=</option>, see
385 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>
386 for details about the specific options supported. This setting
387 is privileged (see above).</para></listitem>
391 <term><varname>TemporaryFileSystem=</varname></term>
393 <listitem><para>Adds a <literal>tmpfs</literal> mount to the
394 container. Takes a path or a pair of path and option string,
395 separated by a colon. This option may be used multiple times to
396 configure multiple <literal>tmpfs</literal> mounts. This
397 option is equivalent to the command line switch
398 <option>--tmpfs=</option>, see
399 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>
400 for details about the specific options supported. This setting
401 is privileged (see above).</para></listitem>
405 <term><varname>Inaccessible=</varname></term>
407 <listitem><para>Masks the specified file or directly in the container, by over-mounting it with an empty file
408 node of the same type with the most restrictive access mode. Takes a file system path as argument. This option
409 may be used multiple times to mask multiple files or directories. This option is equivalent to the command line
410 switch <option>--inaccessible=</option>, see
411 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for details
412 about the specific options supported. This setting is privileged (see above).</para></listitem>
416 <term><varname>Overlay=</varname></term>
417 <term><varname>OverlayReadOnly=</varname></term>
419 <listitem><para>Adds an overlay mount point. Takes a colon-separated list of paths. This option may be used
420 multiple times to configure multiple overlay mounts. This option is equivalent to the command line switches
421 <option>--overlay=</option> and <option>--overlay-ro=</option>, see
422 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> for details
423 about the specific options supported. This setting is privileged (see above).</para></listitem>
427 <term><varname>PrivateUsersChown=</varname></term>
429 <listitem><para>Configures whether the ownership of the files and directories in the container tree shall be
430 adjusted to the UID/GID range used, if necessary and user namespacing is enabled. This is equivalent to the
431 <option>--private-users-chown</option> command line switch. This option is privileged (see
432 above). </para></listitem>
439 <title>[Network] Section Options</title>
441 <para>Settings files may include a <literal>[Network]</literal>
442 section, which carries various parameters configuring the network
443 connectivity of the container:</para>
445 <variablelist class='nspawn-directives'>
448 <term><varname>Private=</varname></term>
450 <listitem><para>Takes a boolean argument, which defaults to off. If
451 enabled, the container will run in its own network namespace
452 and not share network interfaces and configuration with the
453 host. This setting corresponds to the
454 <option>--private-network</option> command line
455 switch.</para></listitem>
459 <term><varname>VirtualEthernet=</varname></term>
461 <listitem><para>Takes a boolean argument. Configures whether to create a virtual Ethernet connection
462 (<literal>veth</literal>) between host and the container. This setting implies
463 <varname>Private=yes</varname>. This setting corresponds to the <option>--network-veth</option> command line
464 switch. This option is privileged (see above). This option is the default if the
465 <filename>systemd-nspawn@.service</filename> template unit file is used.</para></listitem>
469 <term><varname>VirtualEthernetExtra=</varname></term>
471 <listitem><para>Takes a colon-separated pair of interface
472 names. Configures an additional virtual Ethernet connection
473 (<literal>veth</literal>) between host and the container. The
474 first specified name is the interface name on the host, the
475 second the interface name in the container. The latter may be
476 omitted in which case it is set to the same name as the host
477 side interface. This setting implies
478 <varname>Private=yes</varname>. This setting corresponds to
479 the <option>--network-veth-extra=</option> command line
480 switch, and maybe be used multiple times. It is independent of
481 <varname>VirtualEthernet=</varname>. This option is privileged
482 (see above).</para></listitem>
486 <term><varname>Interface=</varname></term>
488 <listitem><para>Takes a space-separated list of interfaces to
489 add to the container. This option corresponds to the
490 <option>--network-interface=</option> command line switch and
491 implies <varname>Private=yes</varname>. This option is
492 privileged (see above).</para></listitem>
496 <term><varname>MACVLAN=</varname></term>
497 <term><varname>IPVLAN=</varname></term>
499 <listitem><para>Takes a space-separated list of interfaces to
500 add MACLVAN or IPVLAN interfaces to, which are then added to
501 the container. These options correspond to the
502 <option>--network-macvlan=</option> and
503 <option>--network-ipvlan=</option> command line switches and
504 imply <varname>Private=yes</varname>. These options are
505 privileged (see above).</para></listitem>
509 <term><varname>Bridge=</varname></term>
511 <listitem><para>Takes an interface name. This setting implies
512 <varname>VirtualEthernet=yes</varname> and
513 <varname>Private=yes</varname> and has the effect that the
514 host side of the created virtual Ethernet link is connected to
515 the specified bridge interface. This option corresponds to the
516 <option>--network-bridge=</option> command line switch. This
517 option is privileged (see above).</para></listitem>
521 <term><varname>Zone=</varname></term>
523 <listitem><para>Takes a network zone name. This setting implies <varname>VirtualEthernet=yes</varname> and
524 <varname>Private=yes</varname> and has the effect that the host side of the created virtual Ethernet link is
525 connected to an automatically managed bridge interface named after the passed argument, prefixed with
526 <literal>vz-</literal>. This option corresponds to the <option>--network-zone=</option> command line
527 switch. This option is privileged (see above).</para></listitem>
531 <term><varname>Port=</varname></term>
533 <listitem><para>Exposes a TCP or UDP port of the container on
534 the host. This option corresponds to the
535 <option>--port=</option> command line switch, see
536 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>
537 for the precise syntax of the argument this option takes. This
538 option is privileged (see above).</para></listitem>
544 <title>See Also</title>
546 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
547 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
548 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>