parallel-debian: More in progress work...

This commit is contained in:
Colin Walters 2011-10-19 20:54:28 -04:00
parent 50b1051ba0
commit 33232117d5
4 changed files with 43 additions and 41 deletions

View File

@ -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
<http://wiki.debian.org/QEMU#Setting_up_a_testing.2BAC8-unstable_system>
Follow the steps for making a disk image, downloading the business

View File

@ -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

View File

@ -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

View File

@ -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;
}
}