Right! VMWare Fusion on Mac OSX allows you to shrink virtual disks easily for Windows virtual machines right from the graphical interface – Virtual Machine -> Settings -> General -> Clean Up Virtual Machine… but how about for Linux guests? There isn’t such option to do this from the graphical interface, so Terminal here we go!
When you delete files from your virtual machine, Fusion does not return the space to your Mac. Shrinking the virtual machine by cleaning up the hard disk returns that freed space to your Mac.
Cleaning up the virtual hard disk also consolidates any unconsolidated snapshot files left on the virtual machine. Unconsolidated snapshot files can be left on the virtual machine when manually deleting a snapshot fails.
There are a couple things we want to do before shrinking the virtual disk; cleaning the clutter (deleting unnecessary files), defragmenting the drive and wiping the free space clean so the shrinker will know what is free to get rid of, to recover as much disk space as possible.
So, boot up your Linux Virtual machine, delete all old files, ISO images, empty the trash and fire up a Terminal window.
Preparing Linux Guest Virtual Machine
1- Defrag guest virtual disk (usually sda1, sdb1) – Listing in Terminal: ls -la /dev/sd*
Note: Defragmenting the virtual disk will tax the host and guest I/Os. Both, your Mac and the Guest OS may become slow or unresponsive while this process is taking place. Be patient.
sudo e4defrag /dev/sda1
2- Wipe the guest virtual disk free space clean so the shrinker will know what is free to get rid of:
Note: Wiping the virtual disk free space clean will tax the host and guest I/Os. Both, your Mac and the Guest OS may become slow or unresponsive while this process is taking place. Again, be patient!
dd if=/dev/zero of=wipefile bs=1024x1024; rm wipefile
We’re now ready to shrink the virtual disk but we can’t reclaim space with the virtual machine running, so shut it down first (Power off).
Shrink VMWare Fusion Linux Guest Virtual Disk
Open Mac OS X Terminal and change directory to /Applications/VMware/Fusion.app/Contents/Library/
cd /Applications/VMware\ Fusion.app/Contents/Library/
Next browse to your Virtual Machine in Finder, right click it and select “Show Package Contents”
In Terminal, type ./vmware-vdiskmanager -k and drag & drop the virtual disk to Terminal for its path to be autocompleted as shown below:
Press enter and be patient while your Linux virtual disk is shrank