How to Fix a Corrupted Hyper-V VHD File
Symptoms and error messages for corrupted Hyper-V VHD files are numerous, from the VM refusing to start, to failures to attach the VHD with messages like
"Failed to open attachment 'C:\ directory \MyVHD.vhd'. Error: 'The file or directory is corrupted and unreadable.'”
There are many possible causes why your VHD may become corrupted. It is not necessary to figure out the exact cause if you need it back fast: just restore the VHD from your latest backup, or as Ben Armstrong puts it in his blogpost“Run data recovery tools inside the virtual machine."” As with all things in IT “fast” is a relative term – restoring a 500 GB disk from backup can take hours. Plan accordingly.
If you are going to take the time to investigate the cause, or do not have a backup, then you must “go all forensic”.
No mater what the VHD type, most common causes of data corruption in the VHD (whether fixed or dynamic) are from:
- Data corruption due to faulty / failing physical storage
- Data corruption due to transferring files over faulty / failing networks
If you can trace back the chain of events leading to the corruption, you will usually find a failure either by disconnecting storage while the virtual drive was being created or moved over the network Note that switching the disk-type from one to the other or expanding the disk may cause the problem, and, for some people, it has solved the problem. Sometimes this failure is not hardware, but caused by 3rd party encryption and anti-virus programs that have been installed on the host.
Fixes to try:
- Mounting the vhd file to the parent partition, and then chkdsk to repair it. Ben Armstrong gives the method of mounting vhd files in his blog.
- Check for integrity using the Hyper-V. Add the vhd file to the IDE controller and then hit the Inspect button
- Merge any VHD and AVHD files. Check if you can open them through windows 7, server 2008 or WinImage (for Virtual PC and Virtual Server VHDs)
- This forum thread mentions a 3rd party $150 tool called MediaHeal if the disk is an older OS (WinXP,WinVista,Windows2000,Windows2003,WinServer,Windows Vista Ultimate,WinNT 4)..
- Try the free Microsoft vhdtool (http://archive.msdn.microsoft.com/vhdtool) that includes a"repair" function which is designed to undo an expand operation on a base VHD when differencing VHDs are present