Chapter 4
IN THIS CHAPTER
Looking at disk formats
Identifying types of disks
Adding storage to the host
Adding storage to the virtual machine
After you build your virtual machine (VM) and your networking is set up, the next thing most system administrators will look at is storage for the application that’s going to be installed on the VM. There are multiple reasons for this:
This chapter discusses how to add storage to both the Hyper-V host and the VMs that reside on the Hyper-V host. Here, you learn about the different types of disks and the disk formats as well.
There are two disk formats to be aware of when you start talking about virtual disks: VHD and VHDX. Each format has pros and cons that you should consider before you decide which one you want to use:
There are four different types of disks used in Hyper-V: fixed, dynamic, differencing, and pass-through. Each has a use case that makes the most sense. When you try to create a disk, you may not see all these options in the menu to choose from.
VHDs in Hyper-V are created as a file that lives in a location that you determine. They may be located locally on your Hyper-V host, or they may be located on a shared volume on network storage.
A fixed disk is similar to your standard traditional hard drive. If you provision a 60GB hard drive, then the file for your VM will be a full 60GB. This disk choice offers the best performance, but it can lead to a lot of wasted space because it can’t be shrunk down after it’s created. Fixed disks are also referred to as thick provisioning.
A dynamic disk can save on space. You may have an application that says it requires 200GB for storage. If you provision a dynamic disk, the OS and the application will see a 200GB disk. The actual disk file will be much smaller — the size of the actual data. For instance, if you’re only using 30GB of a 200GB dynamic disk, then the size of the disk file will be 30GB. The performance is not as good as a fixed disk, and you have to be careful to not overprovision the storage available to the VMs on the Hyper-V host. Dynamic disks are also referred to as thin provisioning.
Differencing disks are different from your traditional VHD/VHDX disks. A differencing disk is a dynamic disk that is tied to a parent disk. The disk that is tied to the parent disk is known as a child disk. Child disks store changes that are made to the parent disks. This makes them excellent for troubleshooting but can make it easy to overprovision storage because they’re using dynamic disks.
Pass-through disks are not VHDs. These are physical drives that are attached to the Hyper-V host and then passed through to the VM. Using pass-through disks also allows you to take advantage of physical network storage that is connected to a Hyper-V host. This enables you to maximize the benefit you receive from an expensive physical storage array in your virtual environment. Plus, it can simplify backups and restores, because the data is stored in its native NTFS format.
Adding storage to a Hyper-V host is a common administrative task. The Hyper-V host is typically storing the VM configuration files and the VM’s disk files on local storage, unless you have it configured to save them on network storage of some kind.
Adding the storage to the Hyper-V host is similar to adding storage to any Windows 2019 Server. Let’s create two 50GB drives and add them to the host. Then I’ll show you how to change the default save location for the virtual hard disks and the VMs.
Before you can add the drives to the server for use, they must be installed. After they’ve been installed, you can go into Server Manager and initialize them.
Follow these steps:
Right-click the first disk that says Offline, and click Bring Online, as shown in Figure 4-1.
You get a dialog box warning about data loss if the disk is in use elsewhere.
At this point, your screen should look similar to Figure 4-2, with all three disks showing online and partitioned.
After you have the new storage added to the Hyper-V host, you can use it for all kinds of things. One of the most common reasons to add storage is to create save locations for the VMs and for the virtual disk files.
Follow these steps to change the default save locations for both VMs and virtual disks:
From Hyper-V Manager, right-click the Hyper-V host and choose Hyper-V Settings.
Virtual Hard Disks is selected by default, so let’s change that one first.
Click Select Folder.
The new location will appear in the box, as shown in Figure 4-3.
This does not change VMs that were previously created. They would need to be moved to the new locations via storage migration (see Chapter 5 of this minibook).
Adding storage to a VM is an everyday event for a system administrator. Sometimes you need to expand a virtual drive; other times, you need to add additional virtual drives.
With a Generation 1 VM, you're given a choice between a VHD- or VHDX-formatted drive. If you have a Generation 2 VM, you don’t have a choice — it can only be a VHDX-formatted drive — so you’re asked what type of drive you want to create rather than what format you want to use.
Because the wizards are a little different for the two generations of VMs, I’ve included the instructions for each.
With the Generation 1 VM, you need to make a decision as to what kind of disk you want to create. If you’re going to move the VM to Azure, you need to select the VHD format; otherwise, you can typically choose the VHDX format. Follow these steps:
Right-click the VM and click Settings.
You have an IDE controller and a SCSI controller. You can use either one. I’m going to use the IDE controller because my other hard drive is using it (this is for tidiness — you can mix and match controllers).
Select the IDE controller and choose Hard Drive and then click Add (see Figure 4-4).
The virtual hard disk button will be selected.
On the Choose Disk Format screen, choose the format you want and click Next.
I’ll select VHDX.
On the Configure Disk screen, select Create a New Blank Virtual Hard Disk and change the size to whatever you want; then click Next.
On the last page of the wizard, you’re given a summary of your selections.
The Generation 2 VM does not have the IDE controller as an option, so you’ll select the SCSI controller when you create this hard drive (unless you have a Fibre Channel Adapter). Follow these steps:
Select the SCSI controller, select Hard Drive, and click Add.
Virtual Hard Disk will be selected.
If you want to expand a VHDX file, you can do it while the VM is running. This is one of the great things about VHDX-formatted disks. If you’re using a VHD-formatted disk, you need to power down the VM to expand it. Follow these steps:
For the VM to see the pass-through disk, it must be offline on the host. If it isn’t offline, it won’t show up as an available disk. You can verify that there is an offline disk available for you by checking the Disks area of File and Storage Services in Server Manager, as shown in Figure 4-6.
After you’ve verified that you do have an available offline disk, open Hyper-V Manager and follow these steps:
Select SCSI controller and then Hard Drive, and then click Add.
Virtual Hard Disk is selected by default.
Select Physical Hard Disk, as shown in Figure 4-7.
If there is no hard drive listed, ensure that the disk shows offline on the Hyper-V host.
The day may come when you need to convert your VHD disk file to a VHDX disk file. You may have reached the 2TB limit, or maybe you want the improved resiliency against power outages. Or you may want to upgrade to a Generation 2 VM. Whatever the case, you can convert the file through the graphical user interface (GUI) or through PowerShell. In this section, I walk you through both methods.
When you do the conversion through the GUI, you start out in the VM Settings screen and you select the hard drive in question. Follow these steps:
Specify the name of the converted disk and click Next.
You can leave it the same — you just need to specify .vhdx
as the file extension.
The disk conversion through PowerShell is a simple command. The command is similar to the following:
Convert-VHD -Path E:\ConvertPS.vhd -DestinationPath E:\ConvertPS.vhdx
In Figure 4-8, you can see that I have the VHD file in my E:
drive. I run the preceding command, and then I have the VHDX file. That’s all there is to it.
The converted disk drive does not get attached automatically to the VM. You have to specify that you want the VM to use the VHDX file after the conversion is complete. This process is similar to creating a new hard drive, except instead of clicking New or Edit, you click Browse and select the VHDX file. After you select it and click OK, the converted VHDX file will then be attached to the VM.