When we run out of disk space on a physical hard drive, our options are limited. We can replace that drive with something bigger, but then need to worry about moving all of the data over successfully. If we are running some sort of RAID or Storage Spaces, then perhaps we could add a new drive to the array of disks, but that is only possible if we have set up the correct infrastructure to support this in the first place. Thankfully, when working with virtual machines that are running on virtual hard disks, we add a little bit more fluidity to our drive management capabilities. After all, these virtual hard disks are just files, right? So it makes sense that they are a little bit easier to manipulate than a mechanical disk with physical limitations. In this recipe, we are going to explore the options available to us inside the Edit Virtual Hard Disk Wizard. This wizard will allow us to choose a virtual hard disk, and then do one of three things with it. We can compact the disk, expand the disk, or we can convert the disk to a different type.
Getting ready
Our work will be accomplished from inside Hyper-V Manager on a Hyper-V server running in the network. You do not even need a virtual machine inside Hyper-V Manager, as the disk management functions can be performed against any VHD or VHDX file - whether or not they are assigned to a VM.
How to do it…
Here are the steps needed in order to edit your virtual hard disks:
Inside Hyper-V Manager, take a look at the right side of your screen. Inside the Actions pane, click on Edit Disk...
Click Next, and then browse to the location of the VHD or VHDX file that you want to manipulate.
Tip
As you can see in the warning presented on this screen, certain types of virtual disks could be negatively affected by editing. Make sure you are not trying to edit a disk in one of those three conditions.
Next we need to choose the Action that we want to perform against this virtual disk.
Compact is pretty self-explanatory; it will renegotiate free space within the disk and compact it to be as small as possible. There are no additional screens you need to run through on this; you simply click Finish.
Expand is also fairly straightforward. Type in a new maximum size for your virtual hard disk, and the file will be expanded to accommodate the larger threshold. This is the most common reason to visit the Edit Virtual Hard Disk Wizard.
Convert is the option we are going to choose in this recipe, because it gives us the opportunity to discuss the different types of virtual disks. After choosing Convert and clicking Next, you will be asked whether you want this file to be a VHD or a VHDX. The only reason you would choose a VHD is when you are going to implement an operating system on the virtual machine that doesn't support running on a VHDX disk, such as Windows Server 2008 R2 or earlier. Otherwise, you will always choose VHDX here.
Now we choose what type of virtual hard disk to convert to. When you allow the virtual machine creation wizard to set up a new disk for you, it always chooses Dynamically expanding. This is most often what is desired by admins, because the VHDX file will start off very small, and it will only grow as it needs to. This keeps physical disk space utilization at a minimum. However, just like with dynamically expanding RAM, it takes resources in order to adjust a hard drive size on the fly. So if you are aiming for a VM that is super-efficient, it will be in your best interests to set that VHDX file to Fixed size. Doing so will cause the VHDX file to consume the entire amount of disk space as soon as the disk is created or converted, which takes a toll on the amount of physical space you have available, but it is faster and more useful for workloads that require high disk performance.
The VHDX file I am currently editing was configured by the wizard, and so it is currently Dynamically expanding. I am going to change it to Fixed size, and on the next screen tell it where to store my new VHDX file. This is necessary because, whenever you convert a virtual disk from one type to another, Hyper-V is actually going to create a brand new VHDX file and then copy the entire drive over to the new one.
How it works…
Editing your virtual disks won't often be necessary, as long as you plan carefully for disk sizes and types during the VM creation process. However, you may come into a Hyper-V environment that was established before your time with a company, and now be tasked with cleaning up and making that Hyper-V server more efficient. Adjusting disk sizes and types can be part of that overall goal to improve the health of your Hyper-V servers.