I keep seeing this item coming up in the forums over and over again.
For some reason I need to make the virtual disk of my VM larger (maybe I downloaded too many patches, maybe too many temp files, maybe too many log files).
The reason does not really matter.
So I open the Edit Disk wizard, I find the VHD and I Expand the virtual disk.
Excellent, now my VM has more space and I go into the operating system and diskpart and perform the actions that I need to for the OS to use the additional space.
This works all to well when all you have is a single VHD. One VHD, no snapshots, no differencing disks.
I have written about snapshots quite a bit over the past year.
A snapshot is a moment in time. The technology that Hyper-V uses to achieve this is a Differencing Disk.
The differencing disk is a child disk that is linked to its parent. The easiest way to describe the concept of the differencing disk is to think of overlays.
In the era of the small hard disk we used to think about sectors and blocks. But things have changed, and most folks don’t concern themselves with that anymore – a disk is a place for stuff and that place has a capacity and that is all we really concern ourselves with. It is the blocks and sectors that form the map that we need to be aware of. Think of it like a dart board, but wil ar more rings.
The root VHD is the map of a disk. A digital representation of a physical hard disk. It has blocks, sectors, etc.
The differencing disk is also a map just like its parent, however, it only contains the blocks and sectors of its parent that are different, than the parent.
To begin my analogy, I am going to think of the single VHD as a map or drawing.
Adding a differencing disk (taking a snapshot) is like laying a piece of tracing paper over a drawing, and only coloring in some features (the changes from the point the snapshot was made).
The drawing does not change, only the way the empty places are colored in.
If you add a second differencing disk (now a chain of three virtual disks – a grandparent VHD, a parent differencing disk – a child differencing disk). This lays a second piece of tracing paper over the drawing, and we proceed to change how the empty spaces are colored in.
What happens when you resize the VHD?
When you resize the VHD, the disk map or drawing, is changed. I have a different combination of sectors and blocks.
Now, the spaces that I colored in on my tracing paper (differencing disks) no longer aligns with the empty spaces in the drawing. The result is a really ugly picture.
The result with my VM is that I just broke the chain. And I broke it right at the root.
There is currently no method (that I know of) that will allow resizing of a virtual disk that contains snapshots – differencing disks.
If you need to resize the virtual disk of a VM and there are snapshots then the snapshots must be deleted (and the VM turned off, then wait patiently). This has the end effect of taking each piece of tracing paper and applying its colors onto the layer underneath. The term is called merging.
The layers of tracing paper are applied back to the primary drawing, the root VHD.
In the end, you have a single VHD that you can safely resize.
Is this the only way you can end up with a single VHD? No I can think of at least a couple more creative ways to end up with a single VHD for resizing.
The key is that you cannot resize a virtual disk with snapshots or differencing disks.
I hope that someone that is thinking about doing this finds this article in Google or Live Search and saves themselves some big recovery pain.