John Joyner unveils the new VHDX format and shows how to easily reduce both the size and capacity of this file format in Windows Server 2012 Hyper-V.
If you are using the Hyper-V virtualization role in Windows Server 2012, you may have some virtual hard disks (VHDs) to manage. When new virtual machines (VMs) are created, they are assigned one or more VHDs of specific types and sizes, and which VHDs new VMs receive is usually associated with a VM template or gallery image. After deploying the standard image VM, it's frequently necessary to modify the VHD parameters over the lifecycle of the VM, for example, to increase the maximum size of one or more VHDs.
Working with VHDs is stress-free in Windows Server 2012 Hyper-V. Compared to previous releases of Hyper-V, Windows Server 2012 VHDs can be much bigger, are even safer, and have shrinkable size and capacity. Windows Server 2012 introduces a new VHD type, with the VHDX file extension, with easy and interchangeable support for the existing Windows Server 2008-format VHD file extension type. There is an option to shrink the capacity of a VHDX using the Windows Server 2012 user interface (UI), and you can also shrink the maximum capacity of VHDXs using PowerShell.
About the new VHDX file format
The ".VHDX" VHD file format specification provides a disk-in-a-file abstraction to improve on the original Hyper-V disk format, the ".VHD" file. The VHDX file container allows for information to be stored about the VHD content and state in metadata. There are some specific benefits that leverage the new file format:
- Larger: Support for virtual hard disk storage capacity of up to 64-TB using Windows Server 2012 VHDX format, along with full support for Windows Server 2008-style VHDs with a 2-TB capacity.
- Safer: Protection against data corruption during power failures by logging updates to the VHDX metadata structures in the file container.
- Shrinkable: Achieve higher storage efficiency when needed by trimming the physical size of dynamic VHDX files, as well as lowering the maximum capacity of VHDX-style VHDs.
Migration between VHD and VHDX file formatsIf you have upgraded from Windows Server 2008 Hyper-V and your VMs still have the older VHD format, it is simple to migrate to the newer VHDX format, and it is a reversible operation. Using the Hyper-V UI in Windows Server 2012, select to edit the VHD and choose to Convert to VHDX format as shown in Figure A. (The equivalent PowerShell command is Convert-VHD.)
Convert VHD format to new VHDX format using Windows Server 2012 Hyper-V MMC.
Converting to VHDX (or if you choose later, back to VHD from VHDX) is an offline process, that is, the VM needs to be shut down while disks are being converted. It's a safe process because the source VHD or VHDX remains as a fallback in case the conversion was unsuccessful. After switching out the disk configuration in the VM settings, and booting the VM on the converted disks successfully, you can delete the source VHD or VHDX file(s).
Reducing VHDX size and capacity
Shrinking both the physical size, and particularly reducing the logical maximum capacity of a VHD, was difficult in previous releases of Hyper-V. This resulted in a lot of overprovisioning when dynamically expanding VHDs were converted to fixed size VHDs — frequently to the default 127-GB size — even when they only contained a few GB of data. Windows Server 2012 helps when you need to shrink storage.After converting a dynamically expanding VHD to the VHDX format, a new Shrink menu option becomes available in the Hyper-V UI as shown in Figure B. VHDX format VHDs only expose the Shrink option when there is free space in the VHDX file to reclaim.
The Shrink option is available on Windows Server 2012 VHDX format files.To get an idea of how Shrink can work in your environment, consider this scenario: You want to trim the disk space consumed by dynamically expanding disk VHDX files, by reducing the maximum capacity of disk partitions in the files. Figure C demonstrates using Windows Server 2012 Disk Management UI to shrink the C: drive of the VM itself-in place-by 5-GB.
- Right-click on the volume in Disk Management and select Shrink Volume.
- Enter the amount of space to shrink and press the Shrink button.
Shrinking the C: drive from inside a Windows Server 2012 VM recovers free space for Hyper-V to reclaim.
Resizing VHDX capacity with PowerShell
Windows Server 2012 introduces Storage Cmdlets in Windows PowerShell to allow you to automate and script work on VHD and VHDX files. The resize-partition and resize-vhd PowerShell cmdlets can be used as shown in the following four lines of PowerShell to change the capacity of a VHDX format disk, in this example from 50-GB to 35-GB.Note: The first PowerShell cmdlet (mount-vhd) confirms (in its screen output) the drive letter that the partition you want to trim is mounted to. In this example the E: drive is the mapped VHDX volume for the actual C: drive of the active partition inside the VHDX. (Thanks to Ben Armstrong for this procedure.)
PS C:\Windows\system32> mount-vhd \\FS01\vmdata\AS02_C.vhdx -passthru | get-disk | get-partition | get-volume
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining Size
—————- ———————- ————— ————- —————— ——————- ——
E NTFS Fixed Healthy 32.27 GB 51.66 GB
D System Reserved NTFS Fixed Healthy 108.7 MB 350 MB
PS C:\Windows\system32> resize-partition -driveletter E -size 35GB
PS C:\Windows\system32> dismount-vhd \\FS01\vmdata\AS02_C.vhdx
PS C:\Windows\system32> resize-vhd \\FS01\vmdata\AS02_C.vhdx -ToMinimumSize
Feature guide: Windows Server 2012 Hyper-V vs. Windows Server 2008 R2 Hyper-V
Microsoft has an interesting and comprehensive white paper to download at this link that lists all the new Windows Server 2012 Hyper-V features; for example in the storage category, there is now fiber channel guest clustering: