Hyper-V, fixing moved VHD files

Here is a scenario for you: some lowly admin thinks he will free up space by moving a VHD file, or perhaps you add more storage to your home test lab, and move your VHD files to the new drive.  If you tried this operation while the VM is running, the file copy will fail.

If you try this on saved or shut down VMs, you can definitely move the virtual hard drive (.vhdx file) which will cause the VM associated with it to rather predictably fail when powered on, as seen below.

1
Failed to restore with error The System cannot find the file specified.
Attachment .vhdx not found. The System cannot find the file specified.
The hard disk image file does not exist.

Lets verify by going to the path specified.

2
Sure enough, there is no VHD file at the path listed.

Now, lets determine where the VHD file went off to.  Lets use Powershell to track down the VM’s ID.

3
Here we are searching for VMs that match the name specified, and then selecting the VM id and the VM Configuration File storage Path (E:\) in the screenshot above.

Using this excellent blog post by Ben Armstrong I determined that the VM configuration files are stored in the Virtual Machines folder on the path specified in the Powershell output (you can also check this using the Hyper-V console)

4
Sure enough, we see a Virtual Machines folder in the path specified.

Earlier, we saw that the VM ID was 6D68E…, lets open the configuration file associated with it.

 

5

 

Search for the VHD path we gathered from the earlier error message.  You should find this under the <controller#> <drive#> tags in the XML.  Replace the incorrect path with the correct path.  Be sure to omit any single or double quotes.

6

 

Now save the file, and try to restart the VM again with Hyper-V or Powershell.

7
If all went well, you should now see the VM started successfully!

I hope this helps you!

Advertisements

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