#!/bin/bash
case "$1" in
start)
virsh start $2
echo starting $2
;;
view)
virt-viewer $2
echo viewing $2
;;
shutdown)
virsh shutdown $2
echo being shutdown $2
;;
destroy)
virsh destroy $2
echo being destroy $2
;;
restart)
echo poweroff $2 ...
virsh destroy $2 &> /dev/null
echo del $1.xml ...
virsh undefine $2 &> /dev/null
echo create disk ...
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$2.qcow2 /var/lib/libvirt/images/$3.qcow2 &> /dev/null
echo create $2 vm...
virt-install \
--name $3 \
--ram 1000 \
--disk /var/lib/libvirt/images/$3.qcow2 \
--import &> /dev/null &
echo created $3 successful !!!
;;
*)
echo "please input exactly."
esac
原文地址:http://12110661.blog.51cto.com/12100661/1863358