Thursday, July 16, 2015

Windows Server 2012 R2 - Hyper-V - a look at VHD features (Part 2)

Now that we have created a virtual disk and created a virtual machine (please see my previous blog post), I will examine some aspects of virtual disk management.

First of all, how can I view the characteristics of a virtual hard disk (or "VHD")? This will be very useful later in the post when we attempt to resize a disk and want to verify the results. We can view the properties of a VHD with the "Inspect" option. We open Hyper-V Manager, open the properties of the virtual machine (Svr5 in this case), highlight the virtual disk (or hard drive) that interests us and finally, in the right pane, click on "Inspect":

We can now see (above) the format, type, location, name and size of our virtual disk.

We can also select the "Inspect Disk" option at the host level. It would then be necessary to locate the virtual disk in question:

Here is where we locate it:

At this time, my virtual machine is running (it's "live") and apparently that does not leave me with many configuration options:

At most, we can expand the virtual disk:

For example, we could increase the size to 56 GB (which I will not actually do at this point):

Note: this is with a "Fixed Size" disk and with a live operating system. In the following lines, we will have a look at other combinations.

Now I will turn the virtual machine (VM) off, repeat the process above and see if we have more options:

Well, now it looks like I can convert the virtual disk to another type or another format.

Important: read the description in the screenshot above carefully. Print too small? You can click on the image to enlarge.

When we convert a VHD, Hyper-V does not adjust a parameter in the virtual disk properties that changes its nature. Instead, Hyper-V will copy the entire contents comprising the virtual disk and essentially create a new copy with (possibly) different parameters. This means that we must have sufficient space on the physical media where we are storing the VHD files.

I'll select the "Expand" option and we'll increase the size of the disk to 60 GB:

The virtual disk size is increased:

Now if we look at our options again, we see that there is now a third option: Shrink

Note that, while we can indeed shrink the virtual disk, we cannot shrink it to less than its original size (in this case, 48 GB):

So, to summarize our experiments so far, we can both expand and shrink a fixed disk when it is offline (when the OS installed on it is not running). However, while we can shrink a virtual disk that was expanded, we cannot shrink to less than its original size.


Next I will convert the virtual disk from fixed size to dynamically expanding.

I could convert the disk format from VHDX to VHD but there is no reason to do so (unless I have to use the VHD with a legacy version of Hyper-V, that is, before Windows 2012). So I will keep the VHDX format...

As for the type, I will convert it from fixed size to dynamically expanding:

Conversion implies the creation of a brand new disk so we need to select a location for the converted disk with sufficient space for the file:

This is the summary of the operation:

Note the advantage in storage use below. The original 48 GB disk consumed an equal amount of space on the E: drive while the converted dynamically expanding drive only consumes about 9 GB of space on the F: drive, roughly the size of a fresh Windows 2012 installation (before updates or addition of roles and features):

Now I will attempt a compact operation. As we add programs and files to the expanding disk it will increase in size. If I later delete these programs and files, the disk will not automatically decrease in size. However, I can compact the virtual disk so it reverts back to its original size. For this demonstration, I will start with a virtual disk that consumes 8.85 GB:

After adding files, the size of the disk increases to almost 11 GB:

Here is another perspective:

Now I will delete the files.

In the properties of the C: drive, we see that the amount of used space has decreased to its original size (more or less):

However, the size of the virtual disk does not decrease at all:

Now let's try to compact the virtual disk while the disk is in use:

This is not possible (at least not on the virtual disk with the operating system):

Now I will turn off the virtual machine and attempt the operation again. This time, I am able to compact the virtual disk:

Likewise, we cannot convert a virtual disk when the virtual machine is running (the option does not appear):

But if we turn off the virtual machine, the option does appear:



By far, I have not tested all the features and options of virtual disk technology in Hyper-V. For example, I have not examined in this blog post differencing disks and checkpoints. On the other hand, I can draw the following conclusions:

  • We can resize a virtual disk (expand or shrink) if it is in the VHDX format.
  • It can be a fixed disk or a dynamically expanding disk.
  • However, the virtual disk must be offline.
  • We may not be able to shrink the virtual disk below its initial size (in my case, the size of the fixed disk before it was converted to dynamically expanding).
  • We can compact a virtual disk of the dynamically expanding type if it is in the VHDX format and offline.

No comments:

Post a Comment