]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: when operating on the host image, let's move the root to a different director... 13184/head
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Jul 2019 11:03:50 +0000 (13:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 29 Jul 2019 07:57:04 +0000 (09:57 +0200)
src/nspawn/nspawn.c

index 2289a0a97fb3e78dc28b21e99ff6a3ea85a4892d..2aec8041f007923a6c27719aa65b8a25210ff3a8 100644 (file)
@@ -3264,8 +3264,24 @@ static int outer_child(
                          "Selected user namespace base " UID_FMT " and range " UID_FMT ".", arg_uid_shift, arg_uid_range);
         }
 
-        if (!dissected_image) {
-                /* Turn directory into bind mount */
+        if (path_equal(directory, "/")) {
+                /* If the directory we shall boot is the host, let's operate on a bind mount at a different
+                 * place, so that we can make changes to its mount structure (for example, to implement
+                 * --volatile=) without this interfering with our ability to access files such as
+                 * /etc/localtime to copy into the container. Note that we use a fixed place for this
+                 * (instead of a temporary directory, since we are living in our own mount namspace here
+                 * already, and thus don't need to be afraid of colliding with anyone else's mounts).*/
+                (void) mkdir_p("/run/systemd/nspawn-root", 0755);
+
+                r = mount_verbose(LOG_ERR, "/", "/run/systemd/nspawn-root", NULL, MS_BIND|MS_REC, NULL);
+                if (r < 0)
+                        return r;
+
+                directory = "/run/systemd/nspawn-root";
+
+        } else if (!dissected_image) {
+                /* Turn directory into bind mount (we need that so that we can move the bind mount to root
+                 * later on). */
                 r = mount_verbose(LOG_ERR, directory, directory, NULL, MS_BIND|MS_REC, NULL);
                 if (r < 0)
                         return r;