快速克隆 KVM ,shell脚本如下
# 需要准备 :[ .kvm-master.xml / .kvm-master.qcow2]
# 已经创建的虚拟机的 xml文件 / img文件 可以做为模板
#!/bin/bash
. /etc/init.d/functions
ONF_DIR=/etc/libvirt/qemu
IMG_DIR=/var/lib/libvirt/images
function createvm(){
if [ -e ${IMG_DIR}/${1}.img ];then
echo "警告 xn ${1}.img 已经存在"
return 1
else
qemu-img create -b ${IMG_DIR}/.kvm-master.qcow2 -f \
qcow2 ${IMG_DIR}/${1}.img 40G &>/dev/null
sed -e "s,kvm-name,${1}," ${IMG_DIR}/.kvm-master.xml >${CONF_DIR}/${1}.xml
sudo virsh define ${CONF_DIR}/${1}.xml &>/dev/null
echo "' xn ${1} 创建成功"
fi
}
if (( $# == 0 ));then
echo "$0 xn1 xn2 xn3 ... ..."
else
for i in $@;do
createvm ${i}
done
fi
exit 0
网友评论