Lately I'm also running macOS virtualized for testing various apps. After some heavy usage the same problem popped up: the .vmdk uses way too much space on my quite small 256GB SSD. Currently is at around 70GB.
The process is similar to what I did on Windows and Linux i.e. write a null file that is erased at the end then use the command-line tools to compact the .vmdk and reclaim space (the example is specific for VMware Fusion).
Before performing these disk operations, take a verified backup or snapshot, shut down the VM correctly, and confirm that the virtual disk is thin-provisioned and that adequate free space is available. Writing from /dev/zero intentionally exhausts the guest’s free space; understand and monitor the operation before proceeding.
Without further ado:
Step one
Fill up all the empty space with 0x00
$ cat /dev/zero > zeroed_empty_space; rm zeroed_empy_space
In case you're wondering what /dev/zero does:
/dev/zerois a special file in Unix-like operating systems that provides as many null characters (ASCII NUL, 0x00) as are read from it. One of the typical uses is to provide a character stream for initializing data storage.
Step two
VMWare Fusion is installed by default in /Applications/VMware Fusion.app so you just have to run:
$ cd '/Applications/VMware Fusion.app/Contents/Library/'
$ vmware-vdiskmanager -k your_vm_name.vmdk
and wait until it finishes - ensure the host has sufficient working free space for your particular disk and VMware configuration; do not rely on an exact one-to-one requirement.
Results
| VM size | |
|---|---|
| Original vmdk size | 70GB |
| After zeroing free space and clean-up | 40GB |