How to Manually Import a Hyper-V Child Virtual Machine Partition

 

The Hyper-V export/import process is brittle and appears to only work if the stars are properly aligned. If you find yourself needing to move a virtual machine from one host to another and the export/import process is not working then read on.

Option #1:  Copy the .vhd file to the new server, manually create a new virtual machine configuration and attach the .vhd file. 

Pros: The simplest method.
Cons: Does not work with snapshots and you have to manually recreate the machine configuration.

Option #2: Copy the entire virtual machine folder from one host to another. Create symbolic links. Fixup the ntfs security permissions.

Pros: You are able to migrate all settings and keep the snapshots.
Cons: It’s going to take a bit of work… but the example below should help.

Scenario:

· We have 1 virtual machine named Guest1 with several snapshots.

· It’s currently located on Host1, D:\VMs\Guest1. 

· We need to move it to Host2, D:\VMs\Guest1.

· The virtual machine GUID is: 1D8267BB-E46C-4C00-9520-7791EBABA547 (This can be found by browsing to D:\VMs\Guest1\Virtual Machines\<GUID>.xml

Here are the steps to move the guest, create the symbolic links and assign the correct permissions.

1. Stop the virtual machine guest, copy Guest1 folder to D:\VMs on Host2 (You can delete the old machine after you have it successfully running on the new host.)

2. Create a symbolic link in “C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines” (Hyper-V RTM) to point to the virtual machine configuration file.

o mklink “C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\1D8267BB-E46C-4C00-9520-7791EBABA547.xml” “D:\VMs\Guest1\Virtual Machines\1D8267BB-E46C-4C00-9520-7791EBABA547.xml”

3. Assign ntfs permissions to the virtual machine symbolic link

o icacls "C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\1D8267BB-E46C-4C00-9520-7791EBABA547.xml" /grant "NT Virtual Machine\1D8267BB-E46C-4C00-9520-7791EBABA547":F /L

4. Assign ntfs permissions to the virtual machine configuration file that the symbolic link is linked to. (Note: This is the same command we just ran, but without the /L switch. You could also use icacls to point to the configuration file at D:\VMs\Guest1\Virtual Machines\1D8267BB-E46C-4C00-9520-7791EBABA547.xml)

o icacls “C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\1D8267BB-E46C-4C00-9520-7791EBABA547.xml” /grant “NT Virtual Machine\1D8267BB-E46C-4C00-9520-7791EBABA547”:F

5. Create a symbolic link for each snapshot. Repeat for each guid xml file listed in the D:\VMs\Guest1\Snapshots directory.

o mklink C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\73C8BA43-36F7-470D-B710-34D1CA5120DD.xml "D:\VMs\Guest1\Snapshots\73C8BA43-36F7-470D-B710-34D1CA5120DD.xml"

6. Assign ntfs permissions to the snapshot symbolic link. Repeat for each symbolic link you created.

o icacls "C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\73C8BA43-36F7-470D-B710-34D1CA5120DD.xml" /grant "NT Virtual Machine\1D8267BB-E46C-4C00-9520-7791EBABA547":F /L

7. Assign ntfs permissions to all the snapshots in the D:\VMs\Guest1\Snapshots directory to grant the virtual machine access.

o icacls D:\VMs\Guest1\Snapshots /grant "NT Virtual Machine\1D8267BB-E46C-4C00-9520-7791EBABA547":F /T

8. Connect any network adapters on the moved Virtual machine to the virtual networks on the new server.

Notes:

  • My drive paths remained the same so no additional configuration file changes were made.  If your path changes when moving hosts, you’ll need to modify the <guid>.xml file under Virtual Machines to update the path to .vhd and snapshots.
  • I’m using icacls instead of the GUI because it couldn’t find "NT Virtual Machine\<GUID>" when using the security tab.
  • You can put everything together into a batch file and execute at once.
  • Don’t forget to assign the network card to the new virtual switch on the new server.

Credits go to the following posts for helping me put the pieces of this puzzle together:

-Weston

 

Thanks a lot for sharing this information Weston.  I hope this helps out everyone which can utilize the information.

 

William

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s