Hyper-V VHD The File Or Directory is Corrupted and Unreadable
Here I will go through a number of ways that you can possibly repair the dreaded corrupt Hyper V VHD if you have not got the option of restoring from backup or you do not actually backup ( if you don’t have a product I recommend Unitrends Hyper V Backup ), symptoms may include the Hyper V virtual machine will not boot and when you try and attach the VHD you receive the error below.
Failed to open attachment Error: 'The file or directory is corrupted and unreadable
How Can I Fix A Corrupt VHD
Checking The Integrity Of A VHD
Sometimes the most simple of fixes are the best, we can run a script in powershell that allows us to mount the VHD in a the root folder this will enable us to run a CHKDSK on it. Run the power shell commands below changing your details
#First we choose what VHD we want mounted $VHDName = "V:\serverx.vhd" #Get the MSVM_ImageManagementService $VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "." #Now we mount the VHD $Result = $VHDService.Mount($VHDName)
We can now run a CHKDSK on this VHD.
Compacting The Corrupt VHD
Another method is to create a new VM and add the corrupt VHD but we then compact the VHD as below.
First create the new Virtual Server and add a new hard disk, then select settings and the hard disk you have created, then browse to the VHD that will not load. Select the Virtual Disk Wizard, then select compact and make sure you select Convert it to a fixed-size virtual hard disk, if you have a VHD that was 50gig it will compact the drive to the size the the amount of data that is on the VHD, so if you have 10 gig of files then the VHD will be compacted to 10 gig. You will get the option to save the new VHD as a new one so make sure you give it a different name in case you need to go back to the corrupt VHD.
Once compacted copy the VHD back to the original server and try and mount it.
Use Microsoft’s VHD Tool
This VHD Tool from Microsoft has the option to repair a VHD, first download the vhdtool here direct from Techieshelp then run the following command to attempt to repair the VHD.
(as always make sure you have a backup of the VHD before starting this process.
VhdTool.exe /repair <BaseVhdFileName> <FirstSnapshotAVhdFileName> [/quiet]
If you have an other methods then please comment below.
Greetings Allen! I know this is an old post but do you think you could upload the vhdtool file (it’s only supposed to be 57k) to a hosted file collaboration site (yousendit, megaupload, etc)? Microsoft took down access to the file from their website and it’s almost impossible to find that executable anywhere with the inordinate amount of google searches I did. Thanks so much in advance!
Hi Stacey, article updated and the tool can be downloaded here now 🙂
I recently had a RAID 5 disk failure and when I fixed the offending disk, my .vhdx was corrupted. I’ve tried many things and am becoming very frustrated with not being able to fix this yet.
I am running Server 2012 R2
I can move the file to another directory, disk, etc…
I cannot mount the .vhdx (unless it is in read only mode)
I tried the PS script in this post which errors out.
I cannot figure out how to compact the VHD (doesn’t seem like an option anymore)
I downloaded and ran the VHD Repair Tool from MS, but there is not an /repair option if you use /? and even if I try it anyway it comes back with the help file.
Please don’t tell me all hope is lost….
Any suggestions or other tricks?