Press "Enter" to skip to content

Convert ESXi disk from thick to thin

When copying, cloning, and moving VM’s around in general any disks that were created with thin provisioning will unltimately be converted to thick provisioning. What a tremendous waste of disk space if you frequently over provision disk space and allow them to grow over time as needed. (Oh yeah that’s what thin provisioning was created for)

Let’s reduce the disk consumption and convert the vmdk’s back to thin (or to thin if you chose thick to begin with)

Ensure you have ssh enabled to your esx server and login as root or su to root from your user account.

Shut down the VM you wish to shrink (I’d suggest reconciling any snapshots you have and making a backup just in case something goes sideways)

Change directory to the path holding your VM, it will look something like /vmfs/volumes/53448b8c-b6d48f58-692a-ac220bdcff63/server_name (you may have to hunt down the right path)
for example I am going to shrink my vCenter Server Appliance which lives in
/vmfs/volumes/53448b8c-b6d48f58-692a-ac220bdcff63/VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10

the directory looks like this:
# ls -ltrah
total 140495888
-rw-r–r– 1 root root 0 Apr 10 23:57 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmsd
-rw-r–r– 1 root root 311 Apr 10 23:57 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmxf
-rw——- 1 root root 547 Apr 11 00:05 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmdk
-rw——- 1 root root 553 Apr 11 00:05 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10_1.vmdk
drwxr-xr-t 1 root root 1.6K Apr 11 01:49 ..
-rw——- 1 root root 100.0G Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10_1-flat.vmdk
-rw——- 1 root root 8.5K Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.nvram
-rw——- 1 root root 25.0G Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10-flat.vmdk
-rw-r–r– 1 root root 125.6K Apr 12 01:37 vmware.log
-rwxr-xr-x 1 root root 3.1K Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmx

As you can see the directory contains 125+G (I closed my terminal window with the actual du output.
But I know it’s using closer to 10G, so let’s shrink it down….

Notice there are two virtual disks ending with OVF10.vmdk & OVF10_1.vmdk

# vmkfstools -K ./VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 100% done.

# vmkfstools -K VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10_1.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 100% done.

This may take a bit of time to complete depending on your disk speed etc…

End result looks the same but notice the actual usage:
# ls -ltrah
total 11077648
-rw-r–r– 1 root root 0 Apr 10 23:57 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmsd
-rw-r–r– 1 root root 311 Apr 10 23:57 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmxf
-rw——- 1 root root 547 Apr 11 00:05 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmdk
-rw——- 1 root root 553 Apr 11 00:05 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10_1.vmdk
drwxr-xr-t 1 root root 1.6K Apr 11 01:49 ..
-rw——- 1 root root 100.0G Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10_1-flat.vmdk
-rw——- 1 root root 8.5K Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.nvram
-rw——- 1 root root 25.0G Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10-flat.vmdk
-rw-r–r– 1 root root 125.6K Apr 12 01:37 vmware.log
-rwxr-xr-x 1 root root 3.1K Apr 12 01:37 VMware-vCenter-Server-Appliance-5.5.0.5201-1476389_OVF10.vmx
drwxr-xr-x 1 root root 1.5K Apr 12 02:03 .

# du -hs
10.6G .

Much better!
Now restart your VM and move on to your next project