Xen VHD Recovery: How to Recover, Repair, and Restore XenServer Virtual Disk Files
When a XenServer VHD becomes corrupted, snapshots break, or storage repositories fail, virtual machines can go offline instantly. Recovery isn’t optional — it’s the difference between downtime and continuity.
This article explains how to repair damaged Xen VHDs, restore lost VM data, and recover files from inaccessible storage. You’ll see the main causes of corruption, practical recovery workflows, and the tools that make the process reliable.
📌 Goal → Give admins a clear path to recover Xen VHDs quickly and safely, keeping XenServer and XCP‑ng environments resilient.
VHDX and AVHDX: What Each File Does and Why They Must Be Merged
VHDX: The Base Virtual Disk
- Definition → VHDX (Virtual Hard Disk Extended) is the primary virtual disk format for Hyper‑V Generation 2 VMs (Windows Server 2012+).
- Role → Contains the guest OS, application data, and persistent writes outside of checkpoints.
- Parent in chain → All differencing disks (AVHDX) ultimately merge back into the VHDX.
- Capacity → Supports up to 64 TB.
- Advantage over VHD → Larger size limits, better performance, improved corruption resistance. 📌 Key point → The VHDX is the authoritative disk; all checkpoint data must eventually consolidate into it.
AVHDX: The Differencing Disk Created by Every Checkpoint
- Definition → AVHDX (Automatic Virtual Hard Disk Extended) is a differencing disk created when a checkpoint is taken.
- Mechanism → Hyper‑V freezes writes to the base VHDX and redirects new writes to the AVHDX.
- Content → Stores only changes made after checkpoint creation; references parent VHDX or another AVHDX for baseline data.
- Chain structure →
- Critical rule → AVHDX files must be merged in reverse order (newest child first → back to base VHDX).
- ⚠️ Risk → Skipping or merging out of order breaks the chain, producing an unusable disk. 📌 Key point → Proper sequential merging is mandatory to restore a consistent VM state.
VM.vhdx (base) ? VM_GUID.avhdx (Checkpoint 1) ? VM_GUID2.avhdx (Checkpoint 2) ? VM_GUID3.avhdx (Current state)AVHD vs. AVHDX: Generation 1 vs. Generation 2
- AVHD → Legacy differencing disk format for Generation 1 Hyper‑V hosts (Windows Server 2008 / Windows 7).
- AVHDX → Modern format for Generation 2 Hyper‑V hosts (Windows Server 2012+).
- Compatibility →
- AVHD can still be used by Gen 2 hosts for backward compatibility.
- AVHDX is not backward‑compatible with Gen 1 hosts.
- Merge procedure → Identical for both formats; handled via PowerShell cmdlets (
Merge-VHD) or Hyper‑V Manager. 📌 Key point → Always confirm the file extension before merging to avoid generation mismatch.
📊 VHDX / AVHDX Checkpoint Chain Reference
| File Type | Role | Created When | Contains |
|---|---|---|---|
| .vhdx | Base parent disk | VM creation | Full OS + data at baseline |
| .avhdx (first) | Child of VHDX | First checkpoint taken | All writes after first checkpoint |
| .avhdx (second) | Child of first AVHDX | Second checkpoint taken | All writes after second checkpoint |
| .avhdx (nth) | Child of (n‑1) AVHDX | Nth checkpoint taken | All writes after nth checkpoint |
| .vmrs | Runtime state | Checkpoint of running VM | CPU/RAM state at checkpoint time |
| .vmcx | Configuration | Checkpoint creation | VM hardware config at checkpoint time |
🔄 Why You Need to Merge Hyper‑V Snapshots
⚡ Performance Degradation from Long Checkpoint Chains
Every read operation on a VM with active AVHDX differencing disks must traverse the entire chain back to the base VHDX.
- Example: A chain of 10 AVHDX files = 11 lookups per read.
- Result → measurable I/O slowdown as chains lengthen.
- Microsoft supports up to 50 checkpoints per VM, but performance issues appear much earlier. 📌 Best practice → Production VMs with more than 3 active checkpoints should be merged immediately.
💾 Storage Consumption Growth
AVHDX files are dynamic — they grow as the VM writes data.
- A new AVHDX starts at 0 bytes but can expand to the full size of the parent VHDX.
- Backup jobs that leave temporary checkpoints behind cause AVHDX files to grow unchecked.
- If datastore space fills, the VM halts. 📌 Risk → Orphaned AVHDX files consume storage until merged or deleted.
🛑 Backup Application Failures
Most Hyper‑V backup tools (Veeam, Commvault, Windows Server Backup) rely on checkpoint‑based backups.
- Orphaned or mismatched AVHDX files break the chain.
- Common errors: “inconsistent snapshot chain” or “unable to read differencing disk.” 📌 Solution → Merging orphaned AVHDX files is required before backup jobs can succeed again.
🗑️ Orphaned AVHDX After Checkpoint Deletion
Deleting a checkpoint in Hyper‑V Manager triggers an automatic merge of its AVHDX into the parent.
- Merge runs as a background task while the VM is active.
- Failures occur due to:
- Storage I/O errors
- Insufficient disk space
- Hyper‑V service interruptions
- If merge fails, the AVHDX remains on disk even though the checkpoint disappears from the Manager. 📌 Impact → VM no longer references the file, but it lingers, wasting space. Manual merge is required to reclaim storage and restore a clean chain.
Method 1: Merge Hyper‑V Snapshots Using Hyper‑V Manager
Prerequisites Before Starting the Merge
Before merging any AVHDX files:
- 🖥️ VM state → The VM must be powered off or in a Saved state.
Merge‑VHDis an offline operation; disks cannot be in use. - 🔗 Chain mapping → Identify the complete checkpoint chain using Hyper‑V Manager or PowerShell
Get‑VHD. - 💾 Backup first → Copy all AVHDX and VHDX files to a safe location. A failed merge leaves the chain inconsistent; without backup, recovery is impossible.
- 📦 Free space check → Ensure sufficient volume space. The merge writes AVHDX data into the parent VHDX, which grows to accommodate merged content.
Step‑by‑Step: Merge AVHDX into VHDX via Hyper‑V Manager Edit Disk
Step 1. Open Hyper‑V Manager. In the center pane, select the target VM.
Step 2. Under Actions in the right pane, click Edit Disk. The Edit Virtual Hard Disk Wizard opens.
Step 3. Click Browse and navigate to the VM’s virtual disk directory. Locate the AVHDX files — they share the VM name with a GUID suffix:
VMname_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.avhdxStep 4. Select the latest (newest) AVHDX file in the chain. Click Next.
Step 5. On the Action page, select Merge. Click Next.
Step 6. On the Merge page, select To the parent virtual hard disk. Click Finish.
- Hyper‑V Manager merges the selected AVHDX into its immediate parent (another AVHDX or the base VHDX).
- One level of the chain is removed per operation.
Step 7. Repeat Steps 2–6 for each remaining AVHDX file, always selecting the newest remaining file at each iteration, until all AVHDX files are merged and only the base VHDX remains.
Step 8. Power on the VM and verify normal operation.
- Check Hyper‑V Manager’s checkpoint list → it should show no checkpoints for the VM.
📌 Key takeaway → Merging snapshots in reverse chain order via Hyper‑V Manager ensures a clean consolidation back into the base VHDX, restoring VM stability and reclaiming storage.
Method 2: Merge VHDX and AVHDX Files Using PowerShell Merge‑VHD
Prerequisites: Enable the Merge‑VHD Cmdlet
- The
Merge‑VHDcmdlet requires the Hyper‑V PowerShell module. - If missing, PowerShell returns: “The term 'Merge‑VHD' is not recognized as the name of a cmdlet.”
- Enable on Windows 10/11:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell- Enable on Windows Server:
Install-WindowsFeature -Name RSAT-Hyper-V-Tools- Verify availability:
Get-Command Merge-VHDStep 1: Map the Full AVHDX Chain with Get‑VHD
Before merging, identify the entire checkpoint chain:
- Check a specific AVHDX file’s parent:
Get-VHD -Path "C:\VMs\VMname\Virtual Hard Disks\VMname_GUID.avhdx"- Output shows:
VhdType: DifferencingParentPath: C:\VMs\VMname\Virtual Hard Disks\VMname.vhdx(or another AVHDX).
- Follow each
ParentPathuntil you reach the base VHDX (VhdType: Dynamic or Fixed). - Document the chain order before merging.
For complex multi‑disk chains, use Microsoft’s Get‑VHDChain function:
function Get-VHDChain {
[CmdletBinding()]
param(
[string]$ComputerName = $env:COMPUTERNAME,
[string[]]$Name = '*'
)
$VMs = Get-VM -ComputerName $ComputerName -Name $Name
foreach ($vm in $VMs) {
$VHDs = ($vm).harddrives.path
foreach ($vhd in $VHDs) {
$VHDInfo = $vhd | Get-VHD -ComputerName $ComputerName
$i = 1
while ($VHDInfo.parentpath -or $i -eq 1) {
if ($i -gt 1) { $VHDInfo = $VHDInfo.ParentPath | Get-VHD -ComputerName $ComputerName }
[pscustomobject]@{
Name = $vm.name
Depth = $i
Type = $VHDInfo.VhdType
Path = $VHDInfo.path
}
$i++
}
}
}
}
Get-VHDChain -Name "YourVMName"Step 2: Merge Each AVHDX into Its Parent — Newest First
Always merge newest → parent → base VHDX.
- Merge one AVHDX into its parent:
Merge-VHD -Path "C:\VMs\VMname\Virtual Hard Disks\VMname_GUID_newest.avhdx" `
-DestinationPath "C:\VMs\VMname\Virtual Hard Disks\VMname_GUID_parent.avhdx"- Merge last AVHDX directly into base VHDX:
Merge-VHD -Path "C:\VMs\VMname\Virtual Hard Disks\VMname_GUID.avhdx" `
-DestinationPath "C:\VMs\VMname\Virtual Hard Disks\VMname.vhdx"- Multi‑level merge (Microsoft Learn syntax):
Merge-VHD -Path "C:\test\Child4.vhdx" -DestinationPath "C:\test\Child2.vhdx"📌 Confirmed by N‑Able documentation → Always start with the newest AVHDX, merge sequentially, and finish with the base VHDX.
Step 3: Update VM Configuration and Power On
After merging, the VM may still reference the old AVHDX path. Update configuration:
- Option A — Edit VM settings:
- Hyper‑V Manager → VM → Settings → Hard Drive → change path to merged VHDX.
- Option B — Create new VM (recommended after orphaned chain recovery):
- New Virtual Machine Wizard → Use an existing virtual hard disk → select merged VHDX.
Finally, power on the VM:
- Successful boot = merge completed correctly.
- Boot failure = incomplete chain merge → re‑map with
Get‑VHDand repeat.
📌 Key takeaway → PowerShell Merge‑VHD provides precise control for merging complex AVHDX chains, ensuring clean consolidation back into the base VHDX and restoring VM stability.
Method 3: Delete Snapshots via Hyper‑V Manager (Automatic Merge)
⚙️ How Automatic Merge Works When Deleting Checkpoints
Deleting a checkpoint in Hyper‑V Manager (Right‑click → Delete Checkpoint) triggers an automatic merge of the associated AVHDX into its parent.
- Runs as a background task while the VM remains online.
- VM continues operating with only minor I/O impact.
- Preferred for production workloads → no manual file handling, no downtime, no chain mapping.
Automatic merge scenarios:
- 🟢 Delete single checkpoint → merges its AVHDX into parent.
- 🌳 Delete Checkpoint Subtree → merges checkpoint + all children.
- 📦 Delete All Checkpoints → merges entire chain back into base VHDX.
📌 Key point → Automatic merge is the safest, least disruptive method for consolidating snapshots in production.
⚠️ When Automatic Merge Fails — Signs and Causes
Automatic merge can fail silently in several scenarios:
- 💿 Insufficient disk space → VHDX grows during merge; if volume fills, merge rolls back and reschedules.
- 📉 Storage I/O errors → write phase interruptions prevent completion.
- 🔄 Hyper‑V service interruption → host reboot, Windows Update restart mid‑merge.
- 🔒 AVHDX locked by backup software → merge blocked until lock is released.
Signs of failed automatic merge:
- Checkpoint deleted in Manager but AVHDX file still exists on disk.
- Storage usage unchanged after deletion.
- Hyper‑V event logs show merge task errors.
📌 Action → If automatic merge fails, proceed with manual PowerShell merge (Merge‑VHD) to restore the chain.
Hyper‑V Snapshot Merge: Troubleshooting Common Failures
❌ Error: “Merge‑VHD : The term 'Merge‑VHD' is not recognized”
- Cause → Hyper‑V PowerShell management module not installed.
- Fix →
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShellOr on Windows Server:
Install-WindowsFeature -Name RSAT-Hyper-V-ToolsThen reopen PowerShell as Administrator and retry.
❌ Error: “The virtual disk is currently in use”
- Cause → VM is running or another process holds the AVHDX/VHDX file open.
Merge‑VHDis an offline operation. - Fix →
- Shut down the VM completely.
- Check Task Manager and Hyper‑V event logs for processes holding the file.
- If locked by backup software, cancel active backup jobs before retrying.
❌ Error: “OperationFailed” or “VirtualizationException”
- Cause → Multiple possible:
- Corrupted AVHDX
- Out‑of‑order merge attempt
- Parent path mismatch in AVHDX metadata
- Diagnosis →
Get-VHD -Path "C:\VMs\VMname\Virtual Hard Disks\VMname_GUID.avhdx"- Check
ParentPathoutput. - Verify the parent file exists.
- If parent path is invalid, metadata is corrupted → proceed to data recovery workflow.
- Check
❌ Error: “A parameter cannot be found that matches parameter name 'vmname'”
- Cause → Passing
-VMNametoMerge‑VHD. The cmdlet accepts file paths only, not VM names. - Fix → Identify disk paths first:
Get-VM -Name "VMName" | Get-VMHardDiskDriveThen pass the path directly:
Merge-VHD -Path "C:\VMs\VMname_GUID.avhdx" -DestinationPath "C:\VMs\VMname.vhdx"❌ Error: Chain Appears to Complete But VM Will Not Boot
- Cause → VM configuration (
.vmcx) still references old AVHDX path. - Fix →
- Recommended → Create a new VM pointing to the merged VHDX:
- New Virtual Machine Wizard → Use an existing virtual hard disk → select merged VHDX.
- Recommended → Create a new VM pointing to the merged VHDX:
- Avoid editing stale
.vmcxconfigs; they retain checkpoint references that break boot.
📌 Key takeaway → Most merge failures stem from missing modules, active locks, incorrect chain order, or stale VM configs. Systematic diagnosis with Get‑VHD and careful path validation resolves the majority of issues.
📊 Hyper-V Snapshot Merge Error Reference Table
| Error | Cause | Fix |
|---|---|---|
| Merge-VHD not recognized | Module not installed | Enable-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Management-PowerShell |
| The virtual disk is currently in use | VM running or file locked | Shut down VM; cancel backup jobs; retry |
| OperationFailed / VirtualizationException | Corrupted AVHDX or wrong merge order | Run Get-VHD to verify chain; always merge newest-first |
| VM won't boot after merge | VM config still references AVHDX | Create new VM pointing to merged VHDX |
| Merge scheduled but AVHDX not shrinking | Automatic merge blocked by low disk space | Free disk space; retry deletion in Hyper-V Manager |
| A parameter cannot be found: vmname | Wrong parameter for Merge-VHD | Use -Path and -DestinationPath with full file paths |
Recovery When AVHDX or VHDX Files Are Corrupted or Missing
🛑 When Merge Fails Due to Corrupted AVHDX Data
- Cause → AVHDX corruption from storage faults, host power loss, or partial writes during failed backups.
- Symptom →
Merge‑VHDreturns errors referencing the damaged file. - Impact → Data written after the preceding checkpoint exists only in this AVHDX. Losing it means losing all changes since that checkpoint.
- ⚠️ Critical warning (per N‑Able docs) → Do not rename or change an AVHDX extension to VHDX. This corrupts metadata further and eliminates recovery options.
🔄 Cross‑Platform Context: VMware VMFS, VMDK, and Hyper‑V VHDX Recovery
- Hyper‑V → Uses VHDX/AVHDX differencing disks.
- VMware → Uses VMFS datastores with VMDK files. Delta VMDKs (
VMname‑000001.vmdk) are the VMware equivalent of AVHDX differencing disks. - Problem → When VMFS datastores go offline or VMDKs are corrupted, standard Windows/Linux tools cannot parse VMFS structures. 📌 Key point → Mixed environments or migrations expose admins to both Hyper‑V and VMware recovery challenges.
🛠️ DiskInternals VMFS Recovery™ for VMware VMDK and VMFS Recovery
Purpose‑built for VMware recovery:
- Recovers data from corrupted or inaccessible VMFS datastores.
- Restores deleted or damaged VMDK files (including delta snapshots).
- Mounts VMDK files without a running ESXi host.
- Reconstructs VMFS volumes with damaged metadata.
- Recovers VMX configuration files.
- Supports remote ESXi connections via IP + credentials.
Workflow:
- 1. Connect to the VMFS volume.
- 2. Run a full scan.
- 3. Locate VMDK files in the recovery browser.
- 4. Preview file integrity (read‑only).
- 5. Extract to a safe destination.
- 6. Re‑register in VMware or convert to VHDX for Hyper‑V use.
📌 Takeaway → For admins managing both Hyper‑V and VMware, DiskInternals VMFS Recovery™ provides the VMware side of the safety net, complementing Hyper‑V snapshot merge and VHDX repair workflows.
Preventing AVHDX Chain Problems: Best Practices
⏳ Keep Checkpoint Chains Short
- Limit active checkpoints to 2–3 maximum.
- Delete checkpoints promptly once the required operation is complete.
- For dev/test VMs with frequent checkpoints → schedule weekly “Delete All Checkpoints” to collapse chains.
- Monitor datastore usage → unexpected growth is the first sign of accumulating AVHDX files.
📊 Monitor Background Merge Task Completion
- After deleting a checkpoint in Hyper‑V Manager, watch the VM’s storage consumption in the summary panel.
- Consumption should decrease as AVHDX merges into VHDX.
- If usage does not drop within expected time (based on AVHDX size + storage throughput), check Hyper‑V event logs for merge task errors.
💾 Back Up Before Any Manual Merge Operation
- Always copy VHDX + AVHDX files to a safe location before manual merge.
- Incorrect chain order can leave the VHDX inconsistent.
- With backups, you can restore the original chain and retry the merge correctly.
📌 Key takeaway → Preventing AVHDX chain problems is about checkpoint discipline, monitoring merges, and safeguarding with backups. These practices minimize risk and ensure recovery remains possible if corruption occurs.
FAQ
What is the difference between VHDX and AVHDX?
VHDX is the base virtual hard disk containing all VM data. AVHDX is a differencing disk created when a Hyper-V checkpoint is taken — it stores only the changes made after the checkpoint. To merge them, all AVHDX files must be committed back into the base VHDX.Can I merge AVHDX files while the VM is running?
Not with Merge-VHD — it requires the disks to be offline. The automatic merge triggered by deleting a checkpoint in Hyper-V Manager runs while the VM is running. Manual PowerShell merge requires the VM to be powered off.Do I have to merge AVHDX files in a specific order?
Yes — always start with the newest AVHDX (the one with no child files) and merge toward the base VHDX. Merging out of order breaks the chain and produces an unrecoverable disk.What happens if I rename an AVHDX file to VHDX?
Do not do this. Renaming the extension does not change the file format. An AVHDX mounted as a VHDX will either fail to mount or present corrupted data, and the original merge path is lost. The only safe way to convert AVHDX to VHDX is via Merge-VHD.
