How to fix Base VHD importing in Hyper-V R2

November 5, 2009 by Thomas Foreman in IT Infrastructure

This week the Wadeware team ran into a big problem in Hyper-V R2. We’re hoping that by posting this blog entry, we’ll be able to help some people out.

A little background, we develop a lot virtual machines (VMs) and have become familiar with Hyper-V and recently started converting over to Hyper-V R2. When exporting a VM in Hyper-V it will copy all of the necessary files needed. If you use base Virtual Hard Disks (VHDs) that are shared by many VMs, it will copy this base VHD for every image exported. All this repetitive image copying is a colossal waste of hard drive space, and once the VMs are exported, we had to go in and delete the duplicate base VHDs. 

In Hyper-V R1, when you imported this VM, as long as the base VHD was located in the same directory as they were exported (such as C:\BaseVM\W2K8R2Base.vhd) it would import just fine.

But note that in Hyper-V R2, when we go to import these VMs on the same R2 server OR on another R2 server we get the following error:

A server error occurred while attempting to import the virtual machine.
Import failed. Unable to find required file or folder “C:\VMs\LabVM\DCServer\Virtual Hard Disk\W2K8R2Base.vhd.”

When inspecting the server’s VHD, it says the parent disk is C:\BaseVM\W2K8R2Base.vhd and after looking in the config.xml file or the exp files, they show the parent disk is C:\BaseVM\W2K8R2Base.vhd as well. Thus, it looks like the R2 import virtual machine wizard is insisting that the base VHD be in the exported location.

The only way to import the VMs is to do the following:

  1. Move the base VHD into the Virtual Hard Disk folder of the exported VM
  2. Import the VM
  3. Move the base VHD out
  4. Inspect the imported VMs VHD
  5. Reconnect it to the base in the C:\BaseVM folder

After consulting with Microsoft, it turns out this is a known issue with R2 and that when exporting VMs, the parent locator information is not updated to reflect the changes of parent locations. So when you do inspection, the parent locator still points to the old folder (although the machine is changed). However, importing a VM does not follow that logic and only checks the exported folder to find parent VHDs.

Thus, VMs can’t be imported through the UI when the base VHD in the Virtual Hard Disks folder is deleted. Instead, Microsoft recommends using their new Import API tool that allows administrators to import the VM pointing to the base VHD on the host.

Information about the new APIs:

You can also refer to example scripts on using new APIs here:

After a little more digging, we also found that MS Learning has a work around to do successful imports by using Symbolic Links to create the missing VHDs for Hyper-V R2.

To mitigate this internally, our developer at Wadeware developed the following script to create Symbolic Links

@ECHO Creating Symlinks necessary to import VM's.
@ECHO ---------------------------------------------
rem ************  to create Symlink for Base Image - substitute VHDName.vhd with the name of the base image needed
mklink "%SUBDIR%\VMs\Client01\Virtual Hard Disks\W2K8R2EEbase.vhd" "C:\BaseVM\W2K8R2EEbase.vhd"

Copy this script to a batch file and adjust the paths. Then put this file in the same folder as your VMs and run it.

Now you can import the machines just fine. Enjoy!