Shrinking a VMDK File
In my previous post I explained the art of extending VMDKs and RAW LUNs in the ESX world. Today I will cover shrinking a .vmdk. It is important to resize the volume with a partition tool before you forcefully resize the .vmdk. If you fail to heed this advice you will have a nonfunctional volume whose partitions need to be reformatted.
1) Make sure you have a valid backup of the partition(s) in question.
2) Download SystemRescueCD
3) Power off your VM and mount the CD.
4) Boot up and marvel as the VM boots into Linux.
5) Hit enter to Boot (default).
6) Once it finishes booting, type qtparted.
7) Right click on the volume in question and choose resize.
8) Ensure that you do not shrink too much. In this example I have a 4GB volume with 3GB worth of data. If you shrink beyond 3GB you will need to recover your data. Remember, you can always extend it out a few MB to fill the volume up. Don’t be too stingy.
9) Boot up your machine and ensure that the data is still in tact. You should see your original volume and your shrunken partition. You will also have extra space (the space you are trying to trim in the first place). Shut the VM down and SSH into the appropriate ESX server.
10) In my example I want to resize the .vmdk to 3GB. Therefore I issued:
vmkfstools –force –X 3G vmhba1:0:59:1:SERVERA_3.vmdk
11) Fin.
- Jason Langone
Commenting is closed for this article.

2007 Systems Architech.