Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
pivot_root: bind-mount the old / rather than starting with empty /
Browse files Browse the repository at this point in the history
That way we get /lib and /etc which sometimes are needed.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
hallyn committed Feb 13, 2015
1 parent 5f50c82 commit 3296a6d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,25 +888,25 @@ static int do_pivot(void) {

static int pivot_into_new_root(void) {
int i, ret;
char *createdirs[] = {NEWROOT "/proc", NEWROOT "/run",
NEWROOT "/run/cgmanager", NEWROOT "/run/cgmanager/fs", NULL};
char *createdirs[] = {NEWROOT "/run/cgmanager", NEWROOT "/run/cgmanager/fs", NULL};
char path[100];

/* Mount tmpfs for new root */
if (mkdir(NEWROOT, 0755) < 0 && errno != EEXIST) {
nih_fatal("%s: Failed to create directory for new root\n", __func__);
return -1;
}
ret = mount("root", NEWROOT, "tmpfs", 0, "size=10000,mode=0755");
ret = mount("/", NEWROOT, NULL, MS_BIND, 0);
if (ret < 0) {
nih_fatal("%s: Failed to mount tmpfs for root", __func__);
nih_fatal("%s: Failed to bind-mount / for new root", __func__);
return -1;
}

/* create /proc and /run/cgmanager/fs, and move-mount those */
for (i = 0; createdirs[i]; i++) {
if (mkdir(createdirs[i], 0755) < 0) {
nih_fatal("%s: failed to created %s\n", __func__, createdirs[i]);
if (mkdir(createdirs[i], 0755) < 0 && errno != EEXIST) {
nih_fatal("%s: failed to created %s\n", __func__,
createdirs[i], strerror(errno));
return -1;
}
}
Expand Down

0 comments on commit 3296a6d

Please sign in to comment.