SYSTEMD.NSPAWN(5)
π systemd.nspawn(5) β the manual, but make it make sense β¨
okay bestie, this is systemd.nspawn β aka the Container settings page π (yes that's the official manual name, we're just vibing with it)
β¨ SYNOPSIS β¨
/etc/systemd/nspawn/machine.nspawn
/run/systemd/nspawn/machine.nspawn
/var/lib/machines/machine.nspawn
three paths, three vibes, all of them absolutely slaying the same file name pattern π«Ά
πΈ DESCRIPTION πΈ
So. An nspawn container settings file β you'll clock it by the .nspawn suffix β¨ β is literally just runtime configuration for a local container, and it's what systemd-nspawn(1) reads. Iconic.
Files of this type are named after the containers they define settings for β so the file name isn't random, it's the container's whole identity, main character energy π.
They're optional bestie, no cap. You only need one when your container's execution environment needs to differ from the defaults. That's it. That's the requirement π
What's inside? Mostly settings that could also be set on the systemd-nspawn command line β but putting them in the file makes it way easier to persistently attach specific settings to specific containers. Because typing the same flags forever is not the move, and we don't do that here π
The syntax is inspired by .desktop files β same family as the other configuration files the systemd project supports. And for the full overview, go read systemd.syntax(7) π
π¦ .NSPAWN FILE DISCOVERY π¦
okay so this is the part where it goes looking for your file, and the search order is VERY important, so pay attention π
Files are searched for by appending the .nspawn suffix to the machine name of the container β the machine name is specified with the --machine= switch of systemd-nspawn, or derived from the directory or image file name. iykyk π§
Here's the whole little detective story:
- First it looks in
/etc/systemd/nspawn/and/run/systemd/nspawn/π - If found there β the settings are read and all of them take full effect (though they may still be overridden by corresponding command line arguments, sneaky π«£)
- Otherwise β it then searches next to the image file, or in the immediate parent of the root directory of the container π
- If found there β only a subset of the settings will take effect. Harsh? Maybe. Necessary? Absolutely π
β οΈ Okay this next bit is the important part, don't scroll past it: all settings that possibly elevate privileges or grant additional access to resources of the host (like files or directories β yes, those) are ignored when the file is found in that second location. Which options this applies to is documented below, so keep reading.
Now for the trust tea β: persistent settings files created and maintained by the administrator (and thus trusted) should be placed in /etc/systemd/nspawn/. Automatically downloaded (and thus potentially untrusted) settings files go in /var/lib/machines/ instead β next to the container images β where their security impact is limited. Safe little corner, we love that for them π
And if you're trying to add privileged settings to .nspawn files you acquired from the image vendor? The recommended move is to copy the settings files into /etc/systemd/nspawn/ and edit them there, so that the privileged options become available. Move it to the trusted neighbourhood and then unlock the good stuff π₯
The precise algorithm for how those files are searched and interpreted can be configured with systemd-nspawn's --settings= switch β check systemd-nspawn(1) for the details, bestie π
...and that's part one, stay tuned because there is SO much more π
β¨ [Exec] SECTION OPTIONS β¨
okay so bestie, settings files may totally include an [Exec] section, and this is where all the "what actually runs and how" energy lives π
it carries various execution parameters:
Boot=β takes a boolean argument, and it defaults tooff. flip it on andsystemd-nspawnwill automatically go hunt for an init executable and invoke it, no cap π in that case, whatever you put inParameters=gets passed as additional arguments to that init process. this is literally the--bootswitch on thesystemd-nspawncommand line. β οΈ heads up: this option may not be combined withProcessTwo=yes. and fun fact, this option is specified by default in thesystemd-nspawn@.servicetemplate unit π
Added in version 226.
Ephemeral=β takes a boolean argument, defaults tooff. if enabled, the container runs with a temporary snapshot of its file system that gets yeeted immediately when the container terminates π«§ it's the equivalent of the--ephemeralcommand line switch. seesystemd-nspawn(1)for the deets on which specific options are supported.
Added in version 240.
ProcessTwo=β takes a boolean argument, defaults tooff. if enabled, the program you specified runs as PID 2, and a lil stub init process runs as PID 1 π§ this setting corresponds to the--as-pid2switch on thesystemd-nspawncommand line. β οΈ may not be combined withBoot=yes.
Added in version 229.
Parameters=β takes a whitespace-separated list of arguments. single ("'") and double (""") quotes may be used around arguments that have whitespace in them. this is either a command line, starting with the binary name to execute, or β ifBoot=is enabled β the list of arguments to pass along to the init process. it corresponds to the command line parameters passed on thesystemd-nspawncommand line β¨
π note:Boot=no,Parameters=a b "c c"is the same assystemd-nspawn a b "c c", andBoot=yes,Parameters=b 'c c'is the same assystemd-nspawn --boot b 'c c'. iykyk π
Added in version 226.
Environment=β takes an environment variable assignment made of a key and a value, separated by=. it sets an environment variable for the main process invoked in the container πΈ this setting may be used multiple times to set multiple environment variables, so go off. corresponds to the--setenv=command line switch.
Added in version 226.
User=β takes a UNIX user name. specifies the user name to invoke the container's main process as. this user has to be known in the container's user database, no pretending π corresponds to the--user=command line switch.
Added in version 226.
WorkingDirectory=β selects the working directory for the process invoked in the container. expects an absolute path in the container's file system namespace. corresponds to the--chdir=command line switch π
Added in version 229.
PivotRoot=β selects a directory to pivot to/inside the container when starting up. takes a single path, or a pair of two paths separated by a colon. both paths must be absolute, and they're resolved in the container's file system namespace. corresponds to the--pivot-root=command line switch π
Added in version 233.
Capability=,DropCapability=β take a space-separated list of Linux process capabilities (peepcapabilities(7)for details).Capability=specifies extra capabilities to pass on top of the default set, andDropCapability=specifies capabilities to drop from that default set βοΈ these settings correspond to the--capability=and--drop-capability=command line switches. note thatCapability=is a privileged setting, and it only takes effect in.nspawnfiles in/etc/systemd/nspawn/and/run/system/nspawn/(see above).DropCapability=, on the other hand, takes effect in all cases, periodt. if you pass the special value"all", all capabilities are retained (or dropped).
these settings change the bounding set of capabilities, which also limits the ambient capabilities as given with AmbientCapability= π₯
Added in version 226.
AmbientCapability=β takes a space-separated list of Linux process capabilities (seecapabilities(7)). this setting specifies capabilities that will be passed to the started program in the inheritable and ambient capability sets. this will grant these capabilities to this process π corresponds to the--ambient-capability=command line switch.
the value "all" is not supported for this setting π
the setting of AmbientCapability= must be covered by the bounding set settings that were established by Capability= and DropCapability=.
also note that AmbientCapability= is a privileged setting (see above) π
Added in version 248.
NoNewPrivileges=β takes a boolean argument that controls thePR_SET_NO_NEW_PRIVSflag for the container payload. equivalent to the--no-new-privileges=command line switch. seesystemd-nspawn(1)for details π¦
Added in version 239.
KillSignal=β specify the process signal to send to the container's PID 1 when nspawn itself receivesSIGTERM, so we can trigger an orderly shutdown of the container π defaults toSIGRTMIN+3ifBoot=is used (on systemd-compatible init systemsSIGRTMIN+3triggers an orderly shutdown, iconic). for a list of valid signals, seesignal(7).
Added in version 230.
Personality=β configures the kernel personality for the container. equivalent to the--personality=switch π
Added in version 226.
MachineID=β configures the 128-bit machine ID (UUID) to pass to the container. equivalent to the--uuid=command line switch. this option is privileged (see above) π
Added in version 226.
PrivateUsers=β configures support for usernamespacing. equivalent to the--private-users=command line switch, and it takes the same options. this option is privileged (see above). it's also the default if thesystemd-nspawn@.servicetemplate unit file is used π«
Added in version 230.
PrivateUsersDelegate=β takes a non-negative integer. configures delegation of additional 64K UID/GID ranges into the container's user namespace for use by nested containers πͺ when set to a value greater than zero, thesystemd-nsresourced.service(8)varlink socket will be bind-mounted into the container so that processes inside it can allocate further user namespaces from the delegated ranges. equivalent to the--private-users-delegate=command line switch. requiresPrivateUsers=managed. defaults to0. seesystemd-nspawn(1)for details.
Added in version 260.
NotifyReady=β configures support for notifications coming from the container's init process π£ equivalent to the--notify-ready=command line switch, and takes the same parameters. seesystemd-nspawn(1)for details about the specific options supported.
Added in version 231.
SystemCallFilter=β configures the system call filter applied to containers. equivalent to the--system-call-filter=command line switch, and takes the same list parameter. seesystemd-nspawn(1)for details π§Ώ
Added in version 235.
RestrictAddressFamilies=β restricts the socket address families accessible to the container. equivalent to the--restrict-address-families=command line switch, and takes the same list parameter. seesystemd-nspawn(1)for details π
Added in version 261.
LimitCPU=,LimitFSIZE=,LimitDATA=,LimitSTACK=,LimitCORE=,LimitRSS=,LimitNOFILE=,LimitAS=,LimitNPROC=,LimitMEMLOCK=,LimitLOCKS=,LimitSIGPENDING=,LimitMSGQUEUE=,LimitNICE=,LimitRTPRIO=,LimitRTTIME=β configures various types of resource limits applied to containers. this is equivalent to the--rlimit=command line switch, and takes the same arguments. seesystemd-nspawn(1)for details βοΈ
Added in version 239.
OOMScoreAdjust=β configures the OOM score adjustment value. equivalent to the--oom-score-adjust=command line switch, and takes the same argument. seesystemd-nspawn(1)for details π
Added in version 239.
CPUAffinity=β configures the CPU affinity. equivalent to the--cpu-affinity=command line switch, and takes the same argument. seesystemd-nspawn(1)for details π§
Added in version 239.
Hostname=β configures the kernel hostname set for the container. equivalent to the--hostname=command line switch, and takes the same argument. seesystemd-nspawn(1)for details π·οΈ
Added in version 239.
ResolvConf=β configures how/etc/resolv.confin the container shall be handled. equivalent to the--resolv-conf=command line switch, and takes the same argument. seesystemd-nspawn(1)for details π
Added in version 239.
Timezone=β configures how/etc/localtimein the container shall be handled. equivalent to the--timezone=command line switch, and takes the same argument. seesystemd-nspawn(1)for details π°οΈ
Added in version 239.
LinkJournal=β configures how to link host and container journal setups. equivalent to the--link-journal=command line switch, and takes the same parameter. seesystemd-nspawn(1)for details π
Added in version 239.
SuppressSync=β configures whether to suppress disk synchronization for the container payload. equivalent to the--suppress-sync=command line switch, and takes the same parameter. seesystemd-nspawn(1)for details πΎ
Added in version 250.
π [FILES] SECTION OPTIONS π
okay so your settings file can also have a [Files] section, and this one is literally the whole file-system vibe check for your container β all the parameters that configure its file system live here π«Ά
ReadOnly=β takes a boolean, defaults to off. flip it on and your container runs with a read-only file system (no cap, nothing's getting written π). this one matches the--read-onlycommand line switch.
added in version 226 β¨
Volatile=β takes a boolean, or the special value"state". this controls whether the container runs with volatile state and/or configuration. it's the same thing as--volatile=, so peek atsystemd-nspawn(1)for the deets on which values are supported.
added in version 226 β¨
Bind=,BindReadOnly=β adds a bind mount from the host into the container, slay. takes a single path, a pair of two paths separated by a colon, or a triplet of two paths plus an option string separated by colons. use it multiple times to configure multiple bind mounts, go off. equivalent to the command line switches--bind=and--bind-ro=βsystemd-nspawn(1)has the specifics. heads up: this setting is privileged (see above π).
added in version 226 β¨
BindUser=β binds a user from the host into the container. equivalent to the command line switch--bind-user=, seesystemd-nspawn(1)for what it actually supports. also privileged (see above π).
added in version 249 β¨
BindUserShell=β when you use it withBindUser, this specifies the shell that gets included in the user record of users bound from the host into the container. equivalent to--bind-user-shell=, checksystemd-nspawn(1). privileged again (see above π).
added in version 258 β¨
TemporaryFileSystem=β adds a"tmpfs"mount to the container π takes a path, or a pair of path and option string separated by a colon. multiple uses = multiple"tmpfs"mounts. equivalent to the--tmpfs=command line switch, details insystemd-nspawn(1). privileged (see above π).
added in version 226 β¨
Inaccessible=β masks the file or directory you name in the container by over-mounting it with an empty file node of the same type with the most restrictive access mode. takes a file system path as its argument. use it multiple times to mask multiple files or directories. equivalent to the--inaccessible=command line switch, seesystemd-nspawn(1)for the specifics. privileged (see above π).
added in version 242 β¨
Overlay=,OverlayReadOnly=β adds an overlay mount point, obsessed. takes a colon-separated list of paths. multiple uses = multiple overlay mounts. equivalent to the--overlay=and--overlay-ro=command line switches βsystemd-nspawn(1)has the fine print. privileged (see above π).
added in version 233 β¨
PrivateUsersOwnership=β configures whether the ownership of the files and directories in the container tree shall be adjusted to the UID/GID range used, if necessary and user namespacing is enabled. equivalent to the--private-users-ownership=command line switch. privileged (see above π).
added in version 249 β¨
π [NETWORK] SECTION OPTIONS π
next up, the [Network] section β every parameter that configures how your container connects to the world π¦
Private=β takes a boolean, defaults to off. enable it and the container runs in its own network namespace, not sharing network interfaces and configuration with the host. matches the--private-networkcommand line switch.
added in version 226 β¨
NamespacePath=β takes the path to a file representing a kernel network namespace that the container shall run in. the path should refer to a (possibly bind-mounted) network namespace file, as exposed by the kernel below/proc/$PID/ns/net. this makes the container enter the given network namespace. one classic use case is handing it a network namespace under/run/netnscreated byip-netns(8)β for example,NamespacePath=/run/netns/foo. β οΈ note that this option cannot be used together with other network-related options, such asPrivate=orInterface=. corresponds to the--network-namespace-pathcommand line switch.
added in version 259 β¨
VirtualEthernet=β takes a boolean. configures whether to create a virtual Ethernet connection ("veth") between host and the container. this setting impliesPrivate=yes. corresponds to the--network-vethcommand line switch. and fun fact: this option is the default if thesystemd-nspawn@.servicetemplate unit file is used π
added in version 226 β¨
VirtualEthernetExtra=β takes a colon-separated pair of interface names, and configures an additional virtual Ethernet connection ("veth") between host and container. the first specified name is the interface name on the host, the second is the interface name in the container. the second one may be omitted, in which case it's set to the same name as the host side interface. this setting impliesPrivate=yes. corresponds to the--network-veth-extra=command line switch, and may be used multiple times. it's independent ofVirtualEthernet=. β οΈ note that this option is unrelated to theBridge=setting below, so any connections created this way are not automatically added to any bridge device on the host side. privileged (see above π).
added in version 228 β¨
Interface=β takes a space-separated list of interfaces to add to the container. the interface object is defined either by a single interface name referencing the name on the host, or a colon-separated pair of interfaces β in which case the first references the name on the host and the second the name in the container. corresponds to the--network-interface=command line switch and impliesPrivate=yes. privileged (see above π).
added in version 226 β¨
MACVLAN=,IPVLAN=β take a space-separated list of interfaces to add MACVLAN or IPVLAN interfaces to, which are then added to the container. the interface object is defined either by a single interface name referencing the name on the host, or a colon-separated pair of interfaces, where the first references the name on the host and the second the name in the container. these correspond to the--network-macvlan=and--network-ipvlan=command line switches and implyPrivate=yes. both privileged (see above π).
added in version 226 β¨
Bridge=β takes an interface name. this setting impliesVirtualEthernet=yesandPrivate=yes, and has the effect that the host side of the created virtual Ethernet link is connected to the specified bridge interface π«Ά corresponds to the--network-bridge=command line switch. privileged (see above π).
added in version 226 β¨
Zone=β takes a network zone name. this setting impliesVirtualEthernet=yesandPrivate=yes, and has the effect that the host side of the created virtual Ethernet link is connected to an automatically managed bridge interface named after the passed argument, prefixed with"vz-". corresponds to the--network-zone=command line switch. privileged (see above π).
added in version 230 β¨
Port=β exposes a TCP or UDP port of the container on the host π corresponds to the--port=command line switch β seesystemd-nspawn(1)for the precise syntax of the argument this option takes. privileged (see above π).
added in version 226 β¨
π¦ SEE ALSO π¦
and that's a wrap bestie, you literally ate this entire page π
the whole thing is from systemd 261.3, filed under SYSTEMD.NSPAWN(5) β go forth and spawn responsibly, ily, mwah πβ¨
π¦ where this page comes from
- ubuntu stonking: systemd-container 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms