From: Lennart Poettering Date: Fri, 11 Aug 2023 10:10:18 +0000 (+0200) Subject: switch-root: when pivot_root() fails, but old root shall be mounted, do so X-Git-Tag: v255-rc1~601^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95648f9ed0d972c3ad86205a462bb5805498ee58;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 34cd2ad0b5f..3801fec6459 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