Analyse Disks with Treesize: Defragment and Shrink VMware Workstation VM Disks

In this article, we will discuss how to “Analyse Disk with Treesize: Defragment and Shrink VMware Workstation VM Disks”. If you’re looking to improve VM performance, defragmenting is the way to go. If you are trying to free up disk space on the host, compacting (shrinking) or disk clean up will be appropriate. Please see how to Map and disconnect Virtual Disk in VMware Workstation, and how to Configure Autologin for a VM in VMware Workstation.
For some of you that utilize VMware Workstation in your lab as part of your virtualization platforms. You would notice that your Virtual Disk Files (VMDK) grow larger than necessary. At times exceeding the actual space used by the guest operating system. To compact or shrink the size of these VMDK files, please read along for all options I have put together.
Note: When you actively use VMware Workstation VMs, tasks such as adding and deleting files, installing and uninstalling software, gradually consume disk space on your host PC.
However, simply removing files or applications inside the virtual machine doesn’t immediately free up all the space on the host. To reclaim this unused space, you need to perform a disk cleanup within the virtual machine itself. This process is similar to compacting a database, where unused “white space” is recovered.
Also, see “Downgrade VMware Workstation: Fix the Processor does not support xsave on VMware Workstation“, and How to Install Windows on VMware Workstation. Here is How to disable side-channel mitigations on VMware Workstation.
Reduce Virtual Machine Disk File
By performing “cleanup” or “compacting”, you can reclaim a significant amount of disk space, optimizing storage on the host system. This process does not apply to pre-allocated disks as shown in the image below.

To reduce the size of the disk, I will work you through the following steps;
- Defragment the disk from VMware workstation or from Windows.
- Compact the virtual disk to reclaim unused space.
- Clean up the virtual disk from the host from the VM Settings and also from the OS using the built-in Workstation utility. They serve different purposes. Therefore, I urge you to read along.
Here is how to Fix VMware Workstation and Device/Credential Guard are not compatible with VMware Workstation. Also, see how to “Install Workstation Pro 17: Fix failed to initialise library for mounting and unmounting virtual disks“.
Defragment and Shrink VMware Workstation VM Disks
In VMware Workstation, defragmenting and compacting (shrinking) a VMDK (virtual machine disk) file are two different processes aimed at optimizing the virtual disk. But they have distinct purposes and functions:
Defragmentation a VMDK File
Defragmentation reorganizes the data stored on the virtual disk to ensure that related files are stored closer together. Over time, as files are created, modified, and deleted, the disk can become fragmented. This means that parts of files are scattered across the disk. Defragmentation aims to improve read/write performance by reducing the amount of time it takes for the virtual machine to access random pieces of data.
Note: Therefore, defragmenting consolidates fragmented files on the virtual disk. This is similar to how traditional defragmentation works on physical hard drives. It doesn’t reduce the size of the VMDK file but optimizes data layout to improve performance. In fact, the size of the VMDK file may increase slightly due to the reorganization of data blocks.
I will recommend to employ defragmentation of your VMs if you notice your virtual machine are getting slower performance wise due to disk fragmentation. This way, defragmentation can help optimize disk access and improve speed.
Here is how to Create and Delete AD DS Partition with NTDSUTIL.EXE. Also, see Create Disk Cleanup Shortcut: How to perform disk clean up in Windows, and How to delete Windows old folder in Windows 11.
Compacting (Shrinking) a VMDK File
Compacting reduces the physical size of the VMDK file on the host machine. It does this by reclaiming the unused space. Over time, as files are deleted from within the virtual machine, the actual size of the VMDK file on the host disk may not shrink. This happens more when using a thin-provisioned disk. Shrinking the VMDK file allows you to recover this unused space.
Shrinking a VMDK file scans the virtual disk for blocks that are no longer in use and removes them. Thereby, reducing the file’s size on the host machine. This process does not change the disk size as seen from inside the virtual machine but frees up space on the host. As I said above, I will work you through the differences and why you should perform this using the VMware Workstation Settings and also from Windows.
Kindly employ compacting when you have deleted a lot of data from the virtual machine. But the actual size of the VMDK file on the host has not decreased, and you want to reclaim that disk space. The table below, discusses the key differences between defragmentation and compacting.
| Feature | Defragmenting VMDK | Compacting VMDK |
|---|---|---|
| Purpose | Reorganizes data to improve disk access performance. | Reduces the size of the VMDK file on the host by reclaiming unused space. |
| Effect on Disk Size | May slightly increase the file size. | Reduces the physical size of the VMDK on the host. |
| Impact on VM | Improves performance by reducing file fragmentation. | Frees up space on the host without affecting VM performance. |
| When to Use | When the virtual machine slows down due to fragmentation. | When you need to reclaim unused space on the host. |
| Performance Gain | Can improve read/write speeds inside the VM. | Does not directly affect performance, but saves disk space on the host. |
In VMware Workstation, the terms compacting and shrinking are interchangeable. Both refer to the same process of reducing the physical size of a virtual disk by removing unused space. Thereby making the VMDK file smaller on the host system.
Please see How to Compact Virtual Hard Disks, and How to create a Recovery Partition in Microsoft Windows 10/11. Also, see How to create a dual-boot setup on Windows 11.
Analyse Disks with Treesize
As you can see in the image below, the local disk space is almost full. I already know the reason, and I would like to work you through the various steps to free up more space on your local disk.

Install Treesize
Treesize is a free disk space manager for Windows operating systems. The software helps you manage your storage by showing you the sizes of folders including all subfolders etc.
You can download “Treesize free” from the Microsoft Store, and also from the Treesize official website. Click on the installer to run and accept the license agreement.

Note: I am actually installing a newer version. But the installation steps are the same. Click on Next to proceed.

Select “Launch Treesize Free now” and click on Finish. This will ensure when you click on Finish, the program will be launched automatically.

I will select “Always start as administrator”.

The disk(s) will be immediately analyzed. The disk space manager TreeSize Free enables you to determine what are utilizing your disk space. Below are some more features of this tool.
- Visualize disk space usage with the treemap chart.
- Gain in-depth information in the column view.
- Filter scan results and break down information to better clean up your hard disk. – Scan smartphones and mobile devices connected to you PC.
- Scan network drives (not in Windows domains / on Windows Server) and locally synchronized cloud shares.
- See the NTFS compression rate and apply NTFS compression to directory branches.
- Use the touch interface on touchscreen devices.

From the image above, we can see virtual machines consumes 275,2 GB of our disk space. Because of this, we will defragment, Compact and perform disk cleanup from the VMware ware and from Windows.
Defragment Virtual disk Files
To do this via VMware Workstation, please select and right click on the VM and select Settings.

On the Hardware Tab, select Hard Dissk (NVMe). On the other pane of the window, select Defragment. This will help consolidate free spaces as discussed above.

As you can see, the virtual disk files are being defragmented. This process can take a while though.

The image below shows that the defragmentation has completed successfully.

Compact Virtual disk Files
To do this via VMware Workstation, please select and right click on the VM and select Settings. On the Virtual Machine Settings, select the Hardware Tab. Next, click on the Hard Disk (NVMe) and on the right pane, select “Compact”. This will shrink and help reclaim unused space.

As you can see, this has been completed successfully.

At least, we can see that our Windows Server has reduced drastically from 120 Gb to 111,4 GB. Also, the MBAM VM reduced from 155 GB to 152,1 GB. To me, I am still not satisfied. What else can we do?

Note: You could use the open-vm tools to reduce the VMDK as well. These are done inside the GUEST OS (Virtual Machine)
Please see How to Check what files are taking up space on Windows 11, and Fix File Explorer thumbnails issue on Windows 11. Also, see how to fix Error 0x80073701: The request to add or remove features on the specified server failed.
Disk Cleanup from thee VMware Workstation Manager
When you use VMware Workstation virtual machines, activities like adding and deleting files, installing and uninstalling software can gradually consume disk space on your host computer. The emphasis here is on the host PC.
Note: However, removing files or applications inside the virtual machine doesn’t immediately free up all the space on the host. To reclaim this unused space, you need to perform a disk cleanup within the virtual machine itself. This process is similar to compacting a database, where unused “white space” is recovered. By performing this cleanup, you can reclaim a significant amount of disk space, optimizing storage on the host system.
I would recommend performing a Cleanup after taking and deleting snapshots. When a VM has been in use for a long time and has fragmented or inefficiently used disk space.
Lastly, I will recommended performing a VM Virtual Disk Cleanup after reducing the VM’s disk usage significantly (like deleting large files, uninstalling applications, etc.). The table below shows the key differences between Compacting and Cleanup.
| Feature | Compacting | Cleanup |
|---|---|---|
| Scope | Reclaims unused space in thin-provisioned disks. | Broader optimization that includes compacting and other cleanup tasks. |
| Disk Type | Works only with thin-provisioned disks. | Can apply to both thin and thick-provisioned disks. |
| Focus | Shrinks the size of the VMDK file by removing unused space. | Includes compacting, but can also clean up snapshots and optimize disk layout. |
| Use Case | When you’ve deleted files inside the VM and want to reclaim space. | After extensive use, snapshot management, or general disk optimization. |
Perform Cleanup
Before performing disk clean up, it is recommended to have the VM Shutdown. Click VM tab and move the mouse cursor over Manage option and then select Clean Up Disks option.

VMware Workstation will calculate how much space can be recovered and perform the necessary cleanup operations. From the Disk Cleanup image below, select “Clean up now”.

As you can see, the cleanup is in process.

Disk cleanup has finished successfully.

As you can see below, we have been able to further reduce the Windows Server 2019 VM to 109,5 GB. Lastly, the local disk now has 41,1GB of free space compared to 31,8 before disk freeup.

Please see how to Manage VMware Snapshots: Delete or Edit or Revert a Snapshot. Here is How to clear cache in Windows 11.
Optimize your Data Drives in Windows
The difference is that cleaning up and compacting a VMDK file in VMware Workstation reduces the virtual disk size by reclaiming unused space within the virtual environment. While defragmenting and cleaning up using Windows utilities reorganizes data and removes unnecessary files on the guest OS but doesn’t reduce the actual VMDK file size on the host.
With the above in mind, it is worth noting that Windows handles the optimization of your data drives automatically. However, if you are concerned about their performance and would like to check their statis manually or change the optimization schedule. You are free to do so.
Note: ​​​​​​​Hard drives are defragmented, which is reorganizing the files so that they are all lined up and easier for the drive to read. Solid-state drives (SSDs) are what’s known as “trimmed,” which is basically telling the drive where it can safely do cleanup work when it’s not busy doing more important things like saving or loading your files. It’s all optimization.
Defragment and Optimize Drives
To do this, search for “Defrag”, or if it on a DC, select Tools and select “defragmentation and Optimize Drive”. Also, you can do this via the Start Menu as shown below.

From the “Optimize Drive” window, select the Drive you wish to optimize. For this VM, I have one drive. The other VM had two drives. So this might also be the case for you.
Select the drive you want to work with, and select Optimize to have Windows run optimization on the drive.

Change Defragmenting Schedule
By default, Windows will automatically optimize your drives once a week. But if you want to change that schedule to be more or less frequent.
To do this, click on “Change Settings”, and select your desired frequency. Do not forget to specify the Drive(s) as well when doing this.

Cleanup direct from Windows (Guest OS)
Disk Cleanup directly from the guest OS utilizes the Windows built-in utility. This tool is designed to free up space on your hard drive by removing unnecessary files that accumulate over time.
It helps improve system performance and can reclaim valuable storage space for the Guest OS unlike the Host OS which we have discussed above.
Disk Cleanup scans your system for various types of files that are no longer needed and gives you the option to remove them. The types of files it can delete include:
- Temporary Files: These files are created by applications and Windows itself that are meant for short-term use.
- Downloaded Program Files: Files that are downloaded when you visit websites such as ActiveX controls and Java applets and are safe to delete.
- Recycle Bin: Files you’ve deleted that are still in the Recycle Bin can be permanently removed to free up space.
- System Error Memory Dump Files: Files created when Windows crashes (blue screen) and can be large and unnecessary unless you need them for troubleshooting.
- Temporary Internet Files: Cached web pages and images stored by your browser. They enable websites to load faster, but are often outdated.
- Thumbnails: Cached image previews (thumbnails) that help load images faster in File Explorer.
- Windows Update Cleanup: Older versions of system files from previous Windows updates that are no longer needed.
- System Files (optional): Disk Cleanup can also clean up old Windows installation files, service pack backups, and other system-level files that are safe to remove but might affect rollback capabilities.
Why and when to use Windows Built-in Disk Cleanup
Since we have discussed this extensively above. I will touch on some points we have not covered so far.
- Over time, unnecessary files can accumulate and take up a significant amount of disk space. Disk Cleanup helps reclaim space.
- As your disk becomes cluttered with temporary files, Windows may slow down. Cleaning up unnecessary files can improve system responsiveness and performance.
- Disk Cleanup helps reduce file clutter. Thereby making your system more organized and efficient to run.
- Disk Cleanup deletes old Windows Update files, error reports, and log files. This ensures that your system isn’t bogged down by outdated or unnecessary data.
- On traditional hard drives, cleaning up your disk can make the defragmentation process even more efficient by clearing out files that don’t need to be reorganized.
I will recommend running or utilizing the Disk Cleanup periodically as part of your system maintenance routine. This helps ensure that your system stays clean and performs well. Also, when your system drive is running out of storage, using Disk Cleanup is one of the quickest ways to free up space.
Lastly, after large Windows updates. This is because, there are often leftover files that can take up significant space. Running Disk Cleanup can remove old update files.
Run Disk Cleanup
Press the Windows key and type “Disk Cleanup,”. Select the utility from the search results.
On the Disk Cleanup window, please select the “Files to delete”. I will select all files. I will also click on “Clean up System Files” for more thorough cleaning. This will scan for additional files like old Windows installations or Windows Update files.

Click OK, and confirm that you want to delete the selected files. The scan will kick off as shown below.

After calculating the size of space you can free. You will be prompted with the window below. Click OK to regain the disk space.

You will be prompted to confirm the deletion. Please select “Delete Files” as shown below.

As you can see below, the cleanup is in progress. This can take a while, please be patient.

Conclusion
Disk Cleanup is an essential utility for managing disk space and maintaining system performance in Windows. Regularly cleaning up temporary files, system junk, and outdated Windows updates helps keep your system running smoothly and prevents it from slowing down due to storage bloat.
While Disk Cleanup is a reliable built-in tool, third-party utilities such as “iSunshare ‘, and “CCleaner”. For instance, CCleaner provides the ability to clean application-specific cache or browser history across multiple browsers. However, Disk Cleanup is safe, doesn’t require installation, and integrates seamlessly with Windows.
I hope you found this article on “Analyse Disk with Treesize: Defragment and Shrink VMware Workstation VM Disks” very useful. Please feel free to leave a comment below