Skip to content

Commit

Permalink
improved LXC support
Browse files Browse the repository at this point in the history
fixes #86
  • Loading branch information
devrandom committed May 17, 2015
1 parent df8381b commit af56f89
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
8 changes: 8 additions & 0 deletions RELEASE_NOTES
@@ -1,3 +1,11 @@
2015-05-16
----------

LXC support has been revamped:

* debootstrap is now used directly, so that no kernel or grub packages are installed
* 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

2015-03-23
----------

Expand Down
56 changes: 38 additions & 18 deletions bin/make-base-vm
Expand Up @@ -74,7 +74,13 @@ if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
FLAVOUR=server
fi

addpkg=openssh-server,pciutils,build-essential,git-core,subversion,lxc,linux-image-generic
addpkg=pciutils,build-essential,git-core,subversion

if [ $LXC = "1" ]; then
addpkg=$addpkg,lxc

This comment has been minimized.

Copy link
@gurnec

gurnec May 17, 2015

Contributor

Minor annoyance: Bitcoin includes export LC_ALL='en_US.UTF-8' in its build script, which causes every bash script (lots...) during the build to litter build.log with:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

Adding an additional package above fixes this:

addpkg=$addpkg,lxc,language-pack-en
else
addpkg=$addpkg,linux-image-generic,grub-pc,openssh-server
fi

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

if [ -e $OUT.qcow2 ]; then
echo $OUT.qcow2 already exists, please remove it first
exit 1
if [ $LXC = "1" ]; then
if [ -e $OUT ]; then
echo $OUT already exists, please remove it first
#exit 1
fi
else
if [ -e $OUT.qcow2 ]; then
echo $OUT.qcow2 already exists, please remove it first
exit 1
fi
fi

libexec/config-bootstrap-fixup
rm -rf $OUT
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
mv $OUT/*.qcow2 $OUT.qcow2
rm -rf $OUT

if [ $LXC = "1" ]; then
#sudo debootstrap --include=$addpkg --arch=$ARCH $SUITE $OUT-root $MIRROR
echo Extracting partition for lxc
qemu-img convert $OUT.qcow2 $OUT.raw
loop=`sudo kpartx -av $OUT.raw|sed -n '/loop.p1/{s/.*loop\(.\)p1.*/\1/;p}'`
sudo cp --sparse=always /dev/mapper/loop${loop}p1 $OUT
sudo chown $USER $OUT
sudo kpartx -d /dev/loop$loop
rm -f $OUT.raw
sudo rm -rf $OUT-bootstrap
# Need universe for lxc in lucid
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
dd if=/dev/zero of=$OUT-lxc bs=1M count=1 seek=10240
mkfs.ext4 $OUT-lxc

This comment has been minimized.

Copy link
@gurnec

gurnec May 17, 2015

Contributor

Minor annoyance: during a make-base-vm, you're asked:

... is not a block special device.
Proceed anyway? (y,n)

You could change the above to this to skip the prompt:

mkfs.ext4 -F $OUT-lxc
t=`mktemp -d gitian.XXXXXXXX`
sudo mount $OUT-lxc $t
sudo cp -a $OUT-bootstrap/* $t
sudo umount $t
rmdir $t

sudo rm -rf $OUT-bootstrap
mv $OUT-lxc $OUT
# bootstrap-fixup is done in libexec/make-clean-vm
else
libexec/config-bootstrap-fixup

rm -rf $OUT
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
mv $OUT/*.qcow2 $OUT.qcow2
rm -rf $OUT
# bootstrap-fixup is done on first boot
fi

1 change: 1 addition & 0 deletions etc/lxc.config.in
Expand Up @@ -32,3 +32,4 @@ lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = GUESTLINK
lxc.network.ipv4 = GUESTIP/24
lxc.utsname = gitian
7 changes: 6 additions & 1 deletion libexec/gconfig
@@ -1,4 +1,9 @@
VM_SSH_PORT=2223
if [ -z "$LXC_EXECUTE" ]; then
LXC_EXECUTE=lxc-start
ver=`lxc-start --version`
if dpkg --compare-versions $ver ge 1.1.0 ; then
LXC_EXECUTE=lxc-execute
else
LXC_EXECUTE=lxc-start
fi
fi
13 changes: 13 additions & 0 deletions target-bin/bootstrap-fixup.in
Expand Up @@ -5,4 +5,17 @@ set -e
. /etc/lsb-release

echo "deb http://HOSTIP:3142/archive.ubuntu.com/ubuntu $DISTRIB_CODENAME main universe" > $1/etc/apt/sources.list
echo "deb http://HOSTIP:3142/security.ubuntu.com/ubuntu $DISTRIB_CODENAME-security main universe" >> $1/etc/apt/sources.list
echo "deb http://HOSTIP:3142/archive.ubuntu.com/ubuntu $DISTRIB_CODENAME-updates main universe" >> $1/etc/apt/sources.list
echo '127.0.1.1 gitian' >> /etc/hosts

# If LXC
if grep /lxc/gitian /proc/1/cgroup > /dev/null; then
apt-get remove -y rsyslog
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
dpkg-divert --local --rename --add /usr/bin/ischroot
ln -s /bin/true /usr/bin/ischroot
echo lxc hold | dpkg --set-selections || true
echo cgmanager hold | dpkg --set-selections || true

This comment has been minimized.

Copy link
@gurnec

gurnec May 17, 2015

Contributor

The resulting base VM is missing user ubuntu which causes gbuild to fail; you could add this line here to fix this:

    adduser --disabled-password --gecos ubuntu --quiet ubuntu || true
fi
3 changes: 0 additions & 3 deletions target-bin/upgrade-system.sh
Expand Up @@ -9,9 +9,6 @@ mkdir -p /var/cache/gitian
# remove obsolete grub, it causes package dependency issues
apt-get -q -y purge grub > /dev/null 2>&1 || true

# prevent upgrade of grub-pc, it fails to find a boot drive in lxc containers
echo grub-pc hold | dpkg --set-selections || true

# upgrade packages
DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade > /dev/null > /var/cache/gitian/upgrade.log 2>&1

Expand Down

1 comment on commit af56f89

@devrandom
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gurnec these have been implemented. I also switched to using /usr/sbin/policy-rc.d instead of holding packages.

Please sign in to comment.