#!/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