build vm with vmdebootstrap
This commit is contained in:
parent
4f28c2c548
commit
9d0b50bced
4 changed files with 97 additions and 36 deletions
|
@ -2,10 +2,10 @@ Create virtual disk of pan.do/ra
|
||||||
|
|
||||||
== Preparations ==
|
== Preparations ==
|
||||||
|
|
||||||
Pan.do/ra VM scripts use python-vm-builder,
|
Pan.do/ra VM scripts use vmdebootstrap 0.9 or later
|
||||||
its available in ubuntu 12.04 and 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 ==
|
== Building ==
|
||||||
|
@ -14,7 +14,12 @@ You can configure some of the arguments in build.sh once done run:
|
||||||
|
|
||||||
./build.sh
|
./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 ==
|
== VirtualBox Usage ==
|
||||||
|
|
66
vm/build.sh
66
vm/build.sh
|
@ -1,30 +1,46 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
size=1048576 #in MB
|
cd "`dirname "$0"`"
|
||||||
arch=amd64 #i368 or amd64
|
BASE=`pwd`
|
||||||
password=pandora
|
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
|
# make sure ubuntu-archive-keyring is installed
|
||||||
extra="--addpkg avahi-daemon"
|
test -e /usr/share/keyrings/ubuntu-archive-keyring.gpg || apt-get install ubuntu-archive-keyring
|
||||||
|
|
||||||
#to create and include in libvirt:
|
vmdebootstrap \
|
||||||
#hypervisor=kvm
|
--image ${TARGET}.img \
|
||||||
#extra="--libvirt qemu:///system"
|
--size ${SIZE} \
|
||||||
|
--sparse \
|
||||||
base=$(pwd)
|
--distribution=${RELEASE} \
|
||||||
sudo vmbuilder $hypervisor ubuntu --suite=trusty \
|
$MIRROR \
|
||||||
--verbose --debug \
|
--enable-dhcp \
|
||||||
--arch $arch \
|
--no-serial-console \
|
||||||
--dest $base/pandora \
|
--no-kernel \
|
||||||
|
--package "linux-image-generic" \
|
||||||
|
--package "avahi-daemon" \
|
||||||
|
--package "ssh" \
|
||||||
|
--mbr \
|
||||||
|
--grub \
|
||||||
|
--sudo \
|
||||||
|
--lock-root-password \
|
||||||
|
--user pandora/pandora \
|
||||||
--hostname pandora \
|
--hostname pandora \
|
||||||
--swapsize 512 \
|
--customize "${BASE}/prepare.sh" \
|
||||||
--rootsize $size \
|
--log ${TARGET}.log --log-level debug --verbose
|
||||||
--user pandora \
|
|
||||||
--pass $password \
|
echo "Installing pan.do/ra in VM"
|
||||||
--addpkg linux-image-generic \
|
qemu-system-x86_64 -enable-kvm -name pandora -m 1024 -drive "format=raw,file=${TARGET}.img" -vnc :2
|
||||||
--components main,universe,multiverse \
|
rm -rf "${TARGET}"
|
||||||
--firstboot=$base/firstboot.sh \
|
/usr/bin/VBoxManage convertfromraw -format VDI "${TARGET}.img" "${TARGET}"
|
||||||
$extra
|
rm "${TARGET}.img"
|
||||||
|
|
|
@ -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
47
vm/prepare.sh
Executable 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"
|
||||||
|
|
Loading…
Reference in a new issue