Situation: You have a bunch of VM’s on a Server 2008 R2 RC instance. The RC expires and dies a horrible death at the hands of the IT manager, who complains for more time than it takes to reinstall the server about someone actually loading an RC onto the server. You now have a working server, but an empty Hyper-V manager, zero snapshots and no config file backups. In the rush to reinstall, VM’s were not exported, but instead just had their VHD and AVHD files copied…

Post Situation Analysis: Bye bye snapshots, bye bye VM configs. In other words quite bleak.

Rushed Solution: Mount the original VHD, create a blank snapshot, rename the snapshot files, and launch!

Rushed Solution == Bad Idea

If you have one base VHD with no snapshot, great! Mount it and off you go. If you have snapshots, you could be in for a rocky ride (you are already 25% stuffed transferring an RC hosted VM to RTM). True, it may work when mounting the last image as described in the rushed solution. What I found was that I got a BSOD on login, but after booting into safe mode and then rebooting again it was ok. The problem I encountered on VM’s with many snapshots (5+) was that at the point of booting up normally and logging in, the registry corrupted. Windows restored the registry, however this left the networking components and drivers for Windows in a completely unusable state (even legacy adapters), and the VM’s needed to be reloaded from scratch after copying data to new VHD’s, and mounting those in new VM’s.

Snapshots use a hierarchical structure (Each VHD/AVHD is basically appended onto the previous one) to keep track of changes without duplicating entire drives. The following info won’t get you to a state where you can flip between snapshots (it’s a sacrifice), but it will give you a working machine at the point that you needed it for data recovery purposes, with all data from all snapshot points.

  1. BACKUP YOUR VHD’s, merging will erase each snapshot on completion, an expensive thing to realise too late!
  2. Launch the Hyper-V manager, and select “Edit Disk”
  3. Click “Next”
  4. Select the last snapshot in the directory (this can be done by viewing the last modified date of the AVHD files, the most recent is most likely your latest snapshot. You can also make use of the “Inspect Disk” option to check.)
  5. Select “Merge” – Another step will appear in the bar on the left
  6. Opt to merge the changes to the parent disk. (Don’t panic as I did at the lack of control from this step, Hyper-V will select the correct parent disk for you.)
  7. Complete the wizard

This will merge the latest snapshot into the previous one. Repeat steps 2-7 for each snapshot level. Once you have merged all the snapshots and the parent disk is listed as the original VHD, you have everything ready to to complete the wizard for the last time. You now have the original VHD containing the complete snapshot tree. Finally set up a new machine with the VHD, and recover your data from the VM.

Note: Only Hyper-V in R2 recognises AVHD files in the Edit Disk wizard, if you are using 2008 R1, rename the AVHD extension to VHD.

Note #2: Thank you to all the various Hyper-V related sites that I trawled through to get to this information, unfortunately I cannot remember you all, by far the most informative in content and comments was on “Hyper-V notes from the field“, thanks Robert! Please visit this site too, as he has outlined a couple more ways in getting the VHD’s merged, I simply covered what I find to be the easiest method in my own terms for my own situation.

Share This

Share this post with your friends!