#!/bin/bash
case $1 in
poweroff)
virsh destroy $2 &> /dev/null &
;;
start)
virsh start $2 &> /dev/null &
virt-viewer $2 &> /dev/null
;;
reboot)
virsh destory $2 &> /dev/null &
virsh start $2 &> /dev/null &
virt-viewer $2 &> /dev/null
;;
create)
virt-install \
--name $2 \
--ram 1000 \
--file /var/lib/libvirt/images/$2.img \
--file-size 8 \
--cdrom /var/ftp/pub/iso/rhel-server-7.1-x86_64-dvd.iso &
;;
backup)
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$2.qcow2 /var/lib/libvirt/images/$3.qcow2 &> /dev/null
virt-install \
--name $3 \
--ram 1000 \
--disk /var/lib/libvirt/images/$3.qcow2 \
--import &> /dev/null &
;;
reset)
rm /var/lib/libvirt/images/$2.qcow2 &> /dev/null
qemu-img create -f qcow2 -b /var/lib/libvirt/images/lcdhahaha.qcow2 /var/lib/libvirt/images/$2.qcow2 &> /dev/null
esac
原文地址:http://12110509.blog.51cto.com/12100509/1863589