chiark / gitweb /
switch-root: remount to MS_PRIVATE
[elogind.git] / src / core / switch-root.c
index 9832a520e4ac3f29d6ecfce0e85d181d826fcb3a..efc7d345e1a83ca28a861b69eda9b0ee92cac281 100644 (file)
@@ -56,6 +56,15 @@ int switch_root(const char *new_root) {
                 goto fail;
         }
 
+        /* Work-around for a kernel bug: for some reason the kernel
+         * refuses switching root if any file systems are mounted
+         * MS_SHARED. Hence remount them MS_PRIVATE here as a
+         * work-around.
+         *
+         * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */
+        if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
+                log_warning("Failed to make \"/\" private mount: %m");
+
         NULSTR_FOREACH(i, move_mounts) {
                 char new_mount[PATH_MAX];
                 struct stat sb;