How to Reclaim Disk Space from Virtual Machines
Hyper-V admins should focus on four key areas to reclaim disk space from virtual machines.
December 6, 2021
Microsoft Hyper-V administrators often find that virtual machines consume physical storage space far more quickly than expected and are looking for ways to reclaim disk space. Focusing on four areas will help admins reclaim lost storage space.
1. Deleted VMs
One of the first things to look for in the quest to reclaim disk space is deleted virtual machines. When you delete a virtual machine using the Hyper-V Manager, Hyper-V deletes only the virtual machine object. Virtual machines tend to vary in size, but deleting one usually frees up only about 4 MB of space.
When you create a Hyper-V virtual machine, Hyper-V creates a virtual machine folder and two sub-folders. One of those subfolders stores the virtual hard disk while the other stores the virtual machine configuration files. You can see these folders and their contents in Figure 1. In this case, the Virtual Machines folder consumes about 4 MB of space (the subfolder is empty), while the virtual hard disk is over 9 GB in size.
reclaim disk space 1
Figure 1
A Hyper-V virtual machine is very small.
Now, take a look at what happens when I delete a virtual machine. For this example, I deleted a virtual machine named Win10. As you can see in Figure 2, both of the virtual machines’ folders still exist. However, the Virtual Machines folder is empty, while the Virtual Hard Disks folder’s contents remain.
reclaim disk space 2
Figure 2
Deleting a virtual machine does not delete its virtual hard disk.
It’s likely that you can recover a significant amount of space by getting rid of orphaned virtual hard disks.
2. ISO Files and Deployment Images
Another way to reclaim disk space is to remove outdated ISO files and Windows deployment images. Granted, most organizations do not store these files on the same volume as their virtual machines. However, given how much space these items can consume, it is worth checking to see if you have any old ISO or Windows deployment image files that you aren’t using any more.
3. Deduplication
You can also try enabling deduplication on the storage volume where your virtual hard disks reside. Imagine for a moment that you have 100 virtual machines, and all of those virtual machines are running Windows Server 2019. That means that the volume contains a hundred copies of the same operating system. Enabling block-level deduplication at the volume level will almost certainly help you to regain a significant amount of space.
4. Compacting Virtual Hard Disks
When you create a new virtual hard disk in Hyper-V, you can choose to create a fixed-length virtual hard disk or a dynamically expanding virtual hard disk. A fixed-length virtual hard disk tends to be the best option for virtual machines that require peak storage performance because Hyper-V will reserve the required storage space up front. If, for example, you were to create a 100 GB virtual hard disk, Hyper-V would reserve 100 GB of disk space.
However, fixed length virtual disks tend to consume a lot of storage space, so most admins opt instead to create dynamically expanding virtual disks. In fact, dynamically expanding virtual disks are used automatically when you create a new virtual machine using the Hyper-V Manager. Unlike a fixed length virtual hard disk, a dynamically expanding virtual hard disk starts out very small, but the virtual hard disk file grows as you add data to the virtual hard disk.
The opposite is not true, however. If you were to delete data from a dynamically expanding virtual hard disk, Hyper-V would not shrink the virtual hard disk file in response to the deletion. Instead, that storage space remains occupied by the virtual hard disk file, even though it is not being used.
Fortunately, Microsoft does provide a way to shrink a dynamically expanding virtual hard disk file. This can be especially useful if you have recently removed a great deal of data from a virtual hard disk.
Make sure that the virtual machine is shut down, and then right click on the virtual machine and choose Settings from the shortcut menu. This will cause the Hyper-V Manager to open the virtual machine’s Settings page. Select the virtual hard disk that you want to compact, and click the Edit button shown in Figure 3. This will cause Windows to launch the Edit Virtual Hard Disk Wizard.
reclaim disk space 3
Figure 3
Select the virtual hard disk and click the Edit button.
Click Next to bypass the wizard’s Welcome screen. At this point, the wizard will ask you to choose the action that you want to perform. Choose Compact and click Next. You will now see a summary screen confirming that you are about to compact the virtual hard disk. Click Finish, and Windows will remove all the free space from the virtual hard disk file, shrinking the file in the process.
About the Author
You May Also Like