Can you shrink the sparse disk image of a Mac OS X guest OS in VMWare Fusion?
In VMware Fusion since version 4 you can go to VM preference -> General -> Clean Up Virtual Machine.
Additionally there is a chart where you can see, what size is expected after shrinking.
Aha — indeed you can, as per this thread on the VMWare discussion boards about this issue, assuming:
- The file is a sparse disk image, and not pre-allocated.
- The VM does not have snapshots.
In short:
Erase free space on the guest OS’s disk from within the guest OS using Disk Utility, then shrink the guest OS’s disk from the host OS using vmware-vdiskmanager
at the command line.
In long:
In the guest OS:
- Open Disk Utility.
- Select the guest OS’s partition.
- Go to the “Erase” tab.
- Click on the “Erase Free Space” button.
- Make sure “Zero Out Deleted Files” is selected, and erase the free space.
- Once it’s finished, close Disk Utility, and shut down the guest OS.
Or in the terminal of the guest OS when the partition is named 'Macintosh HD':
diskutil secureErase freespace 0 Macintosh\ HD
sudo halt
In the host OS:
-
Open Terminal and type:
[ -d "/Library/Application Support/VMware\ Fusion" ] && alias vmware-vdiskmanager="/Library/Application Support/VMware Fusion/vmware-vdiskmanager" || alias vmware-vdiskmanager="/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager"; vmware-diskmanager -k
Type 'space' then the path to the virtual disk file of your VM.
Hit return.
The guest OS’s virtual disk file is found within its virtual machine file. E.g. if your virtual machine file is at /Users/you/VM
, the path to its virtual disk is /Users/you/VM.vmwarevm/VM.vmdk
.
For the record, this shrunk a Snow Leopard VM of mine from 15 GB to 6 GB.
They added a CLI option that was super easy - do this from inside the guest OS:
sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink /
From mudaltsov at the VMware Commmunity Forums:
A slightly easier method - the shrink functionality is built into the VMware Tools command-line utility:
sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrink /
This will first do a wipe of empty space one the file system (same as creating a zero-filled file) and show a progress in the guest Terminal. When that's done, the VMDK shrink will be invoked without shutting down the VM, and show up as a progress bar over the VM window.
The / is a path to the file system to wipe empty space on. If you have multiple partitions, you can wipe them individually and do a final shrink at the end:
-
vmware-tools-cli disk list
to see the available locations for wipe -
vmware-tools-cli disk wipe <location>
to wipe each location (repeat multiple times), without the shrink operation -
vmware-tools-cli disk shrinkonly
to do the final shrink operation.
This is also explained by vmware-tools-cli help disk
In variants of VMware Fusion, succeeding 3.x, the locale of vmware-vdiskmanager
, as mentioned in the accepted answer is:
/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager
So all you need is
/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k
then go to finder, navigate to your VM, which normally is in "~/Documents/Virtual Machines/".
Right click on the File, select "Show package contents", then drag the .vmdk-File to Terminal and hit enter.