The fun in importing VMs into vCenter

Recently I had a task of recovering VMs to one of my clusters at work off of USB hard drives to datastores that didn’t exist with respect to the original vmx file.  Having new datastores names actually posed an issue after you add the VM into the inventory and try and online the image, but this is one of many issues you will come against when trying to re-import VM images from external source.

One of the most obvious things when onlining data is you have to modify the Virtual NIC for the host, as the NIC that the VM was attached to probably wasnt named the same, so that issue had to be corrected first.   This was the easy fix.  I then noticed that some of the images had virtual harddrives that spanned various datastores on its prior source. No problem, I will just delete the disk and reattach them in their new datastore locations.  WRONG!  The minute I try to delete the incorrectly referenced vHarddrive, up comes an error: “Invalid configuration for device ’0′ error”.    Well that is certainly a problem.   The issue is because it cannot reference the datastore that no longer exists, it wont delete the vHarddrive that you want to remove because it belongs to an incorrectly referenced datastore.  Wow, talk about a Chicken and the Egg scenario.  So how are you supposed to modify the virtual harddrive for the iamage?

After a bit of playing around I determined I needed to remove the VM from the inventory and modify the .vmx file so the extra harddrives can be safely removed and re added later.  The steps I performed were fairly simple and straight forward:

  • Remove the VM from the inventory
  • Navigate to the datastore of the .vmx file and download it to your desktop.  Using vi, notepad or whatever text editor you prefer open the downloaded .vmx file.
  • While in the .vmx look for the extra drives usually designated by a datastore ID number followed by the diskname and note the SCSI ID order:
    • scsi0:1.present = “true”
    • scsi0:1.fileName = “1042034-3410432\vmname.vmdk”
  • Change the present to FALSE.   This will remove references of the secondary drives on unknown datastores. Repeat this on every disk that has ID numbers for pathnames.
  • Once changed save the file and upload it back to the datastore directory and import it back into the inventory.
  • Edit the VM now using the vCenter console and add the secondary disks in the order of the ID you noted.

You can now power up the VM and the disks will attach properly in the OS.  Depending on the version (2003) you may have to go to computer management and add the letter back.  2008 R2 seems to auto populate the letter back to the way the originated with no issue.  Fortunately if you make it this far you are in the home stretch.   But wow.  It was certainly a pain getting to this point which is why im documenting it for others.   Good luck and happy importing!