build vm with vmdebootstrap

This commit is contained in:
j 2016-03-05 18:36:39 +05:30
parent 4f28c2c548
commit 9d0b50bced
4 changed files with 97 additions and 36 deletions

View file

@ -2,10 +2,10 @@ Create virtual disk of pan.do/ra
== Preparations ==
Pan.do/ra VM scripts use python-vm-builder,
its available in ubuntu 12.04 and later
Pan.do/ra VM scripts use vmdebootstrap 0.9 or later
You also need qemu to run the vm and virtualbox to convert the image
apt-get install python-vm-builder
apt-get install vmdebootstrap virtualbox qemu
== Building ==
@ -14,7 +14,12 @@ You can configure some of the arguments in build.sh once done run:
./build.sh
this will create a vdi image in pandora/
this will create a vdi image in pandora-r{REVISON}.vdi
If you have a local apt-cacher instance export MIRROR:
export MIRROR="--mirror http://<LOCAL IP>:3142/archive.ubuntu.com/ubuntu/ --configure-apt"
./build.sh
== VirtualBox Usage ==

View file

@ -1,30 +1,46 @@
#!/bin/sh
size=1048576 #in MB
arch=amd64 #i368 or amd64
password=pandora
#!/bin/bash
cd "`dirname "$0"`"
BASE=`pwd`
VERSION=`cd ..;git rev-list HEAD --count`
TARGET=${BASE}/pandora-r${VERSION}.vdi
SIZE=1T
RELEASE=trusty
hypervisor=vbox #vbox or kvm
if [ "$MIRROR" = "" ]; then
MIRROR="--mirror http://archive.ubuntu.com/ubuntu/"
fi
extra=""
if [ $(id -u) -ne 0 ]; then
echo "you need to run $0 as root"
exit 1
fi
#make available as pandora.local
extra="--addpkg avahi-daemon"
# make sure ubuntu-archive-keyring is installed
test -e /usr/share/keyrings/ubuntu-archive-keyring.gpg || apt-get install ubuntu-archive-keyring
#to create and include in libvirt:
#hypervisor=kvm
#extra="--libvirt qemu:///system"
base=$(pwd)
sudo vmbuilder $hypervisor ubuntu --suite=trusty \
--verbose --debug \
--arch $arch \
--dest $base/pandora \
vmdebootstrap \
--image ${TARGET}.img \
--size ${SIZE} \
--sparse \
--distribution=${RELEASE} \
$MIRROR \
--enable-dhcp \
--no-serial-console \
--no-kernel \
--package "linux-image-generic" \
--package "avahi-daemon" \
--package "ssh" \
--mbr \
--grub \
--sudo \
--lock-root-password \
--user pandora/pandora \
--hostname pandora \
--swapsize 512 \
--rootsize $size \
--user pandora \
--pass $password \
--addpkg linux-image-generic \
--components main,universe,multiverse \
--firstboot=$base/firstboot.sh \
$extra
--customize "${BASE}/prepare.sh" \
--log ${TARGET}.log --log-level debug --verbose
echo "Installing pan.do/ra in VM"
qemu-system-x86_64 -enable-kvm -name pandora -m 1024 -drive "format=raw,file=${TARGET}.img" -vnc :2
rm -rf "${TARGET}"
/usr/bin/VBoxManage convertfromraw -format VDI "${TARGET}.img" "${TARGET}"
rm "${TARGET}.img"

View file

@ -1,7 +0,0 @@
#!/bin/sh
apt-get update -q
apt-get install -y curl
curl -L https://pan.do/ra-install > /root/pandora_install.sh
chmod 755 /root/pandora_install.sh
/root/pandora_install.sh >/root/pandora_install.log 2>&1
rm /root/pandora_install.sh

47
vm/prepare.sh Executable file
View file

@ -0,0 +1,47 @@
#!/bin/sh
set -e
rootdir=$1
base=$(dirname $0)
RELEASE=trusty
cat > "$rootdir/root/pandora_install" << EOF
#!/bin/bash
DEBIAN_FRONTEND=noninteractive
sed -i "s/main/main restricted universe multiverse/g" /etc/apt/sources.list.d/base.list
apt-get update
apt-get -y --force-yes dist-upgrade
EOF
cat "$base/pandora_install.sh" >> "$rootdir/root/pandora_install"
#reset install proxy settings
cat >> "$rootdir/root/pandora_install" <<EOF
cat > /etc/apt/sources.list.d/base.list <<EOS
deb http://archive.ubuntu.com/ubuntu $RELEASE main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu $RELEASE main restricted universe multiverse
EOS
apt-get -qq update
sed -i \
-e 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="silent"/g' \
/etc/default/grub
update-grub
EOF
chmod +x "$rootdir/root/pandora_install"
test -e "$rootdir/etc/rc.local" && mv "$rootdir/etc/rc.local" "$rootdir/etc/rc.local.orig"
cat > "$rootdir/etc/rc.local" <<EOF
#!/bin/sh -e
#execute pandora_install
if [ -e /root/pandora_install ]; then
/root/pandora_install 2>&1 | tee /root/pandora_install.log || true
mv /root/pandora_install /root/pandora_installed
shutdown -h now
fi
exit 0
EOF
chmod +x "$rootdir/etc/rc.local"