From 096642065e8e7398a957bebabbbc85b691bec3b4 Mon Sep 17 00:00:00 2001 From: varac Date: Tue, 9 Oct 2012 15:50:55 +0200 Subject: initial commit, create-guest-with-cloudinit + helper scripts --- create-guest-with-cloudinit | 92 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 create-guest-with-cloudinit (limited to 'create-guest-with-cloudinit') diff --git a/create-guest-with-cloudinit b/create-guest-with-cloudinit new file mode 100755 index 0000000..56eec5f --- /dev/null +++ b/create-guest-with-cloudinit @@ -0,0 +1,92 @@ +#!/bin/sh + +VG='vg01' +ETC='/etc/cloudinit' +VARDIR='/var/lib/libvirt/cloudinit' + +fail() { [ $# -eq 0 ] || echo "$@"; exit 1; } +bad_usage() { usage 1>&2; [ $# -eq 0 ] || fail "$@"; exit 1; } + +usage() { + cat < /dev/null 2>&1 +if [ $? -eq 0 ]; then fail "Domain $vmname is defined in libvirt. Please undefine first."; fi + + +lvcreate -L ${size}g -n $vmname $VG +virt-clone -o leap-baseimage-wheezy -n $vmname -f /dev/$VG/$vmname --force + +# resize second (root) partition +echo ",+," | sfdisk -N2 /dev/$VG/$vmname > /dev/null + +libvirt-make-seed-disk $VARDIR/$vmname-user-data.img $userdata +libvirt-write-disk-attach-xml $VARDIR/$vmname-user-data.img > $VARDIR/$vmname-disk-attach.xml + +echo +echo "Attached userdata-disk is at $VARDIR/$vmname-user-data.img" +echo +echo "Finished creating guest $vmname. Enjoy." +echo +echo Press to start the new guest. +read bogus + +echo +echo 'Starting new guest, attaching to console. Exit with Ctrl+]' +echo + +virsh start $vmname +sleep 2 +virsh attach-device $vmname $VARDIR/$vmname-disk-attach.xml +virsh console $vmname + +#do we really need to detach the cloud-init disk ? +#virsh detach-device $vmname $VARDIR/$vmname-disk-attach.xml + + -- cgit v1.2.3