Merge differencing disks (AVHD/AVHDX) to boot Hyper-V machine after restoring to files from Hyper-V datasource

Last Modified

Tue Jan 07 14:54 GMT 2020

Description

  • Hyper-V machine won't boot after restoring files from Hyper-V datasource
  • AVHD/AVHDX files restored from Hyper-V datasource
  • Merge differencing disks (AVHD/AVHDX) to boot Hyper-V machine after restoring to files from Hyper-V datasource

Environment

  • Data Protection
  • Hyper-V datasource

Solution

  • Warning: Do not, under any circumstances, change a file's .AVHDX extension to .VHDX manually prior to contacting support
    • In some circumstances this can cause data loss
    • The only time this is valid is when attempting to mount the last AVHDX in Hyper-V's differencing chain; but this should be done only on support's recommendation
  • AVHD/AVHDX files are differential snapshots created by Hyper-V checkpoint service
    • AVHD refers to Gen 1 Hyper-V host (Windows 7/Server 2008)
    • AVHDX is Gen 2 Hyper-V host (Windows 8/Server 2012 and later)
    • AVHD can be used by a Gen 2 host, but AVHDX is not compatible with a Gen 1 host
  • In Server 2016/2019 and later, the following file extensions may also be found:
    • .RCT
      • Stands for Resilient Change Tracking
      • Similar to VMware's Change Block Tracking technology, this file tracks changes between backups for the VM, to make subsequent backups run more quickly
    • .MRT
      • Stands for Modifiable Region Table
      • Used for change tracking purposes in the event of a host system crash or power loss, to ensure changes are not missed
    • These files should not be modified or altered in any way
    • If these files grow too large, contact Microsoft for assistance
      • Typically these files should shrink after merging all .AVHD/.AVHDX files for a VM
  • To merge files manually:
    1. Select Hyper-V server in Hyper-V Manager
    2. On left-hand side, select Inspect Disk
    3. Browse to location of restored AVHD/AVHDX files
    4. Select one of the AVHD/AVHDX files > OK
    5. Record parent disk name
    6. Repeat steps 2-5 for each AVHD/AVHDX file, and record their order (from newest to oldest)
      • Note: do not use timestamps to determine which files to merge, as this could lead to overwriting the incorrect parent file
    7. Select Hyper-V server in Hyper-V Manager
    8. On left-hand side, select Edit Disk
    9. Next > Select newest AVHD/AVHDX file
    10. Next > Select Merge
    11. Next > To the parent virtual hard disk
    12. Finish
    13. Repeat steps 7-12 for each AVHD/AVHDX disk, until only the VHD/VHDX disk is left for the machine
    14. Mount VHD/VHDX in new virtual machine in Hyper-V and boot
  • To merge files with PowerShell (requires Windows 10/Server 2016 and later):
    1. Open PowerShell and run command to navigate to directory where AVHDX and VHDX files are located:
      • Note: if files are on different disk than C:, first change to correct disk with disk letter in PowerShell prompt:
        • <disk letter>:
        • For example, if data is located on drive D:, command would be:
          • D:
      • To change to correct directory:
        • cd <directory path where files are located>
    2. Run following command on each AVHDX file:
      • Get-VHD .\<name of AVHDX file>.avhdx
    3. Note name of parent AVHDX file from ParentPath entry in output
    4. Repeat steps 2 and 3 until you have a list of all AVHDX files with their respective parent AVHDX files
    5. Beginning from newest AVHDX file (only AVHDX file with no child file), run following command:
      • Merge-VHD -Path '<path to AVHDX>' -DestinationPath '<path to parent AVHDX'
    6. Repeat step 5 on each AVHDX, always starting with newest available file
    7. Once all AVHDX files are consolidated, merge last AVHDX with main VHDX file:
      • Merge-VHD -Path '<path to AVHDX>' -DestinationPath '<path to main VHDX disk'
    • Note: this method requires that the Merge-VHD and Get-VHD cmdlets be added to your PowerShell; if you do not have it added, you may receive the following error:
      • Merge-VHD : The term 'Merge-VHD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      • If you receive this error, run this command from an elevated PowerShell prompt to install the Merge-VHD cmdlet:
        • Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell