
When you create a new virtual machine in Hyper-V Manager, the virtual hard disk is either the size you specify or the default 127GB. However, not all VMs require the allocated storage space. By default, Hyper-V creates dynamically expanding disks, meaning a 90GB disk won’t immediately consume 90GB of physical storage. Still, you may later decide to shrink the virtual disk to prevent it from growing beyond a certain size. In this article, we’ll walk through how to Shrink and Compact Virtual Hard Disks in Hyper-V. Please see Enable or disable Microsoft Edge from showing Web Content.
Microsoft introduced the VHDX virtual disk format with Windows Server 2012. This offered enhanced performance, increased protection against data corruption, support for disk sizes up to 64TB, and improved alignment for dynamic and differencing disks, ensuring better compatibility with large sector disks and more reliable metadata logging to prevent corruption during power failures.
Before proceeding with these steps or performing these operations, it is recommended to back up your Hyper-V VMs in case something goes wrong and results in data loss.
Also, see how to deploy Azure Virtual Desktop in Azure Portal, How to create a dual-boot setup on Windows 11, and “Analyse Disks with Treesize: Defragment and Shrink VMware Workstation VM Disks“.
Prerequiste to Volume Shrinking: Run sDelete
Prior to shrinking a volume, I will urge you to download and install SDelete, a secure delete utility from Sysinternals. SDelete effectively zeroes out previously used storage blocks, ensuring that free space can be reclaimed efficiently.
Note: While running SDelete isn’t mandatory, many users have reported significantly better results when using it to zero out empty blocks before shrinking the volume. I can also attest to this after running sDelete in my VM. This process helps the hypervisor recognize unused space, maximizing the reduction in virtual disk size
SDelete (Secure Delete) is useful if your VHDX file size is not shrinking even after compacting. This happens because Hyper-V does not automatically mark unused space as “zeroed” after you delete files inside the VM. SDelete can overwrite free space with zeros, allowing the Compact operation to remove it properly.
Please see how to Fix Task failed to perform Scheduled Snapshot Replication, Generation 2 VM: How to set up a Hyper-V Virtual Machine through PXE boot and How to Fix Boot Failed UEFI SCSI Device on HyperV.
The SDelete download package includes a ZIP file containing both a 32-bit version (SDelete) and a 64-bit version (SDelete64). You can download SDelete from Sysinternals Microsoft’s Official Webpage.

To zero out free space on a drive, run SDelete with the -z
switch followed by the drive letter C in my case as shown below.

As you can see, our sdelete operation has completed successfully.

Please see how to fix “Failed to Power on with Error ‘A virtual machine disk support provider for the specified file was not found“, How to enable Secure Boot on PC to install Windows 11, and What are the Differences between UEFI and BIOS.
Shrink the Guest VM Volume
Shrinking a VHDX file is the process of reducing the maximum capacity of the virtual hard disk. This operation is used when you have over-allocated space for a virtual hard disk and you want to reduce its size without affecting the data contained within it.
To do this, locate the VM. The VM needs to be running in order to be able to shrink it.

Launch the Disk Management (diskmgmt.msc) from the run dialog wizard inside the VM as shown below. Or search for Computer Manager or Disk Management.


Note: Hyper-V provides an easy way to shrink a VHDX file, but you can also shrink the volume inside the virtual hard disk not just the VHDX file itself. By shrinking the volume first, you ensure that the VHDX file does not exceed the specified size, preventing unnecessary disk expansion and optimizing storage efficiency.
From Computer Management Console, select Disk Management. Right-click on the Drive and select “Shrink Volume”.

Enter the amount of space to shrink. In this case, 20,000MB (20GB) and then click Shrink to proceed.

As you can see, we now have successfully shrunk the volume and we now have the unallocated space as shown below.

Note: If the shrunk free space from your Hyper-V VM’s VHD/VHDX is not appearing on the VM as shown above. Follow these same steps to shrink it again properly and do not forget to run SDelete as recommended. But not mandatory!
Please see How to convert a VHDX file to a VHD, and how to create a Recovery Partition in Microsoft Windows 10/11. See how to Compact Virtual Hard Disks on VMware.
Compact, Optimize or Shrink the Virtual Hard Disk file
Optimizing VHDX virtual disk files helps reclaim space in dynamically expanding virtual hard disks. The Optimize-VHD cmdlet performs this task using the Compact operation, which removes unused blocks and reorganizes data for better efficiency, ultimately reducing the overall VHDX file size.
Compacting a VHDX file is the process of removing unused space from the virtual disk. This is useful for dynamically expanding disks, which grow in size as data is added but do not automatically shrink when data is deleted. Compacting the VHDX file will reduce the physical file size on the host system without changing the logical size of the disk within the virtual machine.
Hyper-V’s dynamically expanding virtual hard disks (VHD/VHDX) offer significant benefits, particularly in optimizing physical storage. However, their convenience comes with a maintenance cost. They expand automatically as needed but won’t release space unless you manually intervene except you compact them.
This process requires the VM to be shutdown and to delete any checkpoints. This can be done by using the PowerShell or Hyper-V manager console as we will see very shortly.
Method 1: Via the Hyper-V Manager
Launch the Hyper-V Manager, right-click on the VM and select Settings or from the Action pane, select settings.

Next, ensure the right VHDX file of the VM is selected. Click on the Edit Disk as shown below. This will launch the Edit Virtual Hard Disk Wizard.

On the locate Virtual Hard Disk page, click on Next.

Select Compact and click Next.

The system will shrink the VHDX file, freeing space on the Hyper-V host. Click on Finish when complete.

Please see How to Create a Windows Server VM on HyperV, how to install HyperV and Configure vSwitch on Windows Server with PowerShell, and how to Fix PXE Boot Stuck or No Boot Image was found for HyperV VM.
Method 2: Using PowerShell
This step also requires you to shutdown the VM and Optimize the VHDX as we have seen in method 1 above. To do this, launch PowerShell as Administrator on the Hyper-V host.
Run the following command as shown below and do not forget to replace the path with the right virtual hard disk file path as shown in the image below.
Optimize-VHD -Path "C:\Path\to\VM.vhdx" -Mode Full

This process will remove the unallocated space from the VHDX file. Thereby, reducing the size on disk disk and returning storage to the Hyper-V host.
In summary, “Shrinking” reduces the virtual disk’s logical size (how large the disk appears within the virtual machine), while “compacting” reduces the physical file size on the host system (how much storage the VHDX file actually occupies). Compacting is usually applied to dynamically expanding disks to reclaim space on the host, whereas shrinking modifies the disk’s maximum capacity
Resize-VHD
You can also use the command below to shrink the VHDX file as discussed below.
Resize-VHD -Path "C:\ProgramData\Microsoft\Windows\Virtual Hard Disks\Windows 11 Clent.vhdx" -ToMinimumSize

-ToMinimumSize
reduces the VHDX to the smallest possible size by removing unused space (this does not change the partition inside the VM, only the VHDX file size on the host).Note: Shrink operations in Hyper-V can also be performed through the command above. Two users stated on Spiceworks that they were able to remove this unallocated space using the command above. This blog post from Altaro also supports the same argument. This was the closest I saw on the web, and it did not work for me as the unallocated space was still visible. Let me know if it does for you.
Note: When you try to run the command again, you will get the below error. This shows I did everything correctly but the unallocated space is still there
Resize-VHD : Failed to resize the virtual disk. The system failed to resize 'C:\ProgramData\Microsoft\Windows\Virtual Hard Disks\Windows 11 Clent.vhdx'. The requested operation could not be completed because the virtual disk's size cannot be safely reduced further. (0xC03A0027).
What this command does is to help reduces the size of the VHDX file by removing unused space within the VHDX container. It also helps shrink the VHDX file size after files inside the VM have been deleted or zeroed out (using tools like sDelete). It did not address the unallocated space within the partition for me. But then, I am not sure why the unallocated space is still available. Please let me know in the comment section.
Please see how to Create local Backup Repository and Add HyperV to VBR Inventory, how to Add Another Hard Drive to a Virtual Machine in HyperV, and how to run Windows 11 on HyperV.
Can the Unallocated Space be removed from Hyper- V VM?
Having taken a look at removing the unallocated space. You will realise that this is more difficult than expanding an existing disk. At the end of this article, I will show you how to put this allocated space to use correctly.

Please see how to fix System Partition not available or large enough on Microsoft BitLocker Administration and Monitoring [Part 1], and a Review of MiniTool Partition Wizard – Disk Utility Tool.
What else can you do with the Unallocated Space?
Here are my suggestions for removing unallocated disk space in a VM if you’re unsure how to proceed. You have two options: create a new partition or extend an existing partition. Both methods will make the unallocated space usable.
Unallocated disk space is an unused portion of a disk that cannot store data like other partitions or volumes. Since it remains inaccessible, many users want to remove it. However, because it contains no data, it cannot be deleted directly. Instead, you can either create a new partition from it or merge it with an existing one to make the space usable as mentioned above.
1: Create a New Simple Volume: By right-clicking the unallocated volume space, choosing New Simple Volume and following the wizard, we can create a new partition on the unallocated disk space

2: Extend Volume: You can extend the volume by right-clicking on the C drive and selecting “Extend Volume”.
You can only merge unallocated space with an adjacent volume to its right; otherwise, the “Extend Volume” option remains disabled. Please see “Fix unable to Extend Volume on Windows protected by BitLocker“. Additionally, only NTFS partitions support expansion if the drive uses FAT32 or exFAT, it cannot be extended with contiguous unallocated space. Also, see “KB5034439 Windows Update Error: Resize WinRE Partition“

FAQs
Microsoft Hyper-V primarily uses VHDX, while QCOW2 is designed for QEMU and KVM hypervisors. Converting VHDX to QCOW2 allows you to import existing virtual machines from Hyper-V or migrate them to Proxmox for streamlined management and deployment.
Converting VHDX to QCOW2 allows you to easily migrate virtual machines from Hyper-V to Proxmox, offering benefits like enhanced storage management, better disk space utilization, and improved compatibility with QEMU and KVM-based hypervisors.
VHD (Virtual Hard Disk): An older format introduced with Microsoft Virtual PC, supporting up to 2TB in size. It allows dynamic and fixed disk types but lacks modern performance and reliability enhancements.
VHDX (Hyper-V Virtual Hard Disk): A newer format introduced with Windows Server 2012 and Windows 8, supporting up to 64TB. It provides better performance, improved data integrity, and power failure protection. VHDX also features larger block sizes, better disk alignment, and enhanced resilience, making it the preferred choice for modern virtual environments.
Summary
Hyper-V dynamically expanding disks can grow rapidly and reach their maximum size. To prevent this, regularly monitor disk usage and manually adjust virtual hard disk properties. Efficient storage management involves shrinking or compacting the disks as needed.
I hope you found this article very useful on how to Shrink and Compact Virtual Hard Disks in Hyper-V. Please feel free to leave a comment below.
The post How to Shrink and Compact Virtual Hard Disks in Hyper-V appeared first on TechDirectArchive.