]> Shrinking thin provisioned ESXi disks 🌐:aligrant.com

Shrinking thin provisioned ESXi disks

Alastair Grant | Friday 22 June 2012

If you use thin provisioning when you create a virtual disk in ESXi, it will not reserve all the space requested, just the space used. This means you can give your guests more space than you have in terms of physical space and also keeps file sizes small if you're moving things about.

When files get created the space is then reserved by the host.

When you delete a file the space isn't recovered automatically. Firstly this is due to files not actually being deleted - when you delete a file you're really just deleting the index entry for that file. The data still exists on disk - which is why it's possible to undelete some files. So it's not possible to recover this space because whilst it's not being used, it still has data.

Programs such as Sysinternals sDelete allow you to (with the -z argument) to zero any free space, that is clear out the data where files used to be. It works by writing a file that fills the entire disk and then deleting it. This means that ESXi will allocate the full capacity of your disk - kind of counter-productive.

Once this has been done, ESXi's "VAAI" feature is supposed to reclaim this - but if your storage device isn't fancy enough to do this or it's just not working then you need another way to do it.

Most suggestions on the VMWare forums are to do a storage vMotion to another data store. If you don't have another datastore or vmotion abilities then you're screwed and left with a fat disk. I managed to work around this by exporting a NFS share on my physical disks through a guest. I then connected to this as a datastore in ESXi.

Simply moving your files backwards and forwards will not fix this for you. You need to first copy your vmdk files over to your NFS datastore and then using SSH do a thin clone back to your original store:

vmkfstools -i /path/to/nfs/datastore/copy.vmdk -d thin /path/to/original/datastore/shrunk.vmdk

The copying back will only write the data needed providing you with a nice shrunk virtual disk. You can then delete the original fat image and then either reattach the new one to your VMs or rename it in SSH.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.