]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
switch-root: when pivot_root() fails, but old root shall be mounted, do so
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Aug 2023 10:10:18 +0000 (12:10 +0200)
committerMike Yuan <me@yhndnzj.com>
Sat, 2 Sep 2023 11:47:58 +0000 (19:47 +0800)
If pivot_root() fails, we'll fall back to switching root via MS_MOVE.
Unlike pivot_root() that won't place the old root fs anyway, but just
hide it. That's problematic during shutdown for example, since after all
we might still want to access it from the exitrd, to disassemble it
properly.

Hence let's make things somewhat systematic: regardless if pivot_root()
or MS_MOVE is used, always make the old root fs show up in the selected
new dir.

src/shared/switch-root.c

index 34cd2ad0b5fe2664de5114ebfbefbfd9d2402eea..3801fec6459876f4d02a5bb1fa6b586ca90680de 100644 (file)
@@ -173,6 +173,12 @@ int switch_root(const char *new_root,
         if (r < 0) {
                 log_debug_errno(r, "Pivoting root file system failed, moving mounts instead: %m");
 
+                if (resolved_old_root_after) {
+                        r = mount_nofollow_verbose(LOG_ERR, "/", resolved_old_root_after, NULL, MS_BIND|MS_REC, NULL);
+                        if (r < 0)
+                                return r;
+                }
+
                 /* If we have to use MS_MOVE let's first try to get rid of *all* mounts we can, with the
                  * exception of the path we want to switch to, plus everything leading to it and within
                  * it. This is necessary because unlike pivot_root() just moving the mount to the root via