0

There seems to be a glaring hole in Hyper-V's virtual machine export/import toolset. Perhaps I'm mistaken with this assessment, but I don't think so.

I have a VM that I restored from backup after a host OS reinstall. The VM's location (and its VHDXs) are outside of the host's defaults (C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines and D:\Virtual Hard Disks). I wish to move it to these locations, but as the VHDXs are rather large (+10TB) a standard import promises at least a twelve-hour copy job. The VHDXs are on the same drive, albeit in a different folder, as the default, so shutting down the VM and moving them will be trivial.

I tried copying the configuration files to the default location and running an in-place registration, but I encountered an error:

enter image description here

Needless to say, this is not very helpful.

I suppose I could manually create a new VM and point to the VHDXs, but I've painstakinly crafted its configuration over time and I'd rather not risk missing a setting by accident.

How can I get this VM into the default location without requiring the arduous task of copying those large VHDXs?

InteXX
  • 713
  • 13
  • 31

2 Answers2

2

Registering a VM in-place that's not in the hosts default location and wanting it to be in the hosts default location is a contradiction in terms. In-place registration means you want to register and run the VM in it's current location. I don't see this as a glaring hole. The possible outcomes are clear from Microsoft's documentation.

If you want to register it in the hosts default location then use one of the latter two options listed below.

Register in-place – This type assumes export files are in the location where you'll store and run the virtual machine. The imported virtual machine has the same ID as it did at the time of export. Because of this, if the virtual machine is already registered with Hyper-V, it needs to be deleted before the import works. When the import has completed, the export files become the running state files and can't be removed.

Restore the virtual machine – Restore the virtual machine to a location you choose, or use the default to Hyper-V. This import type creates a copy of the exported files and moves them to the selected location. When imported, the virtual machine has the same ID as it did at the time of export. Because of this, if the virtual machine is already running in Hyper-V, it needs to be deleted before the import can be completed. When the import has completed, the exported files remain intact and can be removed or imported again.

Copy the virtual machine – This is similar to the Restore type in that you select a location for the files. The difference is that the imported virtual machine has a new unique ID, which means you can import the virtual machine to the same host multiple times.

How can I get this VM into the default location without requiring the arduous task of copying those large VHDXs?

At the end of the day, regardless of how you accomplish it, if the VM's files aren't in the hosts default location then they need to be copied or moved to the hosts default location. The files need to physically be in the hosts default location to actually be in the hosts default location.

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
  • Pardon me, I wasn't clear. By 'glaring hole,' I was referring to the lack of an in-built ability to do what I'm trying to accomplish. In other words, an ability to import the CONFIGURATION only—without also bringing along the VHDXs. – InteXX Dec 17 '20 at 01:47
  • *"Registering a VM in-place that's not in the hosts default location and wanting it to be in the hosts default location is a contradiction in terms."* That's almost there. I'm wanting to register-in-place a VM configuration that IS in the default location. Good to see you again, Joe :-) – InteXX Dec 17 '20 at 02:36
1

The main VM configuration file (.vmcx) contains pointers to all the other files, including the virtual hard disks; as such, registering a VM in-place requires all files to be in the same place where they were originally located. The only way to change paths is to import the VM, either by restoring or copying it.

If the virtual hard disks only needs to be moved between different paths in the same volume, you can use this workaround to avoid an unnecessary file copy:

  • Register the VM in place where it is.
  • Remove the virtual hard disks from the VM (this will only remove the configuration, the actual VHDX files will not be touched).
  • Move the VM to the desidered location using Hyper-V management tools; this should be quick, since there are no disks to be moved.
  • Manually move the virtual hard disks to the desidered location; this should be also quick, since they are on the same volume.
  • Re-attach the virtual hard disks to the VM.
Massimo
  • 68,714
  • 56
  • 196
  • 319
  • 1
    Now why didn't I think of that! I'll tell you why: because I didn't think of it :-) This is perfect—it accomplishes exactly what I'm after and I'll remember it forever. It's been branded into my forehead. I'd send you a photo, but the bleeding is still a bit profuse yet. Maybe later. *"Against in-the-box thinking, the Gods themselves fight in vain."* – InteXX Dec 17 '20 at 01:51
  • Rats, it didn't work. Apparently moving a VM's configuration must involve two separate hosts—a source and a target. Moving a configuration from one location to another on the same host doesn't seem to be supported. Error [here](https://i.stack.imgur.com/GOafC.png). – InteXX Dec 17 '20 at 02:57
  • OK, I got it to work using [this](https://www.jorgebernhardt.com/how-to-use-move-vmstorage/): `Move-VMStorage -Name SERVICES -VirtualMachinePath D:\VMImportTest`. I must've chosen the wrong options during the attempt with the GUI. I set this back to the accepted answer. Thanks for your patience. – InteXX Dec 17 '20 at 03:13
  • 1
    This went off today without a hitch. – InteXX Dec 18 '20 at 10:01