Skip to content

Commit af56f89

Browse files
committed
improved LXC support
fixes #86
1 parent df8381b commit af56f89

File tree

6 files changed

+66
-22
lines changed

6 files changed

+66
-22
lines changed

RELEASE_NOTES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2015-05-16
2+
----------
3+
4+
LXC support has been revamped:
5+
6+
* debootstrap is now used directly, so that no kernel or grub packages are installed
7+
* an attempt has been made to eliminate cases where an update of a package can fail because the container is missing a real init/upstart process
8+
19
2015-03-23
210
----------
311

bin/make-base-vm

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
7474
FLAVOUR=server
7575
fi
7676

77-
addpkg=openssh-server,pciutils,build-essential,git-core,subversion,lxc,linux-image-generic
77+
addpkg=pciutils,build-essential,git-core,subversion
78+
79+
if [ $LXC = "1" ]; then
80+
addpkg=$addpkg,lxc
81+
else
82+
addpkg=$addpkg,linux-image-generic,grub-pc,openssh-server
83+
fi
7884

7985
# Remove cron to work around vmbuilder issue when umounting /dev on target
8086
removepkg=cron
@@ -99,26 +105,40 @@ if [ $VBOX = "1" ]; then
99105
exit 0
100106
fi
101107

102-
if [ -e $OUT.qcow2 ]; then
103-
echo $OUT.qcow2 already exists, please remove it first
104-
exit 1
108+
if [ $LXC = "1" ]; then
109+
if [ -e $OUT ]; then
110+
echo $OUT already exists, please remove it first
111+
#exit 1
112+
fi
113+
else
114+
if [ -e $OUT.qcow2 ]; then
115+
echo $OUT.qcow2 already exists, please remove it first
116+
exit 1
117+
fi
105118
fi
106119

107-
libexec/config-bootstrap-fixup
108-
rm -rf $OUT
109-
env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo vmbuilder kvm ubuntu --rootsize 10240 --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --removepkg=$removepkg --ssh-key=var/id_dsa.pub --ssh-user-key=var/id_dsa.pub --mirror=$MIRROR --security-mirror=$SECURITY_MIRROR --dest=$OUT --flavour=$FLAVOUR --firstboot=`pwd`/target-bin/bootstrap-fixup
110-
mv $OUT/*.qcow2 $OUT.qcow2
111-
rm -rf $OUT
112-
113120
if [ $LXC = "1" ]; then
114-
#sudo debootstrap --include=$addpkg --arch=$ARCH $SUITE $OUT-root $MIRROR
115-
echo Extracting partition for lxc
116-
qemu-img convert $OUT.qcow2 $OUT.raw
117-
loop=`sudo kpartx -av $OUT.raw|sed -n '/loop.p1/{s/.*loop\(.\)p1.*/\1/;p}'`
118-
sudo cp --sparse=always /dev/mapper/loop${loop}p1 $OUT
119-
sudo chown $USER $OUT
120-
sudo kpartx -d /dev/loop$loop
121-
rm -f $OUT.raw
121+
sudo rm -rf $OUT-bootstrap
122+
# Need universe for lxc in lucid
123+
env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo debootstrap --arch=$ARCH --include=$addpkg --exclude=$removepkg --components=main,universe $SUITE $OUT-bootstrap $MIRROR
124+
dd if=/dev/zero of=$OUT-lxc bs=1M count=1 seek=10240
125+
mkfs.ext4 $OUT-lxc
126+
t=`mktemp -d gitian.XXXXXXXX`
127+
sudo mount $OUT-lxc $t
128+
sudo cp -a $OUT-bootstrap/* $t
129+
sudo umount $t
130+
rmdir $t
131+
132+
sudo rm -rf $OUT-bootstrap
133+
mv $OUT-lxc $OUT
122134
# bootstrap-fixup is done in libexec/make-clean-vm
135+
else
136+
libexec/config-bootstrap-fixup
137+
138+
rm -rf $OUT
139+
env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo vmbuilder kvm ubuntu --rootsize 10240 --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --removepkg=$removepkg --ssh-key=var/id_dsa.pub --ssh-user-key=var/id_dsa.pub --mirror=$MIRROR --security-mirror=$SECURITY_MIRROR --dest=$OUT --flavour=$FLAVOUR --firstboot=`pwd`/target-bin/bootstrap-fixup
140+
mv $OUT/*.qcow2 $OUT.qcow2
141+
rm -rf $OUT
142+
# bootstrap-fixup is done on first boot
123143
fi
124144

etc/lxc.config.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ lxc.network.type = veth
3232
lxc.network.flags = up
3333
lxc.network.link = GUESTLINK
3434
lxc.network.ipv4 = GUESTIP/24
35+
lxc.utsname = gitian

libexec/gconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
VM_SSH_PORT=2223
22
if [ -z "$LXC_EXECUTE" ]; then
3-
LXC_EXECUTE=lxc-start
3+
ver=`lxc-start --version`
4+
if dpkg --compare-versions $ver ge 1.1.0 ; then
5+
LXC_EXECUTE=lxc-execute
6+
else
7+
LXC_EXECUTE=lxc-start
8+
fi
49
fi

target-bin/bootstrap-fixup.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,17 @@ set -e
55
. /etc/lsb-release
66

77
echo "deb http://HOSTIP:3142/archive.ubuntu.com/ubuntu $DISTRIB_CODENAME main universe" > $1/etc/apt/sources.list
8+
echo "deb http://HOSTIP:3142/security.ubuntu.com/ubuntu $DISTRIB_CODENAME-security main universe" >> $1/etc/apt/sources.list
89
echo "deb http://HOSTIP:3142/archive.ubuntu.com/ubuntu $DISTRIB_CODENAME-updates main universe" >> $1/etc/apt/sources.list
10+
echo '127.0.1.1 gitian' >> /etc/hosts
11+
12+
# If LXC
13+
if grep /lxc/gitian /proc/1/cgroup > /dev/null; then
14+
apt-get remove -y rsyslog
15+
dpkg-divert --local --rename --add /sbin/initctl
16+
ln -s /bin/true /sbin/initctl
17+
dpkg-divert --local --rename --add /usr/bin/ischroot
18+
ln -s /bin/true /usr/bin/ischroot
19+
echo lxc hold | dpkg --set-selections || true
20+
echo cgmanager hold | dpkg --set-selections || true
21+
fi

target-bin/upgrade-system.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ mkdir -p /var/cache/gitian
99
# remove obsolete grub, it causes package dependency issues
1010
apt-get -q -y purge grub > /dev/null 2>&1 || true
1111

12-
# prevent upgrade of grub-pc, it fails to find a boot drive in lxc containers
13-
echo grub-pc hold | dpkg --set-selections || true
14-
1512
# upgrade packages
1613
DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade > /dev/null > /var/cache/gitian/upgrade.log 2>&1
1714

0 commit comments

Comments
 (0)