常用KVM硬盤格式:1.raw 2.qcow2
raw
用一個字來說就是裸,也就是赤裸裸,你隨便dd一個file就模擬了一個raw格式的鏡像。由於裸的徹底,性能上來說的話還是不錯的。目前來看,KVM和XEN默認的格式好像還是這個格式。因爲其原始,有很多原生的特性,例如直接掛載也是一件簡單的事情。由於原生的裸格式,不支持snapshot。
qcow2
支持多個snapshot,對歷史snapshot進行管理
支持zlib的磁盤壓縮
支持AES的加密
查看硬盤格式:
[root@localhost 桌面]# qemu-img info /VMs/p_w_picpaths/centos6.img p_w_picpath: /VMs/p_w_picpaths/centos6.img file format: raw virtual size: 20G (21474836480 bytes) disk size: 937M
將raw裝換爲qcow2(需關閉虛擬機):
[root@localhost p_w_picpaths]# qemu-img convert -f raw -O qcow2 centos6.img centos6.qcow2 [root@localhost p_w_picpaths]# qemu-img info centos6.qcow2 p_w_picpath: centos6.qcow2 file format: qcow2 virtual size: 20G (21474836480 bytes) disk size: 760M cluster_size: 65536
修改配置文件:
[root@localhost p_w_picpaths]# virsh edit centos6 <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/VMs/p_w_picpaths/centos6.qcow2'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </disk> 將raw替換爲 qcow2
啓動虛擬機,大功告成。
創建、查看快照:
[root@localhost p_w_picpaths]# virsh snapshot-create centos6 Domain snapshot 1393765282 created [root@localhost p_w_picpaths]# virsh snapshot-list centos6 名稱 Creation Time 狀態 ------------------------------------------------------------ 1393765282 2014-03-02 21:01:22 +0800 running [root@localhost p_w_picpaths]# qemu-img info centos6.qcow2 p_w_picpath: 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 p_w_picpaths]# virsh snapshot-list centos6 名稱 Creation Time 狀態 ------------------------------------------------------------ 1393765282 2014-03-02 21:01:22 +0800 running [root@localhost p_w_picpaths]# virsh snapshot-revert centos6 1393765282
快照配置文件:
[root@localhost p_w_picpaths]# 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