Manually Merge .avhd to .vhd in Hyper-V

Manually Merge .avhd to .vhd in Hyper-V

Hyper-V brings to life several additional disaster recovery scenarios that can be leveraged to our advantage when the need arises. One of the features that really comes into play are VM snapshots. A Snapshot is basically a spot in time where the current running configuration of the Virtual Machines is saved to a Snapshot Differencing Disk file (AVHD), from which you can return to from the future. This tip will show you how to manually merge hyper-v snapshots into a single VM for point in time restores.

When you create a differencing disk the original VHD is no longer modified and the snapshots are merged with the original vhd only when it is powered off. In disaster recovery scenarios, There may be cases where we want to manually merge snapshots ( avhd )

In order to do this, You must first change the extension of the Newest AVHD file to VHD. 

Any VHD differencing disk(avhd) will always go to its parent, not the root parent.

So if you have a bunch of AVHDs, Each depends on the one before it - like the rungs of a ladder - they are sequential.  Most folks have a very simple linear chain of snapshots. Example : VHD - AVHD1 - AVHD2 - AVHD3 - AVHD4. ( Here AVHD4 is the Newest and AVHD1 is the Oldest)

The parent of AVHD4 is AVHD3.  The parent of AVHD3 is AVHD2  The parent of AVHDn would simply be the one before it.

You need to Start Merge From New AVHD to Old AVHD to complete the Merge Operation.

To Start Merge follow the below steps
  • First Identify the Newest AVHD ( In Our Ex : AVHD4)
  1. Rename the Newest AVHD (AVHD4)  to VHD ( Should not rename all the AVHDs at a time, Need to Rename only Newest Avhd First)
  2. You can choose the Edit Disk option from the Actions menu in the Hyper-V Management Console. 
  3. Click Next through the first screen and select the snapshot file on the following screen.


  4. Select Merge on the next screen and choose the To parent virtual disk option and click Finish.
  5. After Successfully Completing Merge, Now Automatically AVHD4 will be deleted.
  • Now Rename the Second Newest Avhd (AVHD3) to Vhd. and Repeats the Steps from 1 to 4 until Oldest AVHD ( AVHD1) Get Merge with Parent VHD.
Once this has completed you should create a new virtual machine with the default options you would normally use, selecting to use an existing virtual disk on the hard disk screen. You should select the newly merged VHD file.

Now you have Successfully Completed Manually Merge avhd to vhd in Hyper-V.

This Guide works with all Hyper-V Versions including Windows Server 2012 R2 with Hyper-V.
 

Sort by: Published Date | Most Recent | Most Useful
Comments
  • Thanks for the Very good Article about Manually Merge avhd to vhd in Hyper-V

  • Very helpful, However I think you mean "newest" and not youngest....

  • Is it blindingly obvious to everyone else, or would it be too much to add a couple of steps for us noobs:

    1.5 For your VM, under settings -> Hard drive, select the AVHD that you just renamed as VHD for your virtual hard disk file.

    6. Once you have merged as many AVHDs as you wish, finally, for your VM, under settings -> Hard drive, select the most recent remaining VHD for your virtual hard disk file.

    Once I figured that out, worked great!

  • Helpful stuff. Pictures would really clarify this.  I just corrupted my Sever 2012 Hyper-V vhdx because I thought delete would merge everything like it did in Server 2008.

    thanks,

    Stephan Onisick

  • Only manually merge as a last resort.

    One better solution (if you have 2008 R2 or newer) is to create a snapshot of the VM.  Then select this snapshot, and export this snapshot.  This will create a copy of your VM with a single VHD.

    Import this snapshot.  Check it.

    If it is good, delete the original.

  • Great article!

  • Great article, thanks. Saved me because SCVMM decided to delete my VM (not the disks) so I had to merge the avhd in to the vhd and create a new VM using the existing vhd disk. Worked fine.

    Richard.

  • Great article, thanks. Saved me because SCVMM decided to delete my VM (not the disks) so I had to merge the avhd in to the vhd and create a new VM using the existing vhd disk. Worked fine.

    Richard.

  • I made a snapshot by accident in a production WS2012 environment so before I do anything I need to make sure of what I'm doing.

    Basically I selected Snapshot from the menu by accident expecting a wizard to open or a confirmation screen to pop up but nothing did and it automatically created a snapshot. I saw the almighty cancel button so I pressed it and the snapshot "cancelled" but i noticed the avhdx file was still created and ever since has been continuing to grow, but in the Hyper-V snapshots windows there are now snapshots there. I've been meaning to get rid of it (it's been a month since it was created and have been doing other things in the mean time) but now on it's own it's created a second snap shot which does appear in the snapshot window and I now have 2 avhdx files.

    I don't want the snapshots as I've seen everywhere it's not recommended in prod environments so i was wondering if someone could recommend what I should do.

    I'm thinking of deleting the snapshot that appears in the snapshot window and shutting off the VM so that those 2 automatically merge (hopefully).

    Then I was going to attempt this manual merge to merge the first snapshot which exists but doesn't display in the snapshot window. Having said that when I click Edit Disk as part of these steps there is a warning saying "Do not edit a virtual disk associated with a VM that has snapshots.. otherwise data loss is likely to occur." So I'm a bit worried about that too.

    My avhdx files aren't numbered but I can tell which is the newest based on update date.

    Any thoughts if I go down this path if I should be safe. The VM is hosting an Exchange Server and I'm stressing it will go belly up and I will need to do a restore from back up.

  • I just tested this with a vanilla VHD that was 9gb, created snapshot, cancelled, avhdx file still created. Created some new files on the VM. Turned off. Merged as per this article. creted new VM pointing to new merged VHD. started up. new files were.

    I'll go ahead with my prod VM on the weekend and hopefully it goes smoothly!