常用KVM硬盘格式:1.raw 2.qcow2
raw
用一个字来说就是裸,也就是赤裸裸,你随便dd一个file就模拟了一个raw格式的镜像。由于裸的彻底,性能上来说的话还是不错的。目前来看,KVM和XEN默认的格式好像还是这个格式。因为其原始,有很多原生的特性,例如直接挂载也是一件简单的事情。由于原生的裸格式,不支持snapshot。
qcow2
支持多个snapshot,对历史snapshot进行管理
支持zlib的磁盘压缩
支持AES的加密
查看硬盘格式:
[root@localhost 桌面]# qemu-img info /VMs/images/centos6.img image: /VMs/images/centos6.img file format: raw virtual size: 20G (21474836480 bytes) disk size: 937M
将raw装换为qcow2(需关闭虚拟机):
[root@localhost images]# qemu-img convert -f raw -O qcow2 centos6.img centos6.qcow2 [root@localhost images]# qemu-img info centos6.qcow2 image: centos6.qcow2 file format: qcow2 virtual size: 20G (21474836480 bytes) disk size: 760M cluster_size: 65536
修改配置文件:
[root@localhost images]# virsh edit centos6 <disk type=‘file‘ device=‘disk‘> <driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/> <source file=‘/VMs/images/centos6.qcow2‘/> <target dev=‘vda‘ bus=‘virtio‘/> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x04‘ function=‘0x0‘/> </disk> 将raw替换为 qcow2
启动虚拟机,大功告成。
创建、查看快照:
[root@localhost images]# virsh snapshot-create centos6 Domain snapshot 1393765282 created [root@localhost images]# virsh snapshot-list centos6 名称 Creation Time 状态 ------------------------------------------------------------ 1393765282 2014-03-02 21:01:22 +0800 running [root@localhost images]# qemu-img info centos6.qcow2 image: centos6.qcow2 file format: qcow2 virtual size: 20G (21474836480 bytes) disk size: 915M cluster_size: 65536 Snapshot list: ID TAG VM SIZE DATE VM CLOCK 1 1393765282 155M 2014-03-02 21:01:22 00:04:17.241
恢复快照(虚拟机处于关闭状态):
[root@localhost images]# virsh snapshot-list centos6 名称 Creation Time 状态 ------------------------------------------------------------ 1393765282 2014-03-02 21:01:22 +0800 running [root@localhost images]# virsh snapshot-revert centos6 1393765282
快照配置文件:
[root@localhost images]# ll -h /var/lib/libvirt/qemu/snapshot/centos6/1393765282.xml -rw------- 1 root root 2.4K 3月 2 21:10 /var/lib/libvirt/qemu/snapshot/centos6/1393765282.xml
原文:http://wang390750.blog.51cto.com/8599831/1365975