X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fswitch-root.c;h=3adb8463c5f373d4cd316c4aab9337d2c3f289a9;hb=c73d180dc4bbd87c945a524b42b672af2ffe2609;hp=5f075e6003d90920a393fb202595b563bbf6df9b;hpb=5a4bf02ff57e4dd3453f2b868c72fe45f60033a3;p=elogind.git diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 5f075e600..3adb8463c 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -47,7 +47,6 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, struct stat new_root_stat; bool old_root_remove; const char *i, *temporary_old_root; - int r; if (path_equal(new_root, "/")) return 0; @@ -62,10 +61,9 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, return -errno; } - /* 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. + /* Work-around for kernel design: 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) @@ -104,11 +102,12 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, } } - r = base_filesystem_create(new_root); - if (r < 0) { - log_error("Failed to create the base filesystem: %s", strerror(-r)); - return r; - } + /* Do not fail, if base_filesystem_create() fails. Not all + * switch roots are like base_filesystem_create() wants them + * to look like. They might even boot, if they are RO and + * don't have the FS layout. Just ignore the error and + * switch_root() nevertheless. */ + (void) base_filesystem_create(new_root); if (chdir(new_root) < 0) { log_error("Failed to change directory to %s: %m", new_root); @@ -128,10 +127,10 @@ int switch_root(const char *new_root, const char *oldroot, bool detach_oldroot, /* Immediately get rid of the old root, if detach_oldroot is set. * Since we are running off it we need to do this lazily. */ - if (detach_oldroot && umount2(oldroot, MNT_DETACH) < 0) { - log_error("Failed to umount old root dir %s: %m", oldroot); - return -errno; - } + if (detach_oldroot && umount2(oldroot, MNT_DETACH) < 0) + log_error("Failed to lazily umount old root dir %s, %s: %m", + oldroot, + errno == ENOENT ? "ignoring" : "leaving it around"); } else if (mount(new_root, "/", NULL, MS_MOVE, NULL) < 0) { log_error("Failed to mount moving %s to /: %m", new_root);