How to convert a raw .img KVM file to a .qcow2 file

Qcow2 is a better format for various reasons, see this link.

If you have a KVM host and some of the computers are in img format, you may want to consider changing this.

First use the virsh edit command to check if the format is definitely img. Look for these lines:

> virsh edit nsx.example.com

<devices>
  <emulator>/usr/libexec/qemu-kvm</emulator>
  <disk type='file' device='disk'>
    <driver name='qemu' type='raw'/>
    <source file='/var/lib/libvirt/images/nsx.example.com.img'/>
    <target dev='hda' bus='ide'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>
...

Next I like to shutdown the VM. Then the conversion command is this:

qemu-img convert -f raw -O qcow2 nsx.example.com.img nsx.example.com.qcow2

Once done, change type to qcow2 , change the actual source file name, and restart the VM.

Tags

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top