Mastering Windows Server 2016 Hyper-V

(Romina) #1

unmounts can be useful. PowerShell provides an easy way to mount and unmount a
VHDX file:


Mount-VHD - Path D:\Virtuals\newdyn.vhdx
Dismount-VHD - Path D:\Virtuals\newdyn.vhdx


Throughout this chapter, I talk about VHDX, but many environments will have VHD
files from previous deployments; you might want to convert them to VHDX to gain
the new capabilities:


1. Using Hyper-V Manager, start the Edit Disk action, and select the source VHD file.
2. Under the action, select Convert, and then select the VHDX format.

This converts the VHD to a VHDX file. You also can do this via PowerShell:


Convert-VHD - Path d:\temp\source.vhd - DestinationPath
d:\temp\destination.vhdx


Note that any conversion process creates a new virtual hard disk file and copies the
content across, which means that you need sufficient free space to create the
temporary new file until the old file is deleted. It is also possible to convert a VHDX to
a VHD file by using the same process, provided the VHDX is less than 2 , 040 GB. The
Convert-VHD PowerShell cmdlet is also used to convert a VHD or VHDX to the new
VHD Set (VHDS) type by specifying the .vhds extension.


Dynamic VHDX files will grow as writes are performed, but they never shrink
automatically, even if large amounts of data are deleted. If you delete a large amount
of data from a dynamic VHDX file and want to reclaim the space on the physical disk,
you need to compact the VHDX file. This can be performed by using the Hyper-V
Manager Edit Disk action and selecting the Compact action. This can also be
performed using PowerShell:


Optimize-VHD - Path d:\temp\data 1 .vhdx


Optional parameters can be used with Optimize-VHD that tune the type of
optimization. These are fully explained at https://technet.microsoft.com/en-
us/library/hh 848458 .aspx. However, in most cases the default optimization mode of
Quick for a VHDX file will yield the desired result.


When a VHDX file is created, it can be created as a fixed or dynamic file. This can be
changed through the Edit Disk action or through PowerShell Convert-VHD, specifying
the - VHDType parameter as Fixed or Dynamic.


The size of a VHDX file can also be changed by using the same method, increasing the
available space or even shrinking it, provided there is sufficient unallocated space on
the disk inside the virtual machine. For example, if a VHDX file is 80 GB but the
virtual machine inside has allocated only 60 GB of storage, it would leave 20 GB
unallocated, as shown in Listing 4. 1 and Figure 4. 2. This would allow the VHDX file to
be shrunk by 20 GB. This can be confirmed when looking at the properties of a VHDX

Free download pdf