Monday, December 15, 2014

HOWTO Convert a KVM Disk from RAW to QCOW2

The qemu-img convert command can do conversion between multiple formats, including raw, qcow2, VDI (VirtualBox), VMDK (VMware) and VHD (Hyper-V).

Why qcow2? QEMU copy-on-write format have a range of special features, including the ability to take multiple snapshots, smaller images on filesystems that don't support sparse files, optional AES encryption, and optional zlib compression)

Image format Argument to qemu-img
raw            raw
qcow2          qcow2
VDI (VirtualBox)vdi
VMDK (VMware) vmdk
VHD (Hyper-V) vpc

The following command will convert a KVM image from RAW to qcow2:
qemu-img convert -f raw -O qcow2 /home/vservers/server1/server1.img /home/vservers/server1/server1.qcow2

After the conversion, we can check the image with the following command:
ximena@xdev:~$ qemu-img info server1.qcow2
image: server1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.5G
cluster_size: 65536