diff --git a/mount.c b/mount.c index 6c70c8081..860fd708e 100644 --- a/mount.c +++ b/mount.c @@ -1275,10 +1275,6 @@ static int cr_pivot_root(struct mount_info *mis) pr_info("Move the root to %s\n", opts.root); - if (chdir(opts.root)) { - pr_perror("chdir(%s) failed", opts.root); - return -1; - } if (mkdtemp(put_root) == NULL) { pr_perror("Can't create a temporary directory"); return -1; @@ -1472,6 +1468,11 @@ int prepare_mnt_ns(int ns_pid) * prior to recreating new ones. */ + if (chdir(opts.root ? : "/")) { + pr_perror("chdir(%s) failed", opts.root ? : "/"); + return -1; + } + if (opts.root) ret = cr_pivot_root(mis); else