Reclaim thin provisioned disk – Windows

A couple of days back I wrote a post where I reclaimed wasted disk space on a Solaris JumpStart virtual appliance. I thought; “I do have a couple of Windows based virtual machine templates where this might work”. The background info is the same as the previous post so I’ll move straight to the “doer” part.

For this post I preparing a Windows XP VM with 20GB c: drive and 10GB e: drive and I’m going to use the e: drive in this example. Before adding any data to the VM is using <4GB disk even though it has 30GB provisioned. (The additional GB is the VM swap file).

Lets start adding data.

I have added two iso files to the e: drive. As we can see the used space has increased accordingly.

Lets delete one of the ISO files and see what happens.

Yeah, the e: drive got some more breathing space, but the used storage is still the exact same as the one about. Why is that? Well, the same applies here as with the Solaris JumpStart server; When a file is deleted from the file system, the blocks on the disk still contains data, but the pointer is removed. This is why it is possible to recover deleted files from a hard drive. To “free” the wasted blocks, we need to zeroize the blocks.

Many suggest using SDelete from Sysinternals (Microsoft) to do this. It is a command line tool that works perfectly, if you’re zeroizing the c: drive. In my case I’m trying to zeroize my e: drive and there is a bug in SDelete 1.6 that ignores the driver letter parameter. On one of my templates I did this using SDelete and it just works. I observed that a file was created directly on c:\ that got very large during run and got deleted at the end, pretty much the same as doing a dd from /dev/zero.

Due to the bug in SDelete, I decided to try dd for Windows from chrysocome.net instead. It works just like dd on unix using virtual devices for /dev/zero since that device does not exist on Windows.

I decided to go with version 0.5. Downloaded, extracted to c:\ and executed the dd command to fill my e: drive with zeroes.

The e: drive contains a file full of zeroes and the operating system reports that the drive is full. Zeroes in a file is valid data as well, so to free the wasted space from the OS, delete the file.

c:\dd-05\>del e:\dd.file

The OS reports that there is available disk space on e: now, but on the datastore the VM is  still using the blocks. Use vmkfstools free the zeroized blocks on the datastore. Before executing vmkfstools the VM have to be shut down. Power off the the VM and open a shell on the ESXi host. I’m using ssh. I added an additional disk to show this procedure and I need to identify this disk.

The .vmdk file is the configuration file for the virtual disk and the -flat.vmdk is the actual file. Execute the vmkfstools command with the -K option and provide the full path to the .vmdk file as parameter.

~# vmkfstools -K /vmfs/volumes/Local_SSD_Dell/xp-x86-relcaim/xp-x86-reclaim_1.vmdk

And voila, have a look at that! I’m down to approx 6GB again which is the c: drive and one .iso file on the e: drive.

This is how the wasted thin provisioned datastore usage can be reclaimed on a Windows based virtual machine. I have done this on both Windows XP and Windows 7 with the same result.

Good luck reclaiming disk space.