I recently was privy to a situation whereby an individual (this person’s identity is concealed to protect the innocent) realized that a virtual machines dynamically expanding disk simply wasn’t large enough. This person realized this during some upgrades to key components running on the server and was quickly & swiftly maneuvering around the Hyper-V console when this innocent person quickly extended the base virtual disk.
Not so fast buddy…Extending VHDs with Snapshots
As this person quickly learned, there is a nice little warning that shares with you that modifying any virtual hard disk (vhd) while snapshots exist is simply a bad idea. I tried to warn the individual but it didn’t seem to help any as they continued on and too much of there dismay the warning is accurate.
VhdTool.exe & Repair Function
One day, this high-level Software Design Engineer, decided that he had had enough and was done with the chaos that is busted/corrupt VHDs because folks just didn’t heed to the warning. On this day, Chris Eck decided it was time to extend the functionality he had in his open-source tool called VhdTool.exe. This was the day a hero was born.
VhdTool.exe provides an IT administrator who has made that faithful mistake to set the VHDs in the chain (base + differencing) to the same size hence again allowing your VHD to become usable again.
To start off with VhdTool.exe, I would first suggest you utilize the help -
- Download VhdTool.exe from Codeplex (application, not source)
- Change to the directory you downloaded the tool to, and then execute vhdtool.exe /?
As you can see, VhdTool.exe isn’t designed to only help recover in the case of a poor decision to extend a chained VHD but also can be utilized to create, convert, or extend. For the purposes of our post today though I’m focusing on the /repair switch as this is what save my colleague!
To repair the VHD, it is literally very simple. In the case of my colleague, it actually happen almost instantaneously which was very surprising. To successfully modify the VHD disk size through /repair, do the following:
- At the command-prompt, type:
For the tool, you would utilize the ‘Base’ as being the parent disk in the chain. The differencing disk is identified by the unique ‘.avhd’ extension meaning it is a differencing disk ‘Based’ off the parent. In short, all changes are written to the differencing disk while the base disk is read-only.
After executing the tool, it will return the actual success or failure and tell you what the differences were between the base disk & the chain differencing disk -
Merging AVHD’s after the repair – Sweetness
In this individuals case, they weren’t as worried about the snapshot chain but instead were interested in getting everything merged to a single VHD so they could effectively extend the drive. After the repair process, it was rather simple to do a merge by using Hyper-V’s Edit Disk function and then move to extend it as was the original plan.
NOTE: If you are not interested in losing your snapshot chain, then do not do this step.
For information on merging, see the following article - http://blogs.msdn.com/robertvi/archive/2008/08/26/howto-recover-snapshots.aspx
If you’ve not already sent a 6-pack, or your favorite beef jerky or maybe even money to One Microsoft Way, Redmond, WA 98052 Attn: Chris Eck then this is the time to do it. The VhdTool tool is incredibly useful and very, very important to correcting a mistake made because Hyper-V doesn’t take the necessary action to seriously warn the user that they shouldn’t continue. Better yet, I like the idea of simply not allowing the modification of disks when they exist in a chain. We should file that right now against Windows 8. Enjoy!