Mac – VMware Workstation: how to reduce .vmdk maximum size

virtual machinevmware-workstation

I have a 150 GB disk file (.vmdk, non pre-allocated) where my virtual machine is stored.

The file is currently 20 GB, but it is growing everyday, even though I'm not storing anything new in the guest file system.

I have been looking for hours for a way to reduce the maximum size of this disk, so that it never gets to 150 GB (I'd like to set the limit to 30 GB, and see what happens when the VM reaches this size).

What I have tried:

  • Converting the disk image with VMware Converter → this does not work, the tool only allows creating a full copy or a 'linked clone'.
  • Creating a new blank virtual machine of the desired size in order to copy the 20GB data onto the new .vmdk → I cannot find a way to perform the copy or even connect the new disk to my existing VM (so that I perform the copy using the guest OS).
  • Looking in the .vmx file to check if the maximum size was not set in plain text (it's not).

Although this task seems technically quite simple (there is no tricky shrinking involved, just a simple change of size limit), I'm really out of ideas here…

Is there a solution at all ?

Best Answer

The usual procedure for reducing the size of a .vmdk disk is to:

  1. Defragment the disk via the guest, choosing a defragmentation mode that consolidates empty space at the end of the disk. For a Windows guest, you should empty the Recycle Bin and turn off hibernation and paging, returning them after the defragmentation is done.

  2. Zero all unused space on the disk.
    For Windows use sdelete : sdelete -c.
    For Linux : dd if=/dev/zero of=/mytempfile && rm -f /mytempfile.

  3. Shrink the disk (which may take quite a long time to complete).
    VMware Workstation : Menu VM / Manage / Clean up disks.
    Or use : vmware-vdiskmanager.exe -k [VMDK PATH].
    for ESX : vmkfstools --punchzero [VMDK PATH].

Converting the disk from growable to preallocated could stop its growing. This can be done using vmware-vdiskmanager with the -t parameter whose values are:

0 : single growable virtual disk
1 : growable virtual disk split in 2Gb files
2 : single preallocated virtual disk
3 : preallocated virtual disk split in 2Gb files

The following command will convert the .vmdk from growable to preallocated :

vmware-vdiskmanager -r current_disk_name.vmdk -t 3 new_disk_name.vmdk

If you wish to change the size of the disk, this should be done while the disk is still in growable format (examples here).

For more information see the Virtual Disk Manager User’s Guide.

Related Question