KVM disk performance: raw vs qcow2 & Steps to Convert raw to qcow2

Disk Format: Raw vs. Qcow2:

The libvirt(The virtualization API. libvirt is: A toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes))  snapshots can only be performed on certain type of disk formats. There are several types of VM disk formats, but the most  common are raw and qcow2 (copy-on-write).

    * qcow2 [ "QEMU Copy-On-Write" ]

    * qcow2 is an updated version of the qcow format, intended to supersede it. The main difference with the original is that qcow2 supports multiple virtual machine snapshots through a new, flexible model for storing snapshots.

*   Users can easily convert qcow disk images to the qcow2 format. QEMU and Xen have retained the qcow format for backwards compatibility.

How qcow2 works:





*   Raw disks are presented as-is to the VM without any disk layering and do not support snapshots, whereas qcow2 disks support a range of special features including snapshots, compression and encryption.

*   Raw disks have better I/O performance than qcow2 because the VM disk space is pre-allocated before the VM is created, as opposed to qcow2, where VM disk space is thinly provisioned and allocated on-the-go as the VM requires it.

*   If you create a VM with a raw disk of 10 GB, you?ll see that the disk image size for the VM will be exactly 10 GB, whereas for a VM with a qcow2 disk the actual file size will be a fraction of 10 GB (say 2-3 GB) and it will grow as you occupy disk space inside the VM.

Verify VM disk format:

# file /vm-images/vm1.img
/vm-images/vm1.img: Qemu Image, Format: Qcow, Version: 2

# qemu-img info /vm-images/vm1.img
image: /vm-images/vm1.img
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 3.2G
cluster_size: 65536

Converting disk format from raw to qcow2:

It is easy to convert from a raw VM image (which doesn?t support libvirt snapshots) to qcow2 format. In this example, we convert an image file of size 10 GB for a VM called vm2.

1. Shut down the VM:

# virsh shutdown vm2

2. Let's take a look at the image file format:

# cd /vm-images

# qemu-img info vm2.img
image: vm2.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 10G

3. The conversion process actually makes a qcow2 copy of the raw image and leaves the raw image intact.

The command is:

# qemu-img convert -f raw vm2.img -O qcow2 vm2.qcow2

* The new image file extension is irrelevant; we use “qcow2” to help us identify the different image format.

* The conversion process will take a few minutes, depending on the size of the image file.

4. Let's take a look at the new image file format:

# qemu-img info vm2.qcow2
image: vm2.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 3.2G
cluster_size: 65536

* Notice that the virtual size remains unchanged, it is still 10 GB.

* The disk size (as the OS sees it) will be less than 10 GB. In our case, it is 3.2 GB. If you run the „ls –l? command on the file, its reported size will match the “disk size” reported here. As you add files inside the VM disk, this file size will increase, up to a maximum of 10 GB.

Comments

Popular posts from this blog

Resolved: DOCKER: Error response from daemon: Could not attach to network / rpc error: code = 7 desc = network not manually attachable.

yum failed 6 times. Cannot continue!

How to echo colored text in linux shell script: