Quick Bites:
VHD and VHDX are both virtual hard disk file formats used by Microsoft’s virtualization solutions, such as Hyper-V and Virtual PC (retired in 2011).
- This blog discusses optimizing and resizing Hyper-V VHDX virtual disk files, highlighting the advantages of using the VHDX format over VHD, such as improved logging, automatic disk alignment and dynamic resizing
- It provides detailed steps for optimizing VHDX files using the optimize-vhd PowerShell cmdlet and explains how to resize VHDX files on running virtual machines with the resize-vhd cmdlet
- The blog emphasizes the enhanced scalability, efficiency, and performance benefits of VHDX in Hyper-V environments
Note:
- VHD (Virtual Hard Disk) is the older format and was introduced with Microsoft Virtual PC. It has a maximum size limit of 2TB and supports both dynamic and fixed disk types
- VHDX (Hyper-V Virtual Hard Disk) is the newer and improved format introduced with Windows Server 2012 and Windows 8. It offers improved performance, larger maximum size limit of 64TB, and a more resilient architecture than VHD. VHDX also supports both dynamic and fixed disk types, and includes other features like larger block sizes, improved alignment of the virtual hard disk, and protection against power failures
In general, if you’re using a newer version of Windows and Hyper-V, it’s recommended to use VHDX instead of VHD due to its improved features and performance.
There are various tasks that a Hyper-V administrator can perform to keep a Windows Server Hyper-V environment running optimally. One task that comes with maintaining and optimizing a Hyper-V environment is making sure the actual virtual disks themselves are running optimally and are efficiently sized. With later generations of Hyper-V, the new VHDX virtual disk format provides some really great new functionality from this perspective. The VHDX file format improves upon the legacy VHD virtual disk file format to incorporate powerful functionality and features that allow Hyper-V virtual environments to be much more efficient, error-free, and scalable than in previous generations.
Table of Contents
- Why Use Hyper-V VHDX File format?
- Optimizing VHDX Virtual Disk Files
- Resizing Hyper-V VHDX Virtual Disk Files
- How to expand vhdx disk or shrink vhdx disk size ?
- Concluding Thoughts
In this post, we will take a look at optimizing and resizing Hyper-V VHDX Disk as well as the features and functionality gained by using the VHDX file format, including the optimization capabilities.
Why Use Hyper-V VHDX File format?
To begin with, let’s take a step back and look at basic features that VHDX provides and why Hyper-V administrators would choose to use the newer VHDX file format as opposed to the VHD virtual disk.
The VHDX virtual disk file format was introduced with Windows Server 2012 and provides a much more powerful virtual disk format that helps to solve some of the scalability and performance constraints that exist with the VHD file format.
What are the new configuration maximums for the VHDX file format?
- Supports 64 TB virtual hard disk size
- Improved logging mechanisms in VHDX
- Automatic disk alignment
- Dynamic resizing
- Virtual disk sharing
New disk sizes
The 64 TB virtual hard disk size certainly opens up some pretty interesting use cases. However, for most, there will be no disk that will not fall within the boundaries of this new disk size and most will not even come close to this new configuration maximum. This also will negate the need to perform pass-through storage provisioning if this was necessary for size reasons.
Improved Logging
With the improved logging features that are contained within the VHDX virtual disk metadata, the VHDX virtual disk is further protected from the corruption that could happen due to unexpected power failure or power loss. This also opens up the possibility to store custom metadata about a file. Users may want to capture notes about the specific VHDX file such as the operating system contained or patches that have been applied.
Automatic Disk Alignment
Aligning the virtual hard disk format to the disk sector size provides performance improvements. VHDX files automatically align to the physical disk structure. VHDX files also leverage larger block sizes for both the dynamic and differencing disk formats. This greatly improves the performance of dynamic-sized VHDX files, making the difference in performance negligible between fixed and dynamic. The dynamic sizing option is the option that is preferred when creating VHDX files.
Shared VHDX
There is a new option starting in Windows Server 2012 to share virtual VHDX hard disks between virtual machines.
Why would you do this?
Guest clustering is an interesting option to run a clustered Windows Server configuration on top of a physical Hyper-V cluster to allow application high availability on top of virtual machine high availability. If a virtual machine fails, you still suffer the downtime it takes to restart the virtual machine on another Hyper-V host. When running a cluster inside a Hyper-V cluster, when one virtual machine fails, the second VM in the cluster assumes the role of servicing the application. A shared VHDX allows utilizing a VHDX virtual disk as a shared cluster disk between guest cluster nodes.
Optimizing VHDX Virtual Disk Files
Optimizing VHDX Virtual Disk Files allows optimizing the space in a dynamic sized virtual hard disk file. This is accomplished with the optimize-vhd cmdlet. The Compact operation is used to optimize the files. This option reclaims unused blocks and rearranges the blocks to be more efficiently packed which reduces the overall size of the VHDX virtual hard disk file.
The optimize-vhd operation can only be performed with the virtual hard disk detached or attached in read-only mode if the virtual machine is running.
If the disk is not attached properly for the operation specified or in use, you will see the following:
PowerShell options available with the optimize-vhd cmdlet:
- Optimize-vhd -Path
-Mode Full – This option runs the compact operation in Full mode which scans for zero blocks and reclaims unused blocks. This is only allowed if the virtual hard disk is mounted in read-only mode. - Optimize-vhd -Path
-Mode Pretrimmed – Performs the same as Quick mode but does not require the hard disk to be mounted in read-only mode. - Optimize-vhd -Path
-Mode Quick – The virtual hard disk is mounted in read-only and reclaims unused blocks but does not scan for zero blocks. - Optimize-vhd -Path
-Mode Retrim – Sends retrims without scanning for zero blocks or reclaiming unused blocks. - Optimize-vhd -Path
-Mode Prezeroed – performs as Quick mode but does not require the virtual disk to be read-only. The unused space detection will be less effective than the read-only scan. This is useful if it has been run to zero all the free space on the virtual disk as this mode then can reclaim the space for subsequent block allocations.
Resizing Hyper-V VHDX Virtual Disk Files
Starting with Windows Server 2012 R2, you can now perform a resize operation on a virtual hard disk of a running virtual machine in Hyper-V. This was not possible with previous versions of Hyper-V as the virtual machine had to be powered off. The new functionality is called dynamic resize which allows increasing and decreasing the size of a file while virtual machines are running which has opened up a good deal of possibilities for organizations to do maintenance operations while production virtual machines are running.
What are the requirements to resize VHDX files?
- Must be VHDX, this is not available for VHD files
- Must be attached to SCSI controller
This can be done via the GUI with Hyper-V manager or using PowerShell.
How to expand vhdx disk or shrink vhdx disk size ?
Choose the Edit option for the virtual disk file and then you can choose to Expand, Shrink, or Compact.
With PowerShell, you run the Resize-vhd cmdlet to resize. You can easily see the information regarding the virtual hard disk with the get-vhd cmdlet.
Below we are using the resize-vhd cmdlet to resize the file to the minimum size. You can see the file size has indeed changed when comparing the above cmdlet return for information compared to the below-returned file size information. The minimum size parameter will Shrink VHDX to the smallest possible size. Again, this can be done while the virtual machine is powered on.
Concluding Thoughts
With the newer version of Microsoft Hyper-V, there are quite a few new capabilities in regards to virtual hard disks that Hyper-V administrators to take advantage of. With VHDX virtual hard disks, there are new capabilities in regards to both optimizing and resizing the virtual hard disk. Dynamic virtual hard disks are the preferred configuration since there is no performance penalty with VHDX, reclaiming free space and blocks is a process that Hyper-V administrators can add to the list of tasks they can perform to optimize their Hyper-V environments and reclaim space.
Additionally, with the new ability to expand or shrink VHDX files on running virtual machines, either growing or shrinking them, administrators have the ability to reclaim space or add space on the fly without a maintenance period. All of these new features and capabilities allow Microsoft Windows Server Hyper-V environments to be even more powerful, scalable, and efficient for running production workloads.
FAQ
1.What is a VHDX file in Hyper-V?
In Hyper-V, a VHDX file is a type of virtual hard disk file format that stores the contents of a virtual machine’s (VM’s) hard drive.VHDX is designed to prevent data corruption during unexpected power outages, making it more reliable for critical workloads.
2.Can you optimize the performance of a VHDX file?
Yes, you can optimize VHDX file performance by choosing a fixed disk type, enabling Trim and Unmap to manage unused space, and using larger block sizes for sequential workloads. Placing VHDX files on high-speed storage (like SSDs) and monitoring IOPS also helps enhance performance. Additionally, defragmenting the host disk (for HDDs) reduces fragmentation, improving access times.
3.What precautions should I take when resizing a VHDX file?
- Backup Data: Always create a backup of the VHDX file to prevent data loss in case something goes wrong during resizing
- Shut Down the VM: Ensure the virtual machine using the VHDX file is powered off to prevent data corruption
- Check Available Space: Verify that there is enough storage on the host to accommodate the new VHDX size
- Use Hyper-V Manager: Use Hyper-V Manager or PowerShell for resizing, as these tools ensure compatibility and data safety
- Expand Partitions in Guest OS: After increasing the size, expand the disk partition within the guest OS to utilize the new space
4.How do I convert a VHDX to VHD in Hyper-V?
Following are the steps to convefrt VHDX to VHD
- Open Hyper-V Manager: Launch Hyper-V Manager on your host machine
- Select the Disk: In the Actions pane, click on Edit Disk. This will open the Edit Virtual Disk Wizard
- Locate the VHDX File: Browse and select the VHDX file you want to convert
- Choose Conversion Type: In the wizard, select the Convert option and click Next
- Select Destination Format: Choose VHD as the format you want to convert to, and decide whether you want a fixed-size or dynamically expanding disk
- Specify Destination Path: Specify the location where you want to save the converted VHD file and click Next
- Complete the Conversion: Review the settings, then click Finish to start the conversion process
Begin an Extraordinary Journey: Experience the Ultimate Hyper-V Backup Solution!
Strengthen your critical data with the secure and seamless magic of Hyper-V backup, forming an impregnable fortress of protection. Unlock the full potential of your virtual world, safeguarding your invaluable information with unwavering confidence. This exciting opportunity awaits — step into a realm of endless possibilities and ensure the safety of your data with a free trial today!
Are you ready to embark on this captivating journey? Download BDRSuite now and take the first step towards securing your Hyper-V environment. Embrace tranquility and immerse yourself in the realm of unparalleled Hyper-V backup excellence.
Curious to explore further? Discover the secrets of Hyper-V backup with BDRSuite and unleash the power of seamless data protection!
Related Posts:
How to convert VHD to VHDX Disks with Hyper-V
Beginners’ Guide for Microsoft Hyper-V: VHD vs VHDX Vs AVHD/AVHDX: Overview of Virtual Disk Formats – Part 22
Convert VHD to VHDX using Hyper-V Manager and Powershell
Beginners’ Guide for Microsoft Hyper-V: Hyper-V AVHDX Files – Part-56
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.