Browse Source

Use image file for lxc

tags/0.1
devrandom 8 years ago
parent
commit
0bc83c5f44
4 changed files with 24 additions and 23 deletions
  1. 18
    17
      bin/make-base-vm
  2. 1
    1
      libexec/config-lxc
  3. 4
    5
      libexec/make-clean-vm
  4. 1
    0
      target-bin/bootstrap-fixup

+ 18
- 17
bin/make-base-vm View File

@@ -70,24 +70,25 @@ fi

addpkg=openssh-server,pciutils,build-essential,git-core,subversion

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

rm -rf $OUT
sudo vmbuilder kvm ubuntu --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --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
else
if [ -e $OUT ]; then
echo $OUT already exists, please remove it first
exit 1
fi
rm -rf $OUT
sudo vmbuilder kvm ubuntu --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --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

rm -rf $OUT-root
sudo debootstrap --include=$addpkg --arch=$ARCH $SUITE $OUT-root $MIRROR
sudo target-bin/bootstrap-fixup $OUT-root
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/ i\1'`
sudo cp --sparse=always /dev/mapper/loop${loop}p1 $OUT
sudo chown $USER $OUT
sudo kpartx -d /dev/loop$loop
rm -f $OUT.raw
# bootstrap-fixup is done in libexec/make-clean-vm
fi


+ 1
- 1
libexec/config-lxc View File

@@ -1,4 +1,4 @@
#!/bin/bash

wd=`pwd`
sed "s;ROOTFS;$wd/target-$LXC_SUITE-$LXC_ARCH-root;;s;ARCH;$LXC_ARCH;g" < etc/lxc.config.in > var/lxc.config
sed "s;ROOTFS;$wd/target-$LXC_SUITE-$LXC_ARCH;;s;ARCH;$LXC_ARCH;g" < etc/lxc.config.in > var/lxc.config

+ 4
- 5
libexec/make-clean-vm View File

@@ -41,13 +41,12 @@ if [ $# != 0 ] ; then
done
fi

BASE=base-$SUITE-$ARCH-root
OUT=target-$SUITE-$ARCH-root
BASE=base-$SUITE-$ARCH
OUT=target-$SUITE-$ARCH

if [ -z "$USE_LXC" ]; then
qemu-img create -f qcow2 -o backing_file="$BASE.qcow2" "$OUT.qcow2"
else
sudo rm -rf $OUT
sudo cp -a $BASE $OUT
on-target -u root useradd -m ubuntu
cp -a $BASE $OUT
on-target -u root bash < target-bin/bootstrap-fixup
fi

+ 1
- 0
target-bin/bootstrap-fixup View File

@@ -3,3 +3,4 @@
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

Loading…
Cancel
Save