From 95648f9ed0d972c3ad86205a462bb5805498ee58 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Aug 2023 12:10:18 +0200 Subject: [PATCH] switch-root: when pivot_root() fails, but old root shall be mounted, do so 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 34cd2ad0b5..3801fec645 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -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 -- 2.25.1