How to import qcow2 images to ovirt

Today I was tasked with importing multiple VMs for which I received qcow2 images and libvirt XML files to ovirt.

Oh the joy!

Ovirt doesn’t offer a lot of good possibilities to import VM images in the UI, (I haven’t played around with glance yet) but fortunately there are working tools outside to make the job easier for you.

There are multiple strategies for VM image import, one of which includes creating a dummy virtual machine and disk in ovirt and replacing the disk image manually through NFS. Unfortunately that involves a lot of hacking around, consumes a lot of time, and isn’t really working well if you have a deployment that has storage based on iSCSI like I do.

Fortunately there is a better way, that involves creating an export domain for your data center and using CLI scripts to convert and deploy your VM images to said export domain, after which they can be easily imported via the ovirt engine UI.

A brilliant CLI script that just works is import-to-ovirt.pl and has been developed by Richard W.M. Jones and is available through his website with a short description on how to use it:
https://rwmj.wordpress.com/2015/09/18/importing-kvm-guests-to-ovirt-or-rhev/
http://git.annexia.org/?p=import-to-ovirt.git

I felt compelled to write a couple of lines of all the steps I did to succesfully import a VM image though, because I haven’t seen a step-by-step tutorial for this so far.

 

Step 1: Create an export domain – that involves creating a NFS storage somewhere accessible by your data center hosts and afterwards creating an export domain on it via the UI.

Click Storage -> New Domain -> Select Export on the Domain function combobox -> Set Export Path to the NFS share URL -> provide a name for the export domain -> and hit OK.

Step 2: Put your qcow2 images on a host that is able to access the export domain you just created and download the import-to-ovirt.pl script. In order to run the script you will need to install perl and some dependencies: perl-XML-Writer and perl-Sys-Guestfs. In my case, “yum install perl-XML-Writer perl-Sys-Guestfs” did the trick.

Step 3: Type this in your CLI and hit enter: “export LIBGUESTFS_BACKEND=direct” it apparently tells the script or some component used by the script to not go through libvirt in order to perform the image conversion, but to do it directly instead (I didnt completely understand that part, so please correct me if I’m wrong). If you omit this part, the conversion will not work! I tried it without the line above, but it would always prompt me for libvirt credentials, and even after entering them correctly, would provide weird error messages and ultimately failed.

Step 4: Convert the VM image and write it to the export domain with “./import-to-ovirt.pl vmImage.qcow2 ovirt-nfs.ovirt.lab:/export” The manpage of import-to-ovirt.pl says that its able to import .img files from KVM, but it also supports .qcow2 which is great since I usually get images in qcow2 format. After entering this, the script should get going and show something like this in the end:

Importing Ubuntu 14.04.3 LTS to ovirt-nfs.ovirt.lab:/export...
Copying vmImage.qcow2 ...
(100.00/100%)
Creating OVF metadata ...

OVF written to /tmp/2Y_3TpKZ4P/d10982a7-6647-42aa-b6c8-0a3d4ac20c69/master/vms/2670470f-e28b-4caf-8a73-7be9900ebf3e/2670470f-e28b-4caf-8a73-7be9900ebf3e.ovf

Import finished without errors. Now go to the Storage tab ->
Export Storage Domain -> VM Import, and import the guest.

Step 5: Importing the VM is done via the UI and very easy. Navigate to Storage -> click on your export domain -> Click on the VM Import tab -> Select the VM you just imported and hit import. Now you just have to customize the VMs according to your needs and set up the network interfaces and you’re ready to go!

 

Thanks a lot to Richard W.M. Jones, who really saved a lot of my time with that script.

6 thoughts on “How to import qcow2 images to ovirt

  1. This does not seem to be working anymore with latest ovirt 4.2.6 it seems to think everything is fine but not able to import anything after this.

    [root@ovirt Vmimages]# ./import-to-ovirt.pl media-vsrx-vmdisk-15.1X49-D150.2.qcow2 sprouts1-data:/export
    Importing Wind River Linux 6.0.0.15 to sprouts1-data:/export…
    Copying media-vsrx-vmdisk-15.1X49-D150.2.qcow2 …
    Creating OVF metadata …

    OVF written to /tmp/2f3gRT_zqp/45713416-58d4-47cd-bf00-8fbff6d936ec/master/vms/c0999b30-268b-4cbe-b56a-79d1318eeed4/c0999b30-268b-4cbe-b56a-79d1318eeed4.ovf

    Import finished without errors. Now go to the Storage tab ->
    Export Storage Domain -> VM Import, and import the guest.

Leave a Reply

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