Systemd/src/nspawn
Motiejus Jakštys 5c4deb9a5c nspawn: mount custom paths before writing to /etc
Consider such configuration:

    $ systemd-nspawn --read-only --timezone=copy --resolv-conf=copy-host \
        --overlay="+/etc::/etc" <...>

Assuming one wants `/` to be read-only, DNS and `/etc/localtime` to
work. One way to do it is to create an overlay filesystem in `/etc/`.
However, systemd-nspawn tries to create `/etc/resolv.conf` and
`/etc/localtime` before mounting the custom paths, while `/` (and, by
extension, `/etc`) is read-only. Thus it fails to create those files.

Mounting custom paths before modifying anything in `/etc/` makes this
possible.

Full example:

```
$ debootstrap buster /var/lib/machines/t1 http://deb.debian.org/debian
$ systemd-nspawn --private-users=false --timezone=copy --resolv-conf=copy-host --read-only --tmpfs=/var --tmpfs=/run --overlay="+/etc::/etc" -D /var/lib/machines/t1 ping -c 1 example.com
Spawning container t1 on /var/lib/machines/t1.
Press ^] three times within 1s to kill container.
ping: example.com: Temporary failure in name resolution
Container t1 failed with error code 130.
```

With the patch:

```
$ sudo ./build/systemd-nspawn --private-users=false --timezone=copy --resolv-conf=copy-host --read-only --tmpfs=/var --tmpfs=/run --overlay="+/etc::/etc" -D /var/lib/machines/t1 ping -qc 1 example.com
Spawning container t1 on /var/lib/machines/t1.
Press ^] three times within 1s to kill container.
PING example.com (93.184.216.34) 56(84) bytes of data.

--- example.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 110.912/110.912/110.912/0.000 ms
Container t1 exited successfully.
```
2020-05-05 09:02:57 +02:00
..
meson.build meson: make source files including nspawn-settings.h depend on libseccomp 2019-04-30 19:31:22 +02:00
nspawn-cgroup.c util-lib: move some functions from basic/cgroup-util to shared/cgroup-setup 2019-09-16 18:08:00 +02:00
nspawn-cgroup.h nspawn: Move cgroup mount stuff from nspawn-mount.c to nspawn-cgroup.c 2018-07-20 12:12:02 -04:00
nspawn-def.h tree-wide: remove Lennart's copyright lines 2018-06-14 10:20:20 +02:00
nspawn-expose-ports.c nspawn: some minor modernizations 2020-04-23 07:59:26 +02:00
nspawn-expose-ports.h tree-wide: remove Lennart's copyright lines 2018-06-14 10:20:20 +02:00
nspawn-gperf.gperf nspawn: add support for executing OCI runtime bundles with nspawn 2019-03-15 15:41:28 +01:00
nspawn-mount.c nspawn: be more careful with creating/chowning directories to overmount 2020-04-28 19:40:46 +02:00
nspawn-mount.h nspawn: be more careful with creating/chowning directories to overmount 2020-04-28 19:40:46 +02:00
nspawn-network.c Merge pull request #14381 from keszybz/ifindex-cleanup 2020-01-13 17:57:59 +01:00
nspawn-network.h nspawn: Move --network-interface interfaces back to the host. 2020-01-02 14:13:03 +01:00
nspawn-oci.c tree-wide: fix spelling errors 2020-04-21 23:21:08 +02:00
nspawn-oci.h nspawn: add support for executing OCI runtime bundles with nspawn 2019-03-15 15:41:28 +01:00
nspawn-patch-uid.c *: convert amenable fdopendir() calls to take_fdopendir() 2020-03-31 06:48:03 -07:00
nspawn-patch-uid.h tree-wide: remove various unused functions 2018-12-02 13:35:34 +09:00
nspawn-register.c Merge pull request #13866 from keszybz/nspawn-restarts 2019-10-30 10:53:28 +01:00
nspawn-register.h nspawn: when stopping the machine, just deregister the machine 2019-10-29 10:54:45 +01:00
nspawn-seccomp.c nspawn: log syscalls we cannot add at debug level 2019-11-22 10:23:32 +01:00
nspawn-seccomp.h tree-wide: remove Lennart's copyright lines 2018-06-14 10:20:20 +02:00
nspawn-settings.c nspawn: beef up --resolve-conf= modes 2020-04-22 19:38:04 +02:00
nspawn-settings.h nspawn: beef up --resolve-conf= modes 2020-04-22 19:38:04 +02:00
nspawn-setuid.c *: convert amenable fdopen calls to take_fdopen 2020-03-31 06:48:03 -07:00
nspawn-setuid.h nspawn: refactor setuid code a bit 2019-03-15 15:33:09 +01:00
nspawn-stub-pid1.c tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
nspawn-stub-pid1.h tree-wide: remove Lennart's copyright lines 2018-06-14 10:20:20 +02:00
nspawn.c nspawn: mount custom paths before writing to /etc 2020-05-05 09:02:57 +02:00
test-nspawn-tables.c test-nspawn-tables: add another "tables" test 2018-05-28 10:40:00 +02:00
test-patch-uid.c util-lib: move yes_no() and friends to string-util.h 2019-09-16 18:06:20 +02:00