From 684f6c94276bb7576ca2cf8eae9d2d8801a00814 Mon Sep 17 00:00:00 2001 From: devrandom Date: Wed, 12 Sep 2012 09:52:36 -0700 Subject: [PATCH] Use lxcbr0 as bridge --- README.md | 6 +++--- bin/make-base-vm | 6 ------ etc/lxc.config.in | 11 ++++++----- libexec/config-lxc | 9 +++++++++ libexec/make-clean-vm | 2 +- libexec/on-target | 2 ++ target-bin/bootstrap-fixup | 14 ++++++++++++-- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f28ee86..2bf0342 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,10 @@ Recent distributions allow lxc-start to be run by non-priviledged users, so you If you have a runaway `lxc-start` command, just use `kill -9` on it. -The machine configuration requires access to br0 and assumes that the host address is 10.0.2.2: +The machine configuration requires access to lxcbr0 and assumes that the host address is 10.0.3.1 . If lxc does not configure lxcbr0 on boot, you can do so manually: - sudo brctl addbr br0 - sudo ifconfig br0 10.0.2.2/24 up + sudo brctl addbr lxcbr0 + sudo ifconfig lxcbr0 10.0.3.1/24 up ## Tests diff --git a/bin/make-base-vm b/bin/make-base-vm index 899a86b..83f005b 100755 --- a/bin/make-base-vm +++ b/bin/make-base-vm @@ -16,12 +16,6 @@ usage() { --suite U build suite U instead of lucid --arch A build architecture A (e.g. i386) instead of amd64 --lxc use lxc instead of kvm - - The MIRROR_HOST environment variable can be used to change the - apt-cacher host. It should be something that the target VM can - resolve. It may be set to 127.0.0.1, in which case it will be - changed to 10.0.2.2 on the guest. 10.0.2.2 is the host IP as visible - from the guest under qemu networking. EOF } diff --git a/etc/lxc.config.in b/etc/lxc.config.in index b4c02e5..91c6d86 100644 --- a/etc/lxc.config.in +++ b/etc/lxc.config.in @@ -23,10 +23,11 @@ lxc.cgroup.devices.allow = c 254:0 rwm lxc.mount.entry=proc ROOTFS/proc proc nodev,noexec,nosuid 0 0 lxc.mount.entry=sysfs ROOTFS/sys sysfs defaults 0 0 -# Container with network virtualized using a pre-configured bridge named br0 and -# veth pair virtual network devices -# On the host, run: ifconfig br0 up 10.0.2.2 +# Container with network virtualized using a pre-configured bridge named lxcbr0 +# and veth pair virtual network devices. +# On the host, run (lxc might already have done this): +# ifconfig lxcbr0 up 10.0.3.1 lxc.network.type = veth lxc.network.flags = up -lxc.network.link = br0 -lxc.network.ipv4 = 10.0.2.5/24 +lxc.network.link = lxcbr0 +lxc.network.ipv4 = 10.0.3.5/24 diff --git a/libexec/config-lxc b/libexec/config-lxc index bc401af..89ba5d8 100755 --- a/libexec/config-lxc +++ b/libexec/config-lxc @@ -1,4 +1,13 @@ #!/bin/bash +set -e + +if ifconfig lxcbr0 > /dev/null 2>&1; then + true +else + echo "Must configure lxcbr0 - check the README" + exit 1 +fi + wd=`pwd` sed "s;ROOTFS;$wd/target-$LXC_SUITE-$LXC_ARCH;;s;ARCH;$LXC_ARCH;g" < etc/lxc.config.in > var/lxc.config diff --git a/libexec/make-clean-vm b/libexec/make-clean-vm index cf7d658..59fc99c 100755 --- a/libexec/make-clean-vm +++ b/libexec/make-clean-vm @@ -48,5 +48,5 @@ if [ -z "$USE_LXC" ]; then qemu-img create -f qcow2 -o backing_file="$BASE.qcow2" "$OUT.qcow2" else cp -a $BASE $OUT - on-target -u root bash < target-bin/bootstrap-fixup + on-target -u root /root/firstboot.sh fi diff --git a/libexec/on-target b/libexec/on-target index 8f1ceb4..eaebe9f 100755 --- a/libexec/on-target +++ b/libexec/on-target @@ -1,5 +1,7 @@ #!/bin/sh +set -e + . gconfig TUSER=ubuntu diff --git a/target-bin/bootstrap-fixup b/target-bin/bootstrap-fixup index d6e77c6..8eeae28 100755 --- a/target-bin/bootstrap-fixup +++ b/target-bin/bootstrap-fixup @@ -2,5 +2,15 @@ set -e -echo 'deb http://10.0.2.2:3142/archive.ubuntu.com/ubuntu lucid main universe' > $1/etc/apt/sources.list -echo 'deb http://10.0.2.2:3142/archive.ubuntu.com/ubuntu lucid-updates main universe' >> $1/etc/apt/sources.list +ip=`hostname --all-ip-addresses | cut -d ' ' -f1 | cut -d. -f1-3` + +if [ $ip = "10.0.3" ]; then + # LXC + MIRROR_HOST_ON_GUEST=${MIRROR_HOST_ON_GUEST:-10.0.3.1} +else + # KVM + MIRROR_HOST_ON_GUEST=${MIRROR_HOST_ON_GUEST:-10.0.2.2} +fi + +echo "deb http://$MIRROR_HOST_ON_GUEST:3142/archive.ubuntu.com/ubuntu lucid main universe" > $1/etc/apt/sources.list +echo "deb http://$MIRROR_HOST_ON_GUEST:3142/archive.ubuntu.com/ubuntu lucid-updates main universe" >> $1/etc/apt/sources.list