create vm based on cloud image

This commit is contained in:
j 2017-03-17 01:21:24 +01:00
parent 18bdc1e6d6
commit 9970fcd0ef
5 changed files with 44 additions and 112 deletions

View file

@ -1,6 +1,6 @@
== Installing pan.do/ra inside LXC ==
1) Install lxc on the host (Ubuntu 14.04 or later):
1) Install lxc on the host (Ubuntu 16.04 or later):
sudo apt-get install lxc

View file

@ -2,10 +2,11 @@ Create virtual disk of pan.do/ra
== Preparations ==
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
Pan.do/ra VM are based on cloud images.
You also qemu to run the vm and virtualbox to convert the image
apt-get install vmdebootstrap virtualbox qemu
apt-get install vmdebootstrap virtualbox qemu qemu-utils
apt-get install kvm cloud-utils
== Building ==
@ -16,11 +17,6 @@ You can configure some of the arguments in build.sh once done run:
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,56 +1,28 @@
#!/bin/bash
cd "`dirname "$0"`"
# apt-get install kvm cloud-utils qemu-utils curl
BASE=`pwd`
VERSION=`cd ..;git rev-list HEAD --count`
TARGET=${BASE}/pandora-r${VERSION}.vdi
SIZE=1T
RELEASE=trusty
if [ "$MIRROR" = "" ]; then
MIRROR="--mirror http://archive.ubuntu.com/ubuntu/"
fi
img=xenial-server-cloudimg-amd64-disk1.img
if [ -e "$BASE/settings.sh" ]; then
. "$BASE/settings.sh"
fi
test -e $img || curl -O https://cloud-images.ubuntu.com/xenial/current/$img
cp --reflink=always $img ${TARGET}.img
if [ $(id -u) -ne 0 ]; then
echo "you need to run $0 as root"
exit 1
fi
cloud-localds seed.img cloud-config
qemu-img resize ${TARGET}.img +998G
# make sure ubuntu-archive-keyring is installed
test -e /usr/share/keyrings/ubuntu-archive-keyring.gpg || apt-get install ubuntu-archive-keyring
echo boot image and install pandora
kvm -m 1024 \
-smp 4 \
-cdrom seed.img \
-device e1000,netdev=user.0 \
-netdev user,id=user.0,hostfwd=tcp::5555-:22,hostfwd=tcp::2620-:80 \
-drive file=${TARGET}.img,if=virtio,cache=writeback,index=0 \
-vnc :2
vmdebootstrap=`vmdebootstrap --version`
if [[ $vmdebootstrap == "1.4" ]]; then
EXTRA=--no-systemd-networkd
fi
vmdebootstrap \
--image ${TARGET}.img \
--size ${SIZE} \
--sparse \
--distribution=${RELEASE} \
$MIRROR \
$EXTRA \
--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 \
--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
echo convert qcow2 to vdi
rm -rf "${TARGET}"
/usr/bin/VBoxManage convertfromraw -format VDI "${TARGET}.img" "${TARGET}"
qemu-img convert -f qcow2 -O vdi "${TARGET}.img" "${TARGET}"
rm "${TARGET}.img"

22
vm/cloud-config Normal file
View file

@ -0,0 +1,22 @@
#cloud-config
hostname: pandora
password: pandora
chpasswd: { expire: False }
ssh_pwauth: True
growpart:
mode: auto
devices: ['/']
ignore_growroot_disabled: false
runcmd:
- sed -i s/ubuntu/pandora/g /etc/passwd /etc/shadow /etc/group
- mv /home/ubuntu /home/pandora
- echo "pandora:pandora" | chpasswd
- apt-get update -qq
- apt-get install -y curl
- curl -sL https://pan.do/ra-install -o /root/pandora_install.sh
- chmod +x /root/pandora_install.sh
- /root/pandora_install.sh | tee /root/pandora_install.log
- sed -i s/console=ttyS0/quiet/g /etc/default/grub /boot/grub/grub.cfg /etc/default/grub.d/50-cloudimg-settings.cfg
- poweroff

View file

@ -1,58 +0,0 @@
#!/bin/sh
set -e
rootdir=$1
BASE=$(dirname $0)
RELEASE=trusty
if [ -e "$BASE/settings.sh" ]; then
. "$BASE/settings.sh"
fi
SOURCE_LIST="/etc/apt/sources.list.d/base.list"
if [ ! -e "$rootdir/$SOURCE_LIST" ]; then
SOURCE_LIST="/etc/apt/sources.list"
fi
cat > "$rootdir/root/pandora_install" << EOF
#!/bin/bash
DEBIAN_FRONTEND=noninteractive
sed -i "s/main\$/main restricted universe multiverse/g" $SOURCE_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 > $SOURCE_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
rm -f /etc/init/pandora_install.conf /pandora_install
shutdown -h now
EOF
chmod +x "$rootdir/root/pandora_install"
cat >> "$rootdir/pandora_install" <<EOF
#!/bin/bash
/root/pandora_install >/root/pandora_install.log 2>&1 &
$INSTALL_EXTRA
EOF
chmod +x "$rootdir/pandora_install"
cat > "$rootdir/etc/init/pandora_install.conf" << EOF
description "install pan.do/ra"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on [!12345]
task
exec /pandora_install
EOF