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.
This Core Team blog post shows one way to begin your analysis.
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 (https://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
Comments
- Anonymous
December 08, 2011
Thanks for posting this fix. I encountered the exact same error when expanding the size of the .vhd file and I was concerned that I would have to rebuild the VM from scratch. Does anyone know if this problem was address in Windows 2008 R2 edition? http://blogs.technet.com helped me always for hyper-v issue and another big source of hyperv i found very helpful http://www.hypervhd.com