A tool to move an Hyper-V Virtual Machine without exporting it

By jay at February 20, 2009 20:26
Filed Under:

Cet article est disponible en francais.

Hyper-V is a wonderful tool, and provides great performance and stability. But on the administration side, available tools are a bit scare, and even though most general operations are available, some are a bit hard to use. One can guess that this will improve in Windows Server 2008 R2.

But for now, the administration tools do not provide any mean to import a VM that has not been previously exported. Exporting a VM can only be done on the original host server while it is still running. In the case of a crashed server, exporting a VM becomes a bit more complex.

Some techniques do exist, here and there, that explain by means of mklink and icacls, how to recreate symbolic links and file permissions for the VM configuration files. But that stays a particularly complex task, mostly because all files must be modified, and a specific order must be respected for all modifications. And this is especially true for the case of a running host server.

After having dug in Hyper-V symlinks and WMI interface, I created a GUI tool that allows to attach and detach VM that have not been previously epoxted.

Some thougts on this tool :

  • A VM can only be detached if it is in the "Saved" or "Stopped" state.
  • It is not necessary to stop the Hyper-V service and all modifications are detected live by the service.
  • A VM can only be imported if it contains at least on HDD on the IDE 0 controller.
  • All the VM files must be under the same directory, HDD and snapshots.
  • All files that are modified are backed-up next to the original files; All other files are not modified nor moved.
  • .NET 3.5 must be installed.

I'll provide the sources for this tool in a near future, as well as a console version.

Of course, there will be bugs, and do not hesitate to report them to me. I may not be able to do anything about it because it is a tool that performs a operation that is (I assume) not supported by Microsoft.

You can download the tool here.

Comments

5/5/2009 2:52:01 AM #


Jerome –

We have found a couple of attach problems with VMMOVE. One that we found a work-around for and one that we are stumped by.

1.  The first attach problem yields the error message:


5/3/2009 11:56:46 AM : Trying to attach VM in S:\TEMP\GERMMSG
5/3/2009 11:56:46 AM : Importing [S:\TEMP\GERMMSG] using [C:\ProgramData\Microsoft\Windows\Hyper-V] on [.]
5/3/2009 11:56:47 AM : System.Exception: No VM can be found in the specified directory.
   at HyperVMover.HyperVUtils.AttachVM(String hyperVRootPath, String path, String hostMachine)
   at VMMove.Models.VMListView.LinkMachine(String path)
   at VMMove.MainWindow.linkButton_Click(Object sender, RoutedEventArgs e)

The work-around is to make sure that the “Snapshots” directory is created. On lots of our Hyper-V virtual machines, it had not been created as there had never been a snapshot taken. Perhaps you can fix this by not requiring the Snapshots directory or creating an empty one if it’s not there.


2.  The second attach problem yields the error message:

5/3/2009 12:06:22 PM : Trying to attach VM in S:\TEMP\GERMMSG
5/3/2009 12:06:22 PM : Importing [S:\TEMP\GERMMSG] using [C:\ProgramData\Microsoft\Windows\Hyper-V] on [.]
5/3/2009 12:06:22 PM : System.NullReferenceException: Object reference not set to an instance of an object.
   at HyperVMover.HyperVUtils.<>c__DisplayClass24.<GuessOriginalBasePath>b__1b(<>f__AnonymousType3`3 xPath)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at HyperVMover.HyperVUtils.GuessOriginalBasePath(String configurationFile)
   at HyperVMover.HyperVUtils.AttachVM(String hyperVRootPath, String path, String hostMachine)
   at VMMove.Models.VMListView.LinkMachine(String path)
   at VMMove.MainWindow.linkButton_Click(Object sender, RoutedEventArgs e)


We have no idea what this is or why it’s happening as the machines it is happening on detached just fine. We would like to email you the .XML file for that virtual machine for your inspection in hopes of finding a solution since this same error is happening on over a dozen other virtual machines we want to re-attach.

Thanks for your great utility,

Joseph R. Worrall
Lakewood Communications
110 Shadow Creek Way
Ormond Beach, FL. 32174
Microsoft Certified Partner
HTTP://WWW.LAKECOMM.COM

Joseph Worrall United States

10/29/2009 9:04:39 PM #

Your Utility is amazing. It made a tense, time sensitive deployment super easy for me. I thank you so much for your work on this, and will definately tell my friends about this app.

Lawrence Felipe United States

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading




About me

My name is Jerome Laban, I am a Software developer and .NET enthustiast from Montréal, QC. You will find my blog on this site, where I'm adding my thoughts on current events, or the things I'm working on, such as the Bluetooth Remote Control Software for Windows Mobile.