While it is a somewhat known fact that you used to be able to shrink disks using vmkfstools -X in ESX 2.x, the option was removed as of ESX 3.0. The reason for this probably stems from those few customers that were not familiar with using the command properly and ended up cutting off too much of the disk and corrupted their Guest OS file system as a result.
Ever since the option was removed there have been more experienced users wanting the option to be added back to vmkfstools as they are aware of the risks and want that ability again. For those people I just mentioned, I have a treat for you:
** Use this technique at your own risk. I do not and will not take responsibility for your corrupted vmdk’s as a result of following this process, whether correctly or incorrectly **
If you have ever taken a look at the descriptor file for a vmdk file, you will the “Extent description” section:
# Extent description
RW 52428800 VMFS “foo-flat.vmdk”
The value between ‘RW’ and ‘VMFS’ is the size of disk when divided by 512:
52428800 * 512 = 26843545600 (25G)
-rw——- 1 root root 26843545600 Sep 18 19:10 foo-flat.vmdk
-rw——- 1 root root 370 Sep 18 19:11 foo.vmdk
If you want to shrink (or increase) the size of your vmdk file, alter this value in the descriptor file to reflect your new desired size*. You can do with this ‘vi’ or ‘nano’:
* For this example I will to shrink the disk to 12.5G
# Extent description
RW 26214400 VMFS “foo-flat.vmdk”
After making this change you can use ‘vmkfstools -i’ to clone this disk:
# vmkfstools -i foo.vmdk foo_1.vmdk
Destination disk format: VMFS thick
Cloning disk ‘foo.vmdk’…
Clone: 100% done.
You will discover that the cloned disk now reflects the new size of 12.5G:
-rw——- 1 root root 13421772800 Sep 18 19:13 foo_1-flat.vmdk
-rw——- 1 root root 372 Sep 18 19:13 foo_1.vmdk
-rw——- 1 root root 26843545600 Sep 18 19:10 foo-flat.vmdk
-rw——- 1 root root 370 Sep 18 19:11 foo.vmdk
This technique will also work if you try to cold migrate the VM or Storage VMotion it. This would be less cumbersome than trying to play around with another disk at the command line during a simple shrink process. Change your values and then migrate the disks via VI Client/VC to a different datastore. This will reduce disk space required for this operation and it will be a whole lot cleaner than a manual clone with vmkfstools and then a remove of the original.
SVMotion would be the a favourable option for those that do not want to incur downtime for their VM.

Pingback: Tweets that mention How to Shrink a VMDK file in ESX -- Topsy.com
Pingback: How to shrink a VMDK file in ESX « PixeLabs