Import hyper-v images into Cloudstack and Xenserver

Yesterday I had quite a trouble when trying to upload a datavolume in Cloudstack. Actually it was a fixed size VHD image, that I created with hyper-v.
Even I selected “VHD” format when uploading, the uploaded image was corrupted so much, that it took some hours to figure out how to remove it.
It seems that either Cloudstack or Xenserver had some problems dealing with the hyper-v VHD. (I suspect it is a Xenserver issue)

Since I still needed that data volume, I had to find a way to import it.
The previus day I succesfully imported a hyper-v VHD containing a Windows server image. But that time I first uploaded the VHD to a different Xenserver with Xencenter’s import function, then I used that VHD image to upload it to Cloudstack. Maybe Xencenter did that conversion, that the direct upload missed.
But Xencenter can only be used with bootable operating system images, because it tries to create a VM from the imported VHD.
If the image does not contain a bootable operating system (e.g. it’s just a datadisk), then the import a bit more complex:

The Xenserver used for the conversion should have at least one NFS storage repository. This is important.NFS storage repositories store VDI-s in VHD files. LVM based storage repositories use Linux lvm volumes for this purpose, and it is quite difficult to produce uploadable vhd files from lvm volumes.

1. put the VHD on an nfs share, that you can reach from Xenserver.
2. SSH into Xenserver, and nfs mount the share. I think SMB share could work too, but I did not try.
3. Create a new vdi on the NFS SR. You can either use Xencenter or the cli. The vdi must be a little larger than the VHD you want to import.
4. Find the uuid of the new vhd with the name you used above: xe vdi-list name-label=Restore
5. xe vdi-import uuid=a6e97eeb-ecc5-4535-a665-43b15024c338 filename=/nfs/data.vhd format=vhd –progress
6. Copy the vhd from the SR to your webserver, so you can use the upload function in cloudstack. The vdi can be found in the nfs storage repository: /var/run/sr-mount/(SR uuid)/(vdi uuid).vhd

Conclusion: Hyper-v VHDs can not be imported directly with Cloudstack upload template and upload volume functions. They must be converted to a VHD that Xenserver can recognize. I tought VHD is VHD regardless the virtualization platform, but maybe I was wrong.

Tested on: Cloudstack 4.4.0 with Xenserver 6.2 hosts.
The Xenserver used for the conversion was 6.0.2

Update: Resizing of the uploaded volume fails with unexpected error…
I just deleted the volume and created a new empty datadisk, then used vdi-import. After vdi-import everything works.

Leave a comment