VhdTool & “Save your bacon” – Extend base virtual machine while snapshots exist is bad JooJoo

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.

Problem resolved…

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.

image As many know, you can easily determined if snapshots exist for a virtual machine by looking at the Virtual Machine in Hyper-V manager (or under Manage Checkpoints for VMM) under snapshots.

image If you’ve caught yourself in a position where you’ve not paid attention to the warning and now are “stuck”, let’s talk about some goodness that exist in the world.

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 -

  1. Download VhdTool.exe from Codeplex (application, not source)
  2. Change to the directory you downloaded the tool to, and then execute vhdtool.exe /?

image 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!

Repairing VHDs

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:

  1. At the command-prompt, type:
 VhdTool.exe /repair {Name of Base VHD} {Name of Differencing Disk}

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!