How to convert VM disk from qcow2 to raw format
This article provides a 5 step process to convert an existing virtual machine disks format from qcow2 to raw format.
NOTE: This article assumes to have existing Virtual Machines (VMs) in order to following these steps!
- Backup current virtual machine config
virsh dumpxml vm-name > vm-name.xml
replace vm-name with your virtual machine name. In this example, we will use the virtual machine 'alpha':root@vmsvr# virsh dumpxml alpha > ~/alpha.xml
If you are unsure or just want to double check the virtual machine name, you can find this information by running the following command:virsh list --all
for example:root@vmsvr# virsh list --all Id Name State ------------------------------ 1 alpha running 2 bravo running 4 charlie running 5 echo running 12 foxtrot paused - golf shut off - vmtest shut off
- Find the path of the exisiting disk image
virsh dumpxml vm-name | grep file
in our example:root@vmsvr# virsh dumpxml alpha | grep file <disk type='file' device='disk'> <source file='/var/lib/libvert/images/alpha/tmplEzSU838.qcow2'/>
from the about output, we can confirm that our disk image is named '/var/lib/libvert/images/alpha/tmplEzSU838.qcow2'
- Convert the disk image
qemu-img convert <image-name>.qcow2 <image-name>.raw
in our example:root@vmsvr# qemu-img convert /var/lib/libvert/images/alpha/tmplEzSU838.qcow2 \ /var/lib/libvert/images/alpha/tmplEzSU838.raw - Edit the VM config
virsh edit <vm-name>
then find the driver and source lines:<disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvert/images/alpha/tmplEzSU838.qcow2'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0001' bus='0x00' slot='0x04' function='0x0'/> </disk>replace qcow2 with raw in the highlighted places. The changes should look something like:<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvert/images/alpha/tmplEzSU838.raw'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0001' bus='0x00' slot='0x04' function='0x0'/> </disk>save changes and exit the editor. - Start the VM
virsh start vm-name
in our example:root@vmsvr# virsh start alpha