Domain Cloning
Once a template system has been installed, that system can be cloned. Use the following script to clone your template
clonedomain.sh
LVM_GROUP="vg2"
NAME_ORIGINAL="stretch-template"
LVM_NAME_ORIGINAL="kvm_${NAME_ORIGINAL}_vda"
LVM_SIZE_ORIGINAL=`lvs /dev/${LVM_GROUP}/${LVM_NAME_ORIGINAL} -o LV_SIZE --noheadings --units B --nosuffix`
NAME_CLONE="stretch-clone"
LVM_NAME_CLONE="kvm_${NAME_CLONE}_vda"
if [ $# -eq 0 ]
then
echo "${0}: domain-name"
else
NAME_CLONE=${1}
LVM_NAME_CLONE="kvm_${NAME_CLONE}_vda"
fi
if [ ! -e /dev/${LVM_GROUP}/${LVM_NAME_CLONE} ]
then
# create lvm partition
lvcreate --size ${LVM_SIZE_ORIGINAL}B --name ${LVM_NAME_CLONE} ${LVM_GROUP}
# clone the domain
virt-clone --original ${NAME_ORIGINAL} --name ${NAME_CLONE} --file /dev/${LVM_GROUP}/${LVM_NAME_CLONE} --check path_in_use=off,path_exists=off
else
echo "${0}: refusing to overwrite existing domain"
fi