当前位置: > 虚拟化 Virtualization > KVM >

linux下kvm如何创建快照

时间:2016-04-06 16:18来源:linux.it.net.cn 作者:IT
  1. 准备一个磁盘格式为qcow2的vm(raw格式的磁盘无法创建快照)
  2. 方法一:从头安装一个磁盘格式为qcow2的vm
1
2
3
4
5
6
7
8
9
[root@tanghuimin vm]# <a class="bdcs-inlinelink" href="http://so.21ops.com/cse/search?s=9181936462520079739&entry=1&q=qemu" target="_blank">qemu</a>-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'
[root@tanghuimin 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的磁盘格式

1
2
3
4
5
6
7
8
9
10
11
12
[root@tanghuimin vm]# qemu-img info vm1-clone
image: vm1-clone
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G
[root@tanghuimin vm]# qemu-img convert -f raw vm1-clone -O qcow2 vm1-clone.qcow2
[root@tanghuimin 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

1
2
3
4
5
6
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/vm/vm1-clone'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>

修改为

1
2
3
4
5
6
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/vm/vm1-clone.qcow2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>

2. 创建快照(virsh snapshot-create)

1
2
3
4
5
6
7
8
9
10
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 shutof

3. 从快照恢复(virsh snapshot-revert)

1
2
3
4
5
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)

1
2
3
4
5
6
7
8
9
10
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
------------------------------------------------------------



(责任编辑:IT)
------分隔线----------------------------