The type of work I do relies heavily on passing Hyper-V VMs around. When I send a VM to someone, I usually export a copy onto an external Hard Drive. In a perfect world, the VM would get copied off of the external drive to the local machine before being imported, but that sometimes doesn’t always happen. One user imported the VM while it was still on the external drive. Granted the VM would still work, it would probably be considerably slower due to running off of USB. They ran into problems on their host machine, so they decided to swap it out for another host machine. They shutdown the VM, and deleted it from Hyper-V. Then they plugged in the external drive into a new machine, and tried to import the VM again. This time they received an error:
A server error occurred while attempting to import the virtual machine.
Import failed. Unable to find virtual machine import files under location ‘D:\vm-export\test-import\’. You can import a virtual machine only if you used Hyper-V to create and export it.
Hyper-V doesn’t allow you to import VMs multiple times. In order to import the VM again, they would have needed to export the VM beforehand in order to prepare it for being imported on the second machine. The export process basically, cleans up the file structure of the VM and creates a config.xml file similar to the following:
Upon importing the VM, Hyper-V looks for and then removes the config.xml file. If it can’t find that file, you will get an error message.
Now, if you have received this message, there is no need to panic. There are still ways to recover your VHD files. If your VM had 0 snapshots it is actually very easy to bring the VM back online. Dig around through the VM’s folder structure and locate its VHD file. That is the virtual hard disk that your VM uses to store all of its information.
If you have a VM with snapshots, the process will be a little different. Essentially, you will need to use the “Edit Disk” feature in Hyper-V to merge the AVHD disks into 1 VHD file, and then create a new Virtual Machine using that VHD file. There is a good guide located http://www.networkfoo.org/server-infrastructure/recovering-your-virtual-machine-how-manually-merge-hyper-v-snapshots-back-one- that can help you merge your AVHDs back into a single VHD file.
Once you have a single VHD file, in Hyper-V, create a new Virtual Machine. Give it a name and location, and fill out all the other important information it asks. Then once you get to the “Connect Virtual Hard Disk” screen, select “Use an existing virtual hard disk” and then browse and select the VHD file you found from above. Finish creating the VM and turn it on. The VM should work just as it did before.