* all while making them invisible/inaccessible in the file system tree for later code. That makes
* sync'ing them then difficult. Let's hence issue a manual sync() here, so that we at least can
* guarantee all file systems are an a good state before entering this state. */
- sync();
+ if (!FLAGS_SET(flags, SWITCH_ROOT_DONT_SYNC))
+ sync();
/* Work-around for kernel design: the kernel refuses MS_MOVE if any file systems are mounted
* MS_SHARED. Hence remount them MS_PRIVATE here as a work-around.
typedef enum SwitchRootFlags {
SWITCH_ROOT_DESTROY_OLD_ROOT = 1 << 0, /* rm -rf old root when switching – under the condition that it is backed by non-persistent tmpfs/ramfs/… */
+ SWITCH_ROOT_DONT_SYNC = 1 << 1, /* don't call sync() immediately before switching root */
} SwitchRootFlags;
int switch_root(const char *new_root, const char *old_root_after, SwitchRootFlags flags);
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. */
+ /* 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
+ * to the "smart" sync() we did here that looks at progress parameters) would defeat much of our
+ * efforts here. */
return switch_root(
/* new_root= */ "/run/initramfs",
/* old_root_after= */ "/oldroot",
- /* flags= */ 0);
+ /* flags= */ SWITCH_ROOT_DONT_SYNC);
}
/* Read the following fields from /proc/meminfo: