VMware: Exporting from Oracle VirtualBox/Vagrant to vCloud Director

vmware_logo2Oracle VirtualBox as a virtualization engine paired with Vagrant provides a cross-platform virtualization-agnostic workflow for Linux, Windows, and MacOS.  It is light enough to allow a developer to setup, test, and tear down virtual infrastructure as part of a unit test.

You may find yourself in a position where you have built a VM in VirtualBox that you need to test in a lab running VMware vCloud Director.  This may beg the question of, “Why not simply using the same script or process to rebuild the VM in the VMware lab?”

Perhaps the Vagrant box available in your VMware lab is not yet the latest version or OS flavor, maybe someone in the community constructed a Vagrant box for a software stack you have not yet scripted, or maybe internet access in the lab is limited to certain package repositories and you needed to reference a custom archive.  Whatever the reason, you can export your VM from VirtualBox and import it into VMware if you are willing to jump through a few hoops.

Export from VirtualBox

The first step is to power down the VM from VirtualBox.  If you are in the VirtualBox GUI, you can select Machine > Close.  If you are at the command line using vagrant, you can use:

vagrant halt

Once the host  is powered off, you then want to export it as an appliance.  It does not matter if your VirtualBox disk format is vdi, vmdk, or vhd; when it is exported it becomes a large, compressed .ova file.

virtualbox-export-appliance

Now select File > Export Appliance and a dialog will popup.  Select a format of “OVF 0.9”, and leave the “Write Manifest file” unchecked because you do not need it.   Press “Export”.  It will take a few minutes depending on the size of the virtual machine, but you will end up with a large .ova file.

Convert the OVA file to OVF

Now, you need to use a tool to convert the large .ova file into an .ovf descriptor file and its related .vmdk disk.  VMware has a utility for download called the ovftool, and it is available for Windows, Linux, and macOS.  You will need an account to grab the binary, but it does not require a commercial support contract.

The utility takes two arguments, source and destination.  As an example of it’s usage, if the exported ova from VirtualBox was at c:\temp\myhost.ova and you wanted to covert that to the VMware compatible ovf format, then your command would look like:

ovftool c:\temp\myhost.ova c:\temp\myhost.ovf

This will create two separate files in c:\temp, myhost.ova (xml description file) and myhost.vmdk (virtual disk).

Take note that although the ovftool does allow you to import an ova into vSphere/vCloud Director, because of incompatibilities talked about in the next section, it will be more stable to manipulate the ovf xml definition file before importing.

Make the OVF compatible with VMware

At this point, it would be nice if we could simply import the ovf file into vCloud Director or vSphere.  But unfortunately, there are some incompatibilities in system types, hardware support, and XML schema that we need to address manually.  Since the ovf is just an XML file, it is easy to change.

There is a ‘–lax’ switch in the ovftool that does its best to map unsupported hardware, but I think it is a good idea to make as many fixes as possible manually and then rely on the lax switch as a last resort.

ovf:format

Make sure that the ovf:format value is set as below:

ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"
VirtualSystemType

This is going to be set to something like “virtualbox-2.2”, which is not compatible with VMware.

Set the VirtualSystemType to vmx-07 for ESX 4.x, vmx-04 for ESX 3.5/4.0, vmx-09 for ESX 5.  To be on the safe side, set it to “vmx-07“, but you should set this to the highest level supported by your VMware virtualization engine.

<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
SOUND CARD OPTIONAL

If you have a section that looks similar to the one below, which is a sound card resource, make sure to add @required=false similar to below.

<Item ovf:required="false">

<rasd:Caption>sound</rasd:Caption>

<rasd:Description>Sound Card</rasd:Description>

SATA CONTROLLER TYPE

If you have SATA disk controllers in VirtualBox (ResourceType=20), these are not going to import into VMware.  Change these to SCSI LSI Logic with resource type 6 for VMware as detailed in this article.

What starts as this:

<Item>
<rasd:Address>0</rasd:Address>
<rasd:Caption>sataController0</rasd:Caption>
<rasd:Description>SATA Controller</rasd:Description>
<rasd:ElementName>sataController0</rasd:ElementName>
<rasd:InstanceID>5</rasd:InstanceID>
<rasd:ResourceSubType>AHCI</rasd:ResourceSubType>
<rasd:ResourceType>20</rasd:ResourceType>
</Item>

You should map to:

<Item>
<rasd:Address>0</rasd:Address>
<rasd:Caption>SCSIController</rasd:Caption>
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:ElementName>SCSIController</rasd:ElementName>
<rasd:InstanceID>5</rasd:InstanceID>
<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
</Item>
RAM Units

VirtualBox’s schema allows it to put ‘MegaBytes’ into the AllocationUnits where RAM is specified, and VMware does not allow this.

Where you see:

<Item>
 <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
 <rasd:Caption>1024 MB of memory</rasd:Caption>
 <rasd:Description>Memory Size</rasd:Description>
 <rasd:ElementName>1024 MB of memory</rasd:ElementName>
 <rasd:InstanceID>2</rasd:InstanceID>
 <rasd:ResourceType>4</rasd:ResourceType>
 <rasd:VirtualQuantity>1024</rasd:VirtualQuantity>
</Item>

Replace ‘MegaBytes’ with ‘byte*2^20’, like:

<Item>
 <rasd:AllocationUnits>byte*2^20</rasd:AllocationUnits>
...

Import the OVF into vCloud Director

Now, with the modifications made to our ovf, we can attempt an import into vCloud Director.  This can be done through the vCloud web interface of course, but is increasingly harder to find a modern browser where this functionality is stable.

This is where the ovftool we already installed can come to the rescue.  In addition to being able to take a local destination, it can also take a remote destination to either vSphere or vCloud Director.

For example, to upload into a vCloud Director org named ‘myorg’ that has a catalog named ‘mycatalog’, I could use a command that looks like this (all one line):

ovftool c:\temp\myhost.ovf "vcloud://myuser:mypassword@vcloud-server.mydomain.com?org=myorg&catalog=mycatalog&vappTemplate=myhost"

Once in the catalog, you can add a VM into the vApp you want.

Here are the parameters available:

vcloud://username:password@host:port?org=name_of_org&vapp=name_of_deployed_vapp&catalog=name_of_catalog&vappTemplate=name_of_vapp_template_in_catalog&vdc=name_of_vdc

Import the OVF into vSphere

With the changes we made to the ovf, you should also be able to import the ovf using the vSphere Web Client.  See the article here and here for walk throughs of doing an ovf import using the web client.

Here are the full parameter specifications if you want to use the ovftool for uploading to vSphere.

Post Configuration

After the VM is provisioned, you will need to install VMware tools into the guest OS.  If the DVD/CD hardware was lost in the OVF import, then add a DVD/CD IDE drive from the vSphere GUI (even if your main interface is vCloud Director).

Then from Linux, you can have the VMware Tools CD mounted by selecting “Install VMware Tools” (vCloud Director) or “Install/Upgrade VMware Tools” (vSphere).  Then you need to mount, untar, and run the installer as described in this official KB article.

Once VMware tools is installed, you can power off the machine, and now you will have the ability to recustomize the guest OS and networking.

 

REFERENCES

https://www.virtualbox.org/manual/ch01.html#ovf

https://www.vagrantup.com/docs/boxes/versioning.html

https://en.wikipedia.org/wiki/Megabyte

https://www.vmware.com/support/developer/ovf/

https://my.vmware.com/group/vmware/details?downloadGroup=OVFTOOL420&productId=491

https://my.vmware.com/web/vmware/details?downloadGroup=OVFTOOL400&productId=353

https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2134237

http://www.techrepublic.com/blog/windows-and-office/how-do-i-convert-virtualbox-files-to-work-with-vmware-workstation/

http://geekafterfive.com/2012/08/08/uploading-vms-to-vcloud-with-ovftool/

http://www.top-password.com/blog/vmware-change-scsi-controller-type-from-buslogic-to-lsi-logic/

http://www.unixarena.com/2014/03/vmware-ovf-tool-convert-ova-ovf.html

 

http://www.howtogeek.com/125640/how-to-convert-virtual-machines-between-virtualbox-and-vmware/

 

http://www.itsecurenet.com/virtualbox-ova-to-vsphere-ovf/