需注意:不能随便给末尾加空格
#!/bin/bash
if
[ "$1" = "install" ]
then
virt-install \
--name $2 \
--ram 1024 \
--file /var/lib/libvirt/images/$2.qcow2 \
--file-size 8 \
--cdrom /iso/rhel-server-7.0-x86_64-dvd.iso &
elif
[ "$1" = "start" ]
then
virsh start $2
virt-viewer $2
elif
[ "$1" = "stop" ]
then
virsh destroy $2
elif
[ "$1" = "mksnopshot" ]
then
virsh destroy $2
virsh undefine $2
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$2.qcow2 /var/lib/libvirt/images/$3.qcow2
virt-install \
--name $3 \
--ram 1024 \
--file /var/lib/libvirt/images/$3.qcow2 \
--import &
elif
[ "$1" = "reset" ]
then
virsh reset $2
elif
[ "$1" = "remove" ]
then
virsh destroy $2
virsh undefine $2
rm -fr /var/lib/libvirt/images/$2.qcow2 /var/li b/libvirt/images/$3.qcow2
fi
“`