VMWare: Compact Spare Disk Image

Overview

VMware offers spare disk images which only allocate space as they are used as one option.  This allows for future growth of the disks on a VM without requiring all of the storage be available immediately.  The problem with spares disk images is that in systems with high IO levels that generate a large amount of transient data they will grow even though the total amount of VM storage is not increasing.  To combat this you must occasionally compact the disk image.

Requirements

Disk images may only be compacted while the VM is shut down so that the compact tool has exclusive access to the VMDK file.  

Procedure

The following steps are the recommended method to compact a VM:

  1. Shutdown the guest operating system
  2. Verify the shutdown in vCenter 
  3. Check the amount of used storage in vCenter as a reference for comparison
  4. ssh as root to an esx host (for example for esx1 use the command  “ssh root@esx1.bugs.net”)
  5. Change into the VM folder (for example for AFS06 use the command ” cd /vmfs/volumes/AFS\ Server\ Storage/AFS06/”)
  6. Use the command vmkfstools -K” on each VMDK file one at a time (for example for AFS06 the commands would be “vmkfstools -K AFS06.vmdk ; vmkfstools -K AFS06_1.vmdk”)
  7. Once the hole punching operation is complete compare the storage usage to the original value in vCenter.  It should have decreased.
  8. Start the guest operating system back