Nathan Stratton’s Homepage

Converting Citrix .xva to .img

by on Jun.06, 2009, under Software

Xen is one of the coolest virtualization technologies out there. It comes in may flavors, the two largest being the bleeding edge open source project and the commercial (Citrix) version. There are things I love about the commercial version, but they lost me only supporting windows in their XenCenter administration interface.

The file formats of the commercial and open source Xenare totall different. The open source is a standard image file, you can mount it, fdisk it, whatever you would like. The Citrix Xen Virtual Appliance .XVA file is quite different. It is actually a tar file with ova.xml meta data and directories starting with Ref full of 1M files that make up the drive volumes of the virtual image.

To convert .xva to an xen .img file you first untar the image:

tar -xvf {image}.xva

Then grab this handy utility and run it on your untared data, as an example:

python –convert=Ref:3 {image}.img

This will paste all of those files back together, starting at 00000000. Note I have had problems running this script on Centos 5.x.

Be Sociable, Share!

11 Comments for this entry

  • JBill

    How can one convert a img file to xva format ?

  • nathan

    Why would anyone want to do that! My guess is that if Citrix wanted to charge for Xen that they would provide some sort of utility for that.


  • dr

    Hi nathan,

    i get the following error while running the script

    when i run python –convert=Ref:3 myimage.img

    it cannot find the source directory and when i fire

    python -c xvda image.img
    i get the following error

    convert ref dir : xvda
    to raw file : image.img
    Traceback (most recent call last):
    File “”, line 478, in
    File “”, line 295, in reftoraw
    ValueError: invalid literal for int() with base 10: ‘chunk-000000002.gz’

    Please help…

  • admin

    Make sure you are root, and add the trailing / after Ref:3, I have tested on Fedora 10 and 11.


  • Mark Pace

    There is a newer version of the xenmigrate program that handles XenServer 5.5 xva files properly. You can get it (and any newer releases that may happen) from its source:


  • Steven

    After I run xenmigrate it says it completed successfully…

    xenmigrate 0.7.4 — 2011.09.13
    (c)2011 Jolokia Networks and Mark Pace —

    convert ref dir : /mnt/vm_images/xenserver02-vm-2011-09-09/Ref:78/
    to raw file : testconvert.img
    last file : 1
    disk image size : 0 GB

    RW notification every: 1.0GB
    Successful convert

    But the raw file it produces is only about 1M…. It should be around 20G. Has anyone every seen this behavior before?


  • zinkuz

    Hi admin,

    I get the same message like “dr” and / after Ref:3 didn, helped. It works with imeges less than 1G. When I took newer version of message disapeared but
    it stops after 1st chunk. Any suggestions?

  • Bret Miller

    I really needed a working version of this last week, so I created my own. This one works on Windows with .xva snapshots created by XenServer 5.6 SP2.

  • charles81

    Just taking a wild guess here but are the 1mb files to allow snapshots?

    I know that if you have thin-provisioned virtual disks then they pretty much do this by simply skipping any 1mb blocks/files that have no data in them. So you’ll have something like 000000, 000001, 000002, 000005, 000006 and presumably the 3-4 files are simply empty so not included. Doesn’t save as much space as simply using compression but likely takes some pressure off the CPU and slows down some of the write speed if it needs to create the file first.

    It wouldn’t surprise me that if you looked into snapshots that you’d pretty much find a heap of 1mb files that match up with the ones changed.

    *meh* I could be way off the mark as the virtual disk in XenServer is likely far different from the XVA format.

  • T

    Handy dandy script I cooked up to handle everything from snapshotting a live VM on xenserver to mounting the partitions as /dev/mapper/loopXpY It uses a newer version of from Jolokia Networks, edited by bret.miller (dl link to pastebin on the Jolokia page, patch in my note is 0.7.4->editedversion). This lets you quickly run against a Citrix VM, then do something like dd if=/dev/mapper/loopXpY bs=4096k | ssh some.other.xen ‘dd of=/dev/mapper/NewXenLVM’

    Sharing back since I got this far from this blog post. Kudos to Mark for the py!

  • zinkuz

    Hi, Bret Miller

    The script you’ve made works fine with Windows .xva files
    but when I convert Linux VM it does not boots. Any ideas.

Leave a Reply


Looking for something?

Use the form below to search the site:

Cool Links!

A few highly recommended links...