Thursday 6 May 2010

How to merge Hyper-V snapshots to a parent .vhd

Jason Neurohr has a detailed, illustrated post on the subject of merging Hyper-V snapshots to a parent .vhd, leaving you with a single .vhd file you can run without having to worry about the snapshots. I found Jason’s post excellent and the steps described worked like a charm the first time I had to do this (while I didn’t persist, I found exporting a VM with snapshots from the Hyper-V R2 console just wasn’t working—the snapshots weren’t exported as expected).

The merge process is actually quite simple and I’m therefore reproducing just the relevant details from Jason’s post for my own future benefit:

  • Backup the parent .vhd and all snapshot disks (.avhd)
  • Change the extension for all snapshot differencing disks from .avhd to vhd
  • Within the Hyper-V MMC, select the Edit Disk… option
  • On the Locate Disk screen, locate the snapshot disk to be merged
  • Select the Merge option and then the To the parent virtual hard disk option
  • Finish the wizard and create a new virtual machine using the merged disk

If multiple snapshots exist, merge the most recent snapshot into the parent disk and work in reverse snapshot date order all the way back to the parent.

12 comments:

  1. Thank you this worked for me!

    ReplyDelete
  2. Hello,
    My question is just to be sure, when multiple snapshots exist and you merge a snapshot to the parent virtual hard disk, does it mean that the parent virtual HD corresponds to the previous snapshot in the hierarchy of snapshots?

    Will the manual Merge solve the following problem or is there another solution for it?
    With Hyper-V Manager, I've removed several snapshots but the VM went in the Saved State and I can't set it back to the OFF state.
    Each time when I try to delete the Saved State I receive the error "The operation cannot be performed while the object is in its current state”

    ReplyDelete
  3. How about:
    1. Log in to VM running on the latest snapshot
    2. Run disk2vhd.exe from SysInternals
    3. Use the exported VHD as your new consolidated disk...

    Best regards from www.ishadow.com

    ReplyDelete
  4. Okay, I have a VM with 4 snapshots. I want to merge them all into one VHD. When I shut down the VM and open the setttings and click on the hard drive, the Edit option is disabled with a warning that "Edit is not available because snapshots exist...". Ah, how is one supposed to merge the snapshots.
    Other articles say that using the Delete Snapshot or Delete Snapshot tree will merge. Is it really that simple? To me the word "Delete" means that I'm discarding the delta saved in the snapshot--not merging it into the base so the resultant VM will contain the changes made in the snapshot.

    Clarification?

    ReplyDelete
    Replies
    1. Yes simply deleting the snapshots will merge them but the VM has to be shut down for this to happen. And unfortunately there is no obvious indication that this occurs in the Hyper-V manager apart from an Action option called something like "Cancel Merge in Progress". It would be nice if there where some other way to know the merge status. Each of the AVHD files will be automatically deleted once the merge has incorporated them into the VHD and this may take a long time if you have large snapshot files. You can restart the VM but this will cancel the merge and it will have to restart once turned off again back at the beginning last AHVD file to be accessed. It appears that a lot of people don't even know this occurs and go about doing this under their own steam instead of letting Hyper-V do so automatically.

      Delete
  5. The link to Jason's post is broken, so I'm not sure if something is explained there, but...
    What is the point of renaming the .avhd files? I have successfully merged .avhd's to the parent .vhd without renaming them.

    ReplyDelete
  6. good stuff. thanks for sharing.

    ReplyDelete
  7. Why work from the most recent back? It sounds like you would want to do the oldest snapshot and work to the most recent.

    My concern with this is for example.

    I have original file, day 2, day 3, day 4.

    If I was to follow your example... I would merge day 4, then day 3, and finally day 2.

    So I made a change on day 2... added a new website.

    Then day 3 I made significant changes to the website content.

    Finally on Day 4 I made security changes to the website and installed Windows updates.

    Would the changes from day 3 overwrite the security changes from day 4… and more concerning would the new content added on day 3 be overwritten by the original form of the website from day 2?

    Would you please help me find a production website that would confirm the reasons for the backwards recovery?

    ReplyDelete
  8. I was able to find updated information on http://blogs.msdn.com/b/virtual_pc_guy/archive/2009/04/16/what-happens-when-a-snapshot-is-being-merged-hyper-v.aspx that explains why merge in reverse order.

    The merge happens from the most recent diff disk into the previous diff disk. Each time merging the data into the previous until finally it is merged into the original.

    ReplyDelete
  9. almost clear,

    but what to do if the VM was restarted or made minor changes, and the filedates have been changed due to lets say copying to an alternate location, how do i find what waht the right order of files were?

    cock

    ReplyDelete
  10. Still works for 2012. Bacon saved, thanks.

    ReplyDelete

Spam comments will be deleted

Note: only a member of this blog may post a comment.