From 33232117d51c8f262d74d77e17ae2184f7e63892 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 19 Oct 2011 20:54:28 -0400 Subject: [PATCH] parallel-debian: More in progress work... --- parallel-debian/README-testing-multiroot.md | 6 +++ parallel-debian/create-wheezy-image.sh | 16 -------- parallel-debian/make-image-parallel.sh | 20 ---------- parallel-debian/ostree_switch_root.c | 42 ++++++++++++++++++--- 4 files changed, 43 insertions(+), 41 deletions(-) delete mode 100755 parallel-debian/create-wheezy-image.sh delete mode 100755 parallel-debian/make-image-parallel.sh diff --git a/parallel-debian/README-testing-multiroot.md b/parallel-debian/README-testing-multiroot.md index 4fd0a123..1eadf88c 100644 --- a/parallel-debian/README-testing-multiroot.md +++ b/parallel-debian/README-testing-multiroot.md @@ -2,6 +2,12 @@ Experimenting with multiple roots --------------------------------- + $ mkdir gnomeos-chroot + $ qemu-img create gnomeos.raw 2G + $ mkfs.ext2 -F gnomeos.raw + $ mount -o loop gnomeos.raw gnomeos-chroot + $ debootstrap --arch=amd64 squeeze gnomeos-chroot + Follow the steps for making a disk image, downloading the business diff --git a/parallel-debian/create-wheezy-image.sh b/parallel-debian/create-wheezy-image.sh deleted file mode 100755 index 6f8263ab..00000000 --- a/parallel-debian/create-wheezy-image.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -set -e -set -x - -if test -f debian.img; then - echo debian.img already exists - exit 1 -fi - -qemu-img create debian.img 600M -mkfs.ext2 -q -F debian.img -mkdir -p debian-mnt -mount -o loop debian.img debian-mnt -debootstrap --arch amd64 wheezy debian-mnt -umount debian-mnt diff --git a/parallel-debian/make-image-parallel.sh b/parallel-debian/make-image-parallel.sh deleted file mode 100755 index b6aaa9e7..00000000 --- a/parallel-debian/make-image-parallel.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -set -e -set -x - -DIRS="bin boot dev etc lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var" - -if ! test -f debian.img; then - echo need debian.img - exit 1 -fi - -mount -o loop debian.img debian-mnt -cd debian-mnt -if ! test -d r0; then - mkdir r0 - mv $DIRS r0 -fi -cd .. -umount debian-mnt diff --git a/parallel-debian/ostree_switch_root.c b/parallel-debian/ostree_switch_root.c index 543dcb2b..67a1cc68 100644 --- a/parallel-debian/ostree_switch_root.c +++ b/parallel-debian/ostree_switch_root.c @@ -143,7 +143,9 @@ static int make_readonly(const char *tree) static int switchroot(const char *newroot, const char *subroot) { - const char *root_bind_mounts[] = { "/home", "/root", "/var", NULL }; + const char *toproot_bind_mounts[] = { "/boot", NULL }; + const char *ostree_inherit_mounts[] = { "/home", "/root", NULL }; + const char *ostree_bind_mounts[] = { "/var", NULL }; const char *readonly_bind_mounts[] = { "/bin", "/etc", "/lib", "/lib32", "/lib64", "/sbin", "/usr", @@ -151,13 +153,23 @@ static int switchroot(const char *newroot, const char *subroot) int i; int orig_cfd; int new_cfd; + int subroot_cfd; pid_t pid; + char subroot_path[PATH_MAX]; char srcpath[PATH_MAX]; char destpath[PATH_MAX]; + struct stat stbuf; orig_cfd = open("/", O_RDONLY); new_cfd = open(newroot, O_RDONLY); + snprintf(subroot_path, sizeof(subroot_path), "%s/ostree/%s", newroot, subroot); + subroot_cfd = open(subroot_path, O_RDONLY); + if (subroot_cfd < 0) { + perrorv("failed to open subroot %s", subroot_path); + return -1; + } + /* For now just remount the rootfs r/w. Should definitely * handle this better later... (famous last words) */ @@ -166,11 +178,31 @@ static int switchroot(const char *newroot, const char *subroot) return -1; } - for (i = 0; root_bind_mounts[i] != NULL; i++) { - snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, root_bind_mounts[i]); - snprintf(destpath, sizeof(destpath), "%s/%s%s", newroot, subroot, root_bind_mounts[i]); + for (i = 0; toproot_bind_mounts[i] != NULL; i++) { + snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, toproot_bind_mounts[i]); + snprintf(destpath, sizeof(destpath), "%s/%s", subroot_path, toproot_bind_mounts[i]); if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) { - perrorv("failed to bind mount %s to %s", srcpath, destpath); + perrorv("failed to bind mount (class:toproot) %s to %s", srcpath, destpath); + return -1; + } + } + + for (i = 0; ostree_inherit_mounts[i] != NULL; i++) { + snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, ostree_inherit_mounts[i]); + if (stat (srcpath, &stbuf) < 0) + snprintf(srcpath, sizeof(srcpath), "%s/ostree%s", newroot, ostree_inherit_mounts[i]); + snprintf(destpath, sizeof(destpath), "%s%s", subroot_path, ostree_inherit_mounts[i]); + if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) { + perrorv("failed to bind mount (class:inherit) %s to %s", srcpath, destpath); + return -1; + } + } + + for (i = 0; ostree_bind_mounts[i] != NULL; i++) { + snprintf(srcpath, sizeof(srcpath), "%s/ostree%s", newroot, ostree_bind_mounts[i]); + snprintf(destpath, sizeof(destpath), "%s%s", subroot_path, ostree_bind_mounts[i]); + if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) { + perrorv("failed to bind mount (class:bind) %s to %s", srcpath, destpath); return -1; } }