From 9970fcd0ef6dfd33f30a10cba4e754b1fd2070b0 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 17 Mar 2017 01:21:24 +0100 Subject: [PATCH] create vm based on cloud image --- vm/LXC_README.txt | 2 +- vm/README.txt | 12 +++------ vm/build.sh | 62 +++++++++++++---------------------------------- vm/cloud-config | 22 +++++++++++++++++ vm/prepare.sh | 58 -------------------------------------------- 5 files changed, 44 insertions(+), 112 deletions(-) create mode 100644 vm/cloud-config delete mode 100755 vm/prepare.sh diff --git a/vm/LXC_README.txt b/vm/LXC_README.txt index bcb0f1bf..6e7e8ae3 100644 --- a/vm/LXC_README.txt +++ b/vm/LXC_README.txt @@ -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 diff --git a/vm/README.txt b/vm/README.txt index e6ff7df3..9933ed98 100644 --- a/vm/README.txt +++ b/vm/README.txt @@ -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://:3142/archive.ubuntu.com/ubuntu/ --configure-apt" -./build.sh - == VirtualBox Usage == diff --git a/vm/build.sh b/vm/build.sh index 1e9d1087..a6efeb45 100755 --- a/vm/build.sh +++ b/vm/build.sh @@ -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" diff --git a/vm/cloud-config b/vm/cloud-config new file mode 100644 index 00000000..f516c80b --- /dev/null +++ b/vm/cloud-config @@ -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 diff --git a/vm/prepare.sh b/vm/prepare.sh deleted file mode 100755 index bd5abef8..00000000 --- a/vm/prepare.sh +++ /dev/null @@ -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" < $SOURCE_LIST <> "$rootdir/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