Fixing a corrupt VHD file

Error message – Failed to open attachment ‘C:\ vhddir \MyVHD.vhd’. Error: ‘The file or directory is corrupted and unreadable.’”

There could be many possible causes why your VHD may become corrupted. More often administrators tend to restore the backup from the snapshot catalog. This is to ensure uptime guarantee. However if we have enough time or in the event of not having a snapshot backup our options are very limited. Below are a few fixes that can be tried to repair the corrupt VHD file.

Main causes of data corruption irrespective of a VHD being fixed or dynamic are

  • A faulty or a failing physical storage
  • Data corruption when files are transferred over faulty or failing networks

Tracing the chain of events that led to corruption

  • Failure by disconnecting storage while the virtual drive was being created or moved over the network
  • Switching the disk-type from one to the other or expanding the disk may sometime trigger the problem

Fixes to try

  • Mounting the vhd file to the parent partition, and then run chkdsk to repair it.
  • 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 it can be opened through windows 7, server 2008 or WinImage (for Virtual PC and Virtual Server VHDs)
  • Finally we can try the free Microsoft vhdtool that includes a “repair” function which is designed to undo an expand operation on a base VHD when differencing VHDs are present