#######虚拟机快照#####
qemu-img create -f qcwo2 -b vm2.qcwo2 node1.qcow2
@@此处注意"\"后不能有任何符号
1 #!/bin/bash
2 echo poweroff $1 ...
3 virsh destroy $1 &> /dev/null
4 echo del $1.xml ...
5 virsh undefine $1 &> /dev/null
6 echo create disk ...
7 qemu-img create -f qcow2 -b /var/lib/libvirt/images/$1.qcow2 /var/lib/libvir t/images/$2.qcow2 &> /dev/null
8 echo create $1 vm ...
9 virt-install \
10 --name $2 \
11 --ram 1000 \
12 --disk /var/lib/libvirt/images/$2.qcow2 \
13 --import &> /dev/null &
14 echo Successful!
编写虚拟机的执行脚本
@@此处注意"\"后不能有任何符号
1 #!/bin/bash
2 case "$1" in
3 reset)
4 virsh destroy $2 &> /dev/null
5 virsh undefine $2 &> /dev/null
6 qemu-img create -f qcow2 -b /var/lib/libvirt/images/nn.qcow2 /var/lib/libvirt/images/$2.qcow2 &> /dev/null
7 virt-install \
8 --name $2 \
9 --ram 1000 \
10 --disk /var/lib/libvirt/images/$2.qcow2 \
11 --import &> /dev/null &
12 echo successful!
13 ;;
14 shutdown)
15 echo shutdown ...
16 virsh shutdown $2 &> /dev/null
17 ;;
18 poweroff | destroy)
19 echo Powering off $2
20 virsh destroy $2 &> /dev/null
21 ;;
22 start)
23 echo starting ...
24 virsh start $2 &> /dev/null
25 ;;
26 view)
27 echo Waitting for a momount ....
28 virt-viewer $2 &> /dev/null &
29 ;;
30 set)
31 qemu-img create -f qcow2 -b /var/lib/libvirt/images/nn.qcow2 /var/lib/libvirt/images/$2.qcow2 &> /dev/null
32 virt-install \
33 --name $2 \
34 --ram 1000 \
35 --disk /var/lib/libvirt/images/$2.qcow2 \
36 --import &> /dev/null &
37 echo set successful!
38 ;;
39 *)
40 echo Error:can not found... "Please input reset|set|start|poweroff|shutdown after xuniji.sh"
41 ;;
42 esac
效果如下:
本文出自 “12097560” 博客,请务必保留此出处http://12107560.blog.51cto.com/12097560/1863353
原文地址:http://12107560.blog.51cto.com/12097560/1863353