Shrink Virtual Disks in VMWare

The situation

If you are using VMware, you already know that the size of the virtual machines seems to grow and grow. Doesn’t mind if your guest is Ubuntu, OSX, Windows,… You might have a OSX guest reporting 40GB usage, but the VMware files in your host might take 100GB (real case, just happened to me a week ago).

I will now dump the steps I follow to reclaim those unused 60GB, depending on the guest operating system.

Windows guests

You are most probably using NTFS. VMware knows NTFS perfectly fine, so you can just use the menu entry to shrink the Windows guest:

Shrink Windows NTFS guest

Library -> right-click Windows Guest -> Manage –> Clean Up Disks…

Linux, OSX, FreeBSD guests

VMware just doesn’t know what space is actually empty in your guest operating system, so clicking Manage –> Clean Up Disks… will do nothing for you.

We have to make it easy for VMware, after cleaning up your guest, run these commands to fill the guest’s empty space with zeroes (might take long):

sudo dd if=/dev/zero of=/zerofile bs=4096
sudo rm /zerofile

Now, VMware will be smart enough to detect empty space in the guest. Tell VMware to shrink the disk by running this in your terminal:

/path/to/vmware-installation-folder/vmware-vdiskmanager -k <Absolute Path to the Virtual Hard Disk>

Example in OSX host

First, I remove unecessary files from a Ubuntu 16.04 guest:

sudo apt-get autoremove
sudo apt-get clean

Then, I fill the guest’s empty disk space with zeroes:

sudo dd if=/dev/zero of=/zerofile bs=4096
sudo rm /zerofile

At last, I use my OSX host’s terminal to tell VMware to shrink the guest’s (Ubuntu) disk:

/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k /Users/mikel/Documents/Virtual\ Machines.localized/Ubuntu\ 16.04\ i386.vmwarevm/Virtual\ Disk.vmdk

Example in Windows host

First, I fill the OSX guest’s empty disk space with zeroes:

sudo dd if=/dev/zero of=/zerofile bs=4096
sudo rm /zerofile

At last, I use my Windows host’s command line (Start Menu -> Find "cmd") to tell VMware to shrink the guest’s (OSX) disk:

C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager -k "C:\Users\mikel\Documents\Virtual Machines\OSX Mavericks\Virtual Disk.vmdk"

Notes

  • When following this method, VMware does not care whether the guest uses FAT32, ext2, ext3, reiserFS, … we take care of making it easy for VMware

  • I have done this with Ubuntu 12.04 to Ubuntu 16.04, OSX Leopard to
    MacOS Sierra, … I’m confident this works with any guest operating
    system

  • This method will fill the guest’s whole disk. Then VMware will create a shrunk copy of the guest before deleting the old “massive” one. Make sure you have enough free disk to handle this

© 2017 Akaita development