Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
VM=$1
size=`sudo lvs -o lv_size --unit=b --noheadings /dev/vg_vms/ubuntu-base-vm | sed 's/^ *//'`
echo size=$size
sudo lvcreate --size=$size --name=vms-$VM vg_vms
sudo virt-resize --expand sda1 \
/dev/vg_vms/ubuntu-base-vm /dev/vg_vms/vms-$VM
mkdir -p tmp
virsh dumpxml ubuntu-base-vm > tmp/ubuntu-base-vm.xml
mac=`egrep "^$VM"'\s' ips.txt | awk '{print $3}'`; echo $mac
python ./modify-domain.py \
--name $VM \
--new-uuid \
--device-path=/dev/vg_vms/vms-$VM \
--mac-address $mac \
< tmp/ubuntu-base-vm.xml > tmp/$VM.xml
virsh define tmp/$VM.xml
virsh dumpxml $VM
ip=`egrep "^$VM\s" ips.txt | awk '{print $2}'`; echo $ip
sed -e "s/IP_ADDRESS_GOES_HERE/$ip/g" -e "s/VM_NAME_GOES_HERE/$VM/g" < templates/hosts > tmp/hosts.$VM
sed -e "s/IP_ADDRESS_GOES_HERE/$ip/g" -e "s/VM_NAME_GOES_HERE/$VM/g" < templates/network-interfaces > tmp/network-interfaces.$VM
sed -e "s/IP_ADDRESS_GOES_HERE/$ip/g" -e "s/VM_NAME_GOES_HERE/$VM/g" < templates/configure.sh > tmp/configure.sh.$VM
chmod a+x tmp/configure.sh.$VM
sudo virt-sysprep -d $VM \
--verbose \
--enable udev-persistent-net,bash-history,hostname,logfiles,utmp,script \
--hostname $VM \
--script `pwd`/tmp/configure.sh.$VM
virsh start $VM
#!/bin/bash
VM=$1
virsh destroy $VM
rm /var/lib/libvirt/images/$VM-start.qcow2
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$VM.qcow2 /var/lib/libvirt/images/$VM-start.qcow2
virsh start $VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.