From f2c1d491a539035d6cc1fa53a7cef0cbc8d52902 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Apr 2023 18:35:31 +0200 Subject: switch-root: don't require /mnt/ when switching root into host OS So far, we invoked pivot_root() specifying /mnt/ as second argument, which then unmounted right-after. We'd create /mnt/ if needed. This sucks, because it means /mnt/ must strictly be pre-created on immutable images. Remove this limitation, by using pivot_root() with "." as source and target, which will result in two stacked mounts afterwards: the new one underneath, the old one ontop. We can then simply unmount the top one, and have what we want without needing any extra /mnt/ dir. Since we don't need /mnt/ anymore we can get rid of the extra unmount_old_root parameter and simply specify it as NULL if we don't want the old mount to stick around. --- src/shutdown/shutdown.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/shutdown') diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index 802be44a79..cf0351cf78 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -169,7 +169,7 @@ static int switch_root_initramfs(void) { * /run/initramfs/shutdown will take care of these. * Also do not detach the old root, because /run/initramfs/shutdown needs to access it. */ - return switch_root("/run/initramfs", "/oldroot", false, MS_BIND); + return switch_root("/run/initramfs", "/oldroot", MS_BIND); } /* Read the following fields from /proc/meminfo: -- cgit v1.2.1