Show
The release of Windows Server 2012 was warmly welcomed due to the introduction of multiple virtualization features, including the new VHDX file format. VHDX is essentially the successor of VHD, but with more advanced capabilities. However, you can still create and manage VHD files in your Hyper-V environment. Let’s explore how Hyper-V VHD and VHDX files differ, what benefits they provide, and how they can be used. About Hyper-V VHD and VHDX FilesVirtual disks created in the Hyper-V environment can be stored as files in VHD or VHDX format located on a physical disk. Virtual hard disks are an alternative to physical hard drives; they function as the hard disks of a virtual machine (VM). Virtual disks can contain a native file system, disk partitions, sectors, and folders. They can conduct standard disk and file operations. Each VM is required to have at least one virtual hard disk that can be used as a storage for VM data. Earlier Windows versions supported only a single file format for virtual disks – VHD. As a result of growing technological demands, Windows 2012 introduced the VHDX file format, which has considerably improved storage capacity, enhanced performance on large-sector disks, and ensured higher levels of data protection. Both Hyper-V VHD and VHDX files can be of different types:
Differences Between Hyper-V VHD and VHDX FilesTo better understand how Hyper-V VHD and VHDX files function, let’s explore how the file formats differ. In turn, this tells us how each of them can improve the performance of the virtual disks. The following table contrasts the two formats:
As you can see, the new Hyper-V VHDX file format includes several features that have significantly improved its utility. For example, trimming allows you to identify data blocks that are no longer used and can be deleted, which enhances storage optimization and improves overall performance. Another feature that was introduced with the new Hyper-V VHDX file format is Shared VHDX, which allows VMs on the same guest cluster to use a VHDX file as a shared storage. Moreover, Hyper VHDX files allow you to resize (shrink or expand) virtual disks on demand, while the VM is still running, which considerably saves time and reduces overhead. Finally, due to enhanced data alignment, Hyper-V VHDX files can considerably improve I/O operations. By contrast, large-sector physical disks are prone to performance degradation. Even though VHDX is a more advanced version of the VHD format, there are still some cases where the use of VHD is preferable. For example, Hyper-V VHDX files are not compatible with the earlier versions of Windows Server. Therefore, if you are running virtual environments with mixed guest OSes and you need to move VMs between different hosts, the VHD file format would be the optimal choice, as it is supported by more OSes. How to Work with Hyper-V VHD and VHDX Files in PowerShellNow that you know what Hyper-V VHD and VHDX files are and what benefits they can provide, you are ready to create and configure your virtual hard disks. For this purpose, you can use Hyper-V Manager or PowerShell in Administrator mode. In this blog post, we describe how to manage Hyper-V VHD and VHDX file operations in PowerShell. This is the best approach, as PowerShell provides more options for configuring Hyper-V VHD and VHDX files. You can create, convert, merge, or remove disks quickly and easily by running PowerShell scripts. Create Hyper-V VHD and VHDX filesTo create a new virtual hard disk in the VHD or VHDX format, open PowerShell as an Administrator and run the New-VHD cmdlet. The following example shows you how to create a virtual hard disk of the dynamic type at the specified path, with the size of 10 GB, a block size of 128 MB, and a logical sector size of 4 KB. Note that it is the file extension (.vhd or .vhdx) that determines the file format; in this case, a VHDX file is being created.
The virtual hard disk is now created and the following information about the virtual disk is displayed in the PowerShell window. Add Hyper-V VHD and VHDX filesWith the Add-VMHardDiskDrive cmdlet, you can add a virtual hard disk to a specific VM. In the following example, the virtual hard disk DemoDisk.vhdx at the specified path gets attached to the VM named DemoVM. The SCSI controller, the controller number 0, and the controller location 1 are also assigned to the virtual disk.
Remove Hyper-V VHD and VHDX filesThe Remove-VMHardDiskDrive command is used to delete a virtual hard disk from a VM. To demonstrate how this cmdlet works, here is how to delete the disk created just above:
Using these cmdlets, you can easily create and delete virtual disks with the required parameters and attach them to specific VMs. Convert Hyper-V VHD and VHDX filesAs mentioned above, VHDX files offer a host of benefits over their VHD predecessors. Thus, in many cases, it is advisable to convert all VHD files to VHDX format. To upgrade Hyper-V VHD files to VHDX, simply run the Convert-VHD cmdlet, which lets you change the file format while saving the content of the source virtual hard disk. The data of the source virtual hard disk is copied to a new disk of the required format. The operation should be performed offline; it is recommended to detach the virtual hard disk. The example below demonstrates the cmdlet that allows conversion of Hyper-V VHD files to VHDX:
Recall, however, that VHDX files are only compatible with Windows Server 2012 and later. Thus, you might need to convert Hyper-V VHDX files to VHD. In this case, the same Convert-VHD cmdlet can be used, just in reverse. Remember that the virtual hard disk must be detached before conducting the operation.
Merge Hyper-V VHD and VHDX filesAs mentioned above, differencing disks are used to store and revert the changes made to another VHD or a guest OS. Each differencing disk tracks and stores the changes made to one associated virtual disk. In this case, the differencing disk is referred to as a “child disk” and the virtual hard disk is called a “parent disk”. With the Merge-VHD cmdlet, you can merge the changes stored in a differencing disk into the parent disk or into another child disk in the differencing disk chain. Note that this operation is performed offline; ensure that the disk chain is detached. To merge the child virtual hard disk to the parent virtual hard disk, run the following cmdlet. Note that once the operation is complete and the contents of the child disk are transferred into the parent, the differencing disk is destroyed.
In the following example, we have a parent disk, maindisk.vhdx, and a child disk, ChDisk1.vhdx, which itself has a child: ChDisk2.vhdx. The latter virtual disk even has its own child, ChDisk3.vhdx. Together, these disks constitute the differencing chain. The following cmdlet can be used to merge the child virtual hard disks in the disk chain.
Through this operation, the data from ChDisk3.vhdx and ChDisk2.vhdx is merged into ChDisk1.vhdx. The PowerShell script simplifies the process of merging virtual hard disks; the whole operation can be conducted in one run, no matter the size of the differencing chain. This is an advantage of Powershell – with Hyper-V Manager, you are not permitted to merge multiple layers of the differencing disk chain at once. You would have to merge each layer of the differencing disk chain manually, and these extra steps would cost you time and effort. Mount Hyper-V VHD and VHDX filesThe Mount-VHD cmdlet allows you to mount one or more virtual hard disks. The following example demonstrates how to mount a virtual hard disk with the path C:\Virtual Disks\DemoDisk.vhdx.
Using PowerShell scripts, you can mount a virtual hard disk in read-only mode:
Dismount Hyper-V VHD and VHDX filesIf you want to dismount a virtual hard disk, run the Dismount-VHD cmdlet in PowerShell. In the example below, you can see how to dismount the virtual hard disk with the path C:\Virtual Disks\DemoDisk.vhdx.
Another option is to dismount the virtual hard disk using the disk number of the mounted disk, as follows:
Resize Hyper-V VHD and VHDX filesIf you want to resize (shrink or expand) a virtual hard disk, the Resize-VHD cmdlet should be used. The following example demonstrates how to resize a virtual hard disk by assigning it a new specified size. In this case, we have expanded the VHDX from 10GB to 20GB:
However, shrinking is only available for VHDX files. Note that the virtual hard disk should not be shrunk to a size that is smaller than its specified minimum size. To see the minimum size of the virtual hard disk, run the following cmdlet:
You can use the following command to shrink the VHDX file to its minimum size:
ConclusionBoth Hyper-V VHD and VHDX files play a significant role in virtual environments as they function as as the hard disks of a VM. The VHD file format was used for a long time, but to keep up with the constant progress of virtualization technology, Microsoft introduced a more advanced version. Thus, the VHDX file format was released with Window Server 2012 to improve the performance of large-sector physical disks, enhance storage capacity, and ensure data protection. After comparing all the features that Hyper-V VHD and VHDX files provide, it is safe to say that Hyper-V VHDX is a more efficient and reliable file format built to handle performance demands of modern virtual environments. Make sure you protect your VHD and VHDX disks with a data protection solution tailored for virtualized infrastructure. Consider NAKIVO Backup & Replication which is a fast and cost-effective solution that provides multiple options for securing Hyper-V, VMware, AWS EC2 and Microsoft 365 environments. |