PowerKVM Qcow2 disk image use cases PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Ozan Uzun   

Qcow2 is the widely used disk image format in KVM world

PowerKVM 3.1/Kimchi has a lot of new features. What I most needed was qcow2* support. PowerVC was using qcow2 for deployment on 2.1 but Kimchi was only capable of using raw disks. Let’s start with definition of qcow.

 Qcow is a file format for disk image files used by QEMU, a hosted virtual machine monitor.[1] It stands for "QEMU Copy On Write" and uses a disk storage optimization strategy that delays allocation of storage until it is actually needed. Files in qcow format can contain a variety of disk images which are generally associated with specific guest operating systems. Two versions of the format exist: qcow, and qcow2, which use the .qcow and .qcow2 file extensions, respectively.

Qcow2 has a long list of features even including encryption. But I need to focus on daily used ones. Snapshots, thin provision, sparsify support is crucial on a live environment for today’s conditions.

After the initial installation I will check the images. First good news for me; it is thin provision by default.

I will be using virsh shell for KVM management, and qemu-img command on Linux shell

 

[root@p8kvm images]# pwd

/var/lib/libvirt/images

    

[root@p8kvm images]# file 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img

7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img: QEMU QCOW Image (v2), 85899345920 bytes

 

[root@p8kvm images]# qemu-img info 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img

image: 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img

file format: qcow2

virtual size: 80G (85899345920 bytes)

disk size: 4.8G

cluster_size: 65536

Format specific information:

 compat: 0.10

 refcount bits: 16          

Let’s check  caching mechanism of the default setup, which is none by default. Fine by me.

virsh # edit ubuntu_test_15

…..

<disk type='file' device='disk'>

<driver name='qemu' type='qcow2' cache='none'/>

<source file='/var/lib/libvirt/images/7f961655-c5a2-4ea6-aa62-788cf9b3e24d-0.img'/>  

……

Snapshots:

 

Testing, snapshot on a running guest, and see the results.

[root@p8kvm images]# virsh

virsh # snapshot-create-as zimbratest zimbratest_812016  

 

virsh # snapshot-list zimbratest

Name Creation Time State

------------------------------------------------------------

 zimbratest_812016 2016-01-08 12:53:45 +0200 running

 

[root@p8kvm images]# qemu-img info 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img

image: 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img

file format: qcow2

virtual size: 80G (85899345920 bytes)

disk size: 6.6G

cluster_size: 65536

Snapshot list:

ID TAG  VM SIZE DATE VM CLOCK  

1 zimbratest_812016 1.8G 2016-01-08 12:53:45 350:03:38.298

Format specific information:

 compat: 0.10

 refcount bits: 16

 cluster_size: 65536

 

The 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img file now includes the snapshot in it. It can be classified as an internal snapshot. The file size is 1.8 G bigger now, which includes the memory state of the Guest. Snapshots are very useful for an admin; personally I do not recommend live snapshots (while the OS is running) for critical workloads.

Clone example with snapshot:

Another nice use example of snapshot is cloning. I will create a snapshot of this OS’s disk in no time and use the cloned disk for a new, “clone” OS.

The command, I will be using is qemu-img again, the new file will be named as cloneubuntu.img

I will first clone the disk with qemu-img , second define the new clone-ubuntu image.

The machine definition is already there, I will just export and change the name and disk name of the xml file. May sound confusing, but it is only 15 second process. There are many other ways to do it, but I want to show this one.

First  disk cloning 

qemu-img create -b 7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img -f qcow2 cloneubuntu.img  

Formatting 'cloneubuntu.img', fmt=qcow2 size=85899345920 backing_file='7b0deeaf-f9b9-44fc-9839-ae82598fa7da-0.img' encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16

 

 

Export the definition ( PowerVM=profile)

 

[root@p8kvm images]# virsh dumpxml ubuntu_test_15 > ubuntuclone.xml

 

[root@p8kvm images] vi ubuntuclone.xml

 

 

Edit the name, uuid and disk lines.

To create a uuid please use uuidgen command

[root@p8kvm images]# uuidgen

1f6dd783-5ee1-4f77-ab62-612791a3154d         

 

Now edit ubuntuclone.xml

 <name>ubuntu_test_clone</name> 

..

 <uuid> 1f6dd783-5ee1-4f77-ab62-612791a3154d</uuid>

..

 <source file='/var/lib/libvirt/images/cloneubuntu.img'/>

 

 

Define the Guest and run it

[root@p8kvm images]# virsh define ubuntuclone.xml

Domain ubuntu_test_clone defined from ubuntuclone.xml

 

[root@p8kvm images]# virsh start ubuntu_test_clone

Domain ubuntu_test_clone started

With a small script, you can clone tons of virtual servers in no time.
 
< Prev   Next >