Commit 929a0f24 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

mount: remove root with MS_PRIVATE before pivot_root

Otherwise if the root is mounted with MS_SHARED, pivot_root fails with EINVAL.
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 000404ad
......@@ -603,6 +603,12 @@ static int cr_pivot_root()
pr_perror("Can't create a temparary directory");
return -1;
}
if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
pr_perror("Can't remount root with MS_PRIVATE");
return -1;
}
if (pivot_root(".", put_root)) {
pr_perror("pivot_root(., %s) failed", put_root);
if (rmdir(put_root))
......
......@@ -42,6 +42,12 @@ static int prepare_mntns()
fprintf(stderr, "mkdir(old) failed: %m\n");
return -1;
}
if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
fprintf(stderr, "Can't remount root with MS_PRIVATE: %m\n");
return -1;
}
if (pivot_root(".", "./old")) {
fprintf(stderr, "pivot_root(., ./old) failed: %m\n");
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment