How to compact a VMWare virtual hard drive

vmware-esx

I'm using VMWare ESX to host some VMs, and have allocated 60Gb to one Windows Server 2008 VM. It's not using close to that and is unlikely to.

How can I reduce the amount of space that this virtual disk takes up on the physical disk? I've heard words like Thin Disk and compact bandied about, but haven't had a chance to look properly yet (running out of room is not yet a pressing concern).

Best Answer

Thin\Thick format are generally the terms VMware uses for the VMDK formats - thin will dynamically grow (up to the limit) as space is actually consumed, thick is pre-allocated. Compact is usually used to describe a thin storage format used for Templates.

To convert an existing thick format VMDK to thin format your options are:

1. If you have vCenter and a license that includes Storage VMotion you can convert from thick format to thin format without downtime using that.

2. Use VMware Converter - this will allow you to create a new VM that is a copy of the original but with thin disks rather than thick\fully allocated ones. This will incur some downtime.

3. Use vmkfstools from the command line. This requires the most downtime of all of the solutions. Shut the VM down and from the ESX Console navigate to the relevant VM directory and use the following command:

vmkfstools -i yourthickdisk.vmdk -d thin yourthindisk.vmdk

This clones the original vmdk (the -i flag) but the -d flag specifies that the clone should be a thin format disk. Once the clone is complete edit the VM config to point the new thin disk vmdk. If everything starts up OK you can safely remove the old (thick) VMDK.

4. There is a variation on the vmkfstools option detailed in this blog post using a snapshot to allow you to make the conversion on a running VM. I'm pretty sure that wouldn't be supported by VMware but it's a neat hack.