From: Lennart Poettering Date: Fri, 2 Jun 2023 16:24:27 +0000 (+0200) Subject: switch-root: automatically make target switch root dir a mount point X-Git-Tag: v254-rc1~298^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f717d7a40a696b351415976f22a4f498c401de41;p=thirdparty%2Fsystemd.git switch-root: automatically make target switch root dir a mount point Let's make sure implicitly that the target directory is a mount point, instead of doing so manually beforehand. This allows us to drop this step from the transition into the /run/initramfs/ dir at shutdown. During the initrd→host transition the switch root operations so far where towards pre-existing mount points, but there are cetrainly usecases where it might make sense to siwtch into arbitrary subdirectories, too. --- diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 17078c04903..070d5bd908b 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -66,6 +66,11 @@ int switch_root(const char *new_root, return 0; } + /* Make the new root directory a mount point if it isn't */ + r = fd_make_mount_point(new_root_fd); + if (r < 0) + return log_error_errno(r, "Failed to make new root directory a mount point: %m"); + if (FLAGS_SET(flags, SWITCH_ROOT_DESTROY_OLD_ROOT)) { istmp = fd_is_temporary_fs(old_root_fd); if (istmp < 0) diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index cdf828616ea..f8a9b0243a0 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -159,12 +159,6 @@ static int parse_argv(int argc, char *argv[]) { } static int switch_root_initramfs(void) { - if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) - return log_error_errno(errno, "Failed to mount bind /run/initramfs on /run/initramfs: %m"); - - if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) < 0) - return log_error_errno(errno, "Failed to make /run/initramfs private mount: %m"); - /* Do not detach the old root, because /run/initramfs/shutdown needs to access it. * * Disable sync() during switch-root, we after all sync'ed here plenty, and a dumb sync (as opposed