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 == == 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 sudo apt-get install lxc

View file

@ -2,10 +2,11 @@ Create virtual disk of pan.do/ra
== Preparations == == Preparations ==
Pan.do/ra VM scripts use vmdebootstrap 0.9 or later Pan.do/ra VM are based on cloud images.
You also need qemu to run the vm and virtualbox to convert the image 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 == == 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 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 ==

View file

@ -1,56 +1,28 @@
#!/bin/bash #!/bin/bash
cd "`dirname "$0"`" # apt-get install kvm cloud-utils qemu-utils curl
BASE=`pwd` BASE=`pwd`
VERSION=`cd ..;git rev-list HEAD --count` VERSION=`cd ..;git rev-list HEAD --count`
TARGET=${BASE}/pandora-r${VERSION}.vdi TARGET=${BASE}/pandora-r${VERSION}.vdi
SIZE=1T
RELEASE=trusty
if [ "$MIRROR" = "" ]; then img=xenial-server-cloudimg-amd64-disk1.img
MIRROR="--mirror http://archive.ubuntu.com/ubuntu/"
fi
if [ -e "$BASE/settings.sh" ]; then test -e $img || curl -O https://cloud-images.ubuntu.com/xenial/current/$img
. "$BASE/settings.sh" cp --reflink=always $img ${TARGET}.img
fi
if [ $(id -u) -ne 0 ]; then cloud-localds seed.img cloud-config
echo "you need to run $0 as root" qemu-img resize ${TARGET}.img +998G
exit 1
fi
# make sure ubuntu-archive-keyring is installed echo boot image and install pandora
test -e /usr/share/keyrings/ubuntu-archive-keyring.gpg || apt-get install ubuntu-archive-keyring 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` echo convert qcow2 to vdi
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
rm -rf "${TARGET}" 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" 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