Last Updated: February 25, 2016
·
13.89K
· pbruna

Export oVirt VM to qcow2 image file

We just made the change from oVirt to Proxmox, the reason is the topic for another post, but here i'm going to tell you how to export the VMs disc to a qcow2 file. The source VM disc is a LVM image

Prepare the VM

First you need to complete 2 task.

1. Delete network card association
This way you get the same interface you currently have. All you need to do is to empty the file /etc/udev/rules.d/70-persistent-net.rules.

2. Fill your disk with zeros
This tip is from Richard WM Jones (http://rwmj.wordpress.com/2010/10/19/tip-making-a-disk-image-sparse/) and the result is a thin provision qcow2 image. For every filesystem in your vm you need to run:

dd if=/dev/zero of=zerofile bs=1M
rm -rf zerofile

Ready to convert

1. Discover your VM LV association
Each disk of your vm is associated with a LVM volumen, so the first thing to do is to know which LV you need to export.

With the VM still running, connect to the Hypervisor where is running and run the following command:

virsh --readonly -c qemu:///system domblklist pbrunalab
**vda** /rhev/data-center/70ca7a78-b570-11e1-bcfe-2e18820c3a67/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/images/7e4c3ed3-73e6-44d8-8d21-efbb7818af86/e0c77de3-7589-43bc-bfdd-db11e11dab93

Looking at the result you know that the vda disk is linked to some kind of device. Now you need to get the device:

ls -l /rhev/data-center/70ca7a78-b570-11e1-bcfe-2e18820c3a67/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/images/7e4c3ed3-73e6-44d8-8d21-efbb7818af86/e0c77de3-7589-43bc-bfdd-db11e11dab93

lrwxrwxrwx. 1 vdsm kvm 78 Feb 25 23:11 /rhev/data-center/70ca7a78-b570-11e1-bcfe-2e18820c3a67/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/images/7e4c3ed3-73e6-44d8-8d21-efbb7818af86/e0c77de3-7589-43bc-bfdd-db11e11dab93 -> /dev/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/e0c77de3-7589-43bc-bfdd-db11e11dab93

I you look carefully you already know that the Logical Volume is /dev/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/e0c77de3-7589-43bc-bfdd-db11e11dab93. No you can poweroff your VM.

2. Exporting to a qcow2 file
Now with vm not running and knowing the LV is time to export. This steps assume that in /mnt/export you had mounted a external device or a NFS share.

#Activate the LV
lvchange -ay /dev/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/e0c77de3-7589-43bc-bfdd-db11e11dab93

# Export to qcow2
qemu-img convert -p -O qcow2 /dev/e1537ba0-7d0f-4e4a-88b8-7f5698b2ceae/e0c77de3-7589-43bc-bfdd-db11e11dab93 /mnt/export/vm_disk-vda.qcow2

That's all.

3 Responses
Add your response

Thank you sir; I am going to try this asap. Going from oVirt to openstack...

over 1 year ago ·

Thank you so much! RHEV has finally caused me one too many problems and I'm bailing out. I'm taking my VMs and I'm leaving. Thanks to your post, that is.

over 1 year ago ·

hi

what is the post link for reason ovirts to proxmox ?

thanks

over 1 year ago ·