1. 准备一个磁盘格式为qcow2的vm(raw格式的磁盘无法创建快照)
方法一:从头安装一个磁盘格式为qcow2的vm
[[email protected] vm]# qemu-img create -f qcow2 -o preallocation=metadata /vm/vm2.qcow2 2G Formatting ‘/vm/vm2.qcow2‘, fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation=‘metadata‘ [[email protected] vm]# qemu-img info vm2.qcow2 image: vm2.qcow2 file format: qcow2 virtual size: 2.0G (2147483648 bytes) disk size: 464K cluster_size: 65536 |
virt-install --name vm2 --vcpus=1 --ram=1024 --disk path=/vm/vm2.qcow2,format=qcow2 --cdrom /root/iso/CentOS-6.6-x86_64-minimal.iso --network bridge:br0 |
方法二:将现存的磁盘格式为raw的vm转换成qcow2的磁盘格式
[[email protected] vm]# qemu-img info vm1-clone image: vm1-clone file format: raw virtual size: 2.0G (2147483648 bytes) disk size: 2.0G |
[[email protected] vm]# qemu-img convert -f raw vm1-clone -O qcow2 vm1-clone.qcow2 [[email protected] vm]# qemu-img info vm1-clone.qcow2 image: vm1-clone.qcow2 file format: qcow2 virtual size: 2.0G (2147483648 bytes) disk size: 813M cluster_size: 65536 |
virsh edit vm1-clone
将
<disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘raw‘ <source file=‘/vm/vm1-clone‘/> <target dev=‘hda‘ bus=‘ide‘/> <address type=‘drive‘ controller=‘0‘ bus=‘0‘ </disk> |
修改为
<disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘ <source file=‘/vm/vm1-clone.qcow2‘/> <target dev=‘hda‘ bus=‘ide‘/> <address type=‘drive‘ controller=‘0‘ bus=‘0‘ </disk> |
2. 创建快照(virsh
snapshot-create)
virsh # snapshot-list vm2 Name Creation Time State ------------------------------------------------------------ virsh # snapshot-create vm2 Domain snapshot 1433458417 created virsh # virsh # snapshot-list vm2 Name Creation Time State ------------------------------------------------------------ 1433458417 2015-06-05 06:53:37 +0800 shutoff |
3. 从快照恢复(virsh
snapshot-revert)
virsh # snapshot-list vm2 Name Creation Time State ------------------------------------------------------------ 1433458417 2015-06-05 06:53:37 +0800 shutoff virsh # snapshot-revert vm2 1433458417 |
4. 删除快照(virsh
snapshot-delete)
virsh # snapshot-list vm2 Name Creation Time State ------------------------------------------------------------ 1433458417 2015-06-05 06:53:37 +0800 shutoff virsh # virsh # snapshot-delete vm2 1433458417 Domain snapshot 1433458417 deleted virsh # snapshot-list vm2 Name Creation Time State ------------------------------------------------------------ |