build vm with vmdebootstrap

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

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"