*** Snapshots and Storage Information *** So, I converted an existing 13G RAW disk image to qcow2. #root@~ $qemu-img -f raw convert -O qcow2 /var/lib/libvirt/images/cs81test.img /var/lib/libvirt/images/cs81test.qcow2 #File system notes root@~ $du -sh /var/lib/libvirt/images/lovelock1.dsk 2.4G/var/lib/libvirt/images/lovelock1.dsk #Note: Preallocation is faster(when using qemu-img) ##Ex for creating: qemu-img create -f qcow2 -o preallocation=metadata /var/lib/libvirt/images/fedora15.qcow2 8G ##Ex for conversion: qemu-img convert -c -f raw -O qcow2 -o preallocation=metadata /var/lib/libvirt/images/honeycomb.dsk /var/lib/libvirt/images/honeycombq.qcow2 ################## root@~ $qemu-img convert -c -f raw -O qcow2 /var/lib/libvirt/images/lovelock1.dsk /var/lib/libvirt/images/lovelock1q.qcow2 root@~ $du -sh /var/lib/libvirt/images/lovelock1q.qcow2 785M/var/lib/libvirt/images/lovelock1q.qcow2 root@~ $ ################## == References/Notes == - sparse-files: http://intgat.tigress.co.uk/rmy/uml/sparsify.html - performance: http://www.ilsistemista.net/index.php/virtualization/11-kvm-io-slowness-on-rhel-6.html?start=4 - http://wiki.qemu.org/Features/Snapshots2 - http://wiki.qemu.org/QMP #'write-through cache' (research more on this) + Every write to the cache causes a synchronous write to the backing store. + For RAW Images -- write-through cache should *always* be disabled. (cache=none) ; (preallocation doesn't have influence) EX to disbale cache: + For QCOW2 Images -- And enable 'metadata preallocation' NOTES: ####################### Examples of creating images with, without preallocation ####################### [root@sunrise temp]# qemu-img create -f qcow2 -o preallocation=metadata fedora15tbx.qcow2 8G Formatting 'fedora15tbx.qcow2', fmt=qcow2 size=8589934592 encryption=off cluster_size=0 preallocation='metadata' ################## [root@sunrise temp]# du -sh fedora15tbx.qcow2 1.4M fedora15tbx.qcow2 [root@sunrise temp]# ################## [root@sunrise temp]# qemu-img create -f qcow2 fedora15-without-preall.qcow2 8G Formatting 'fedora15-without-preall.qcow2', fmt=qcow2 size=8589934592 encryption=off cluster_size=0 ################## [root@sunrise temp]# du -sh fedora15-without-preall.qcow2 136K fedora15-without-preall.qcow2 [root@sunrise temp]# ################## [root@sunrise temp]# ls -lash fedora15tbx.qcow2 fedora15-without-preall.qcow2 1.4M -rw-r--r--. 1 root root 8.1G Aug 11 15:36 fedora15tbx.qcow2 136K -rw-r--r--. 1 root root 193K Aug 11 15:36 fedora15-without-preall.qcow2 [root@sunrise temp]# ################## [root@sunrise temp]# qemu-img create -f qcow2 -o size=10000000000,preallocation=metadata testfile.qcow2 8G Formatting 'testfile.qcow2', fmt=qcow2 size=10000000000 encryption=off cluster_size=0 preallocation='metadata' ################## [root@sunrise temp]# ls -lash testfile.qcow2 1.6M -rw-r--r--. 1 root root 9.4G Aug 11 15:40 testfile.qcow2 [root@sunrise temp]# ################## ############### Converting an existing disk image to Qcow2 with preallocation ; modifying your virtual machine XML file######################## => 1/ convert your RAW image to qcow2 root@images $ls -lash /var/lib/libvirt/images/honeycomb.dsk 1.1G -rw-r--r--. 1 root root 11G Aug 11 14:56 /var/lib/libvirt/images/honeycomb.dsk ############### ## This is INCORRCET root@images $qemu-img convert -c -f raw -O qcow2 -o preallocation=metadata /var/lib/libvirt/images/honeycomb.dsk /var/lib/libvirt/images/honeycombq.qcow2 ############### root@images $ls -lash /var/lib/libvirt/images/honeycombq.qcow2 335M -rw-r--r--. 1 root root 11G Aug 11 15:56 /var/lib/libvirt/images/honeycombq.qcow2 root@images $ ############### => 2/ Edit the xml file -- /etc/libvirt/qemu/honeycomb.xml and ensure change the 'disk' parameters -- 'type' , and correct 'source file' . . .
############### => 3/ (Re-)Define the xml file root@images $virsh define /etc/libvirt/qemu/honeycomb.xml Domain honeycomb defined from /etc/libvirt/qemu/honeycomb.xml root@images $ ############################################################################ ## IMPORTANT NOTE:'compression' and 'preallocation' *cannot* be used at the same time. ## The really slow part of qcow2 is allocating clusters, and you don't have to do that any more with preallocation. ## qcow2 with preallocation is about the best thing you can do to extract best performance out of qcow2. ## preallocation=full -- Ref: http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg03017.html =>1/ Convert convert your RAW image to qcow2 (with preallocation) ############## root@oz-test $qemu-img convert -f raw -O qcow2 -o preallocation=metadata /var/lib/libvirt/images/cs81test.img /var/lib/libvirt/images/cs81test.qcow2 root@oz-test $ ############## root@oz-test $ls -lash /var/lib/libvirt/images/cs81test.img 13G -rw-------. 1 root root 12G Jul 22 15:53 /var/lib/libvirt/images/cs81test.img root@oz-test $ ############## root@oz-test $ls -lash /var/lib/libvirt/images/cs81test.qcow2 1.6G -rw-r--r--. 1 root root 13G Aug 11 16:59 /var/lib/libvirt/images/cs81test.qcow2 root@oz-test $ =>2/ change your libvirt xml ############## . .
############## =>3/ (Re-)Define the xml file ############## root@~ $virsh define /etc/libvirt/qemu/cs81test.xml Domain cs81test defined from /etc/libvirt/qemu/cs81test.xml ############## =>4/ Snapshots work(with libvirt) ############## root@~ $virsh snapshot-current cs81test ############## CREATE A SNAPSHOT TEMPLATE ############## root@~ $cat /etc/libvirt/qemu/snapshot-cs81test.xml cs81-inst-aug11 up2date cs81 packages installed. As of Aug-11 root@~ $ ############## CREATE SNAPSHOT ############## root@~ $virsh snapshot-create cs81test /etc/libvirt/qemu/snapshot-cs81test.xml Domain snapshot cs81-inst-aug11 created from '/etc/libvirt/qemu/snapshot-cs81test.xml' root@~ $ ############## LIST THE SNAPSHOT ############## root@~ $virsh snapshot-list cs81test Name Creation Time State --------------------------------------------------- cs81-inst-aug11 2011-08-11 18:43:24 +0530 shutoff root@~ $ ############## =>5/ After the above, weirdly, it fails root@~ $virsh snapshot-create cs81test Domain snapshot 1313069252 created root@~ $virsh snapshot-list cs81test Name Creation Time State --------------------------------------------------- 1313069252 2011-08-11 18:57:32 +0530 shutoff cs81-inst-aug11 2011-08-11 18:43:24 +0530 shutoff root@~ $ ############## root@~ $virsh snapshot-delete cs81test 1313069252 root@~ $virsh snapshot-list cs81test Name Creation Time State --------------------------------------------------- cs81-inst-aug11 2011-08-11 18:43:24 +0530 shutoff root@~ $ ############## =CREATING A SECOND SNAPSHOT WITH A NAME= ############## root@~ $cat /var/tmp/snap2-cs81test.xml 2nd snapshot with a bit of text root@~ $ ############## root@~ $virsh snapshot-create cs81test /var/tmp/snap2-cs81test.xml Domain snapshot 2nd snapshot created from '/var/tmp/snap2-cs81test.xml' ############## root@~ $virsh snapshot-list cs81test Name Creation Time State --------------------------------------------------- 2nd snapshot 2011-08-11 19:10:07 +0530 shutoff cs81-inst-aug11 2011-08-11 18:43:24 +0530 shutoff ##############