VMware

VMware treadmill process

In my VMware environment I have several VMs that have very large VMDKs, but are only using a small portion of that space. These are referred to as “THICK” disks. I would like to reclaim that unused space and turn them into “THIN” disks, which means I need some kind of a treadmill process to thin them out.

Various googling shows some examples of using VMKFSTOOLS to clone the disk into a thin provisioned copy, delete the source, then rename the new disk to replace the original. But this misses 2 key requirements: 1) Ensuring the system is offline before starting, 2) Performing the task on all available systems at once. For this, we need a couple other steps.

Identifying offline systems and VMDKs
Using the VI Toolkit powershell extension, I can run the following command on a single line
get-vm | where {$_.PowerState -eq ‘PoweredOff’} | get-harddisk | export-csv d:tempfoo.csv
This exports all the systems and drives into a CSV file that can be opened in Excel and massaged as necessary. Change the path name from [Datastore] /path to /vmfs/volumes/datastore/path.

Creating a script to thin out the disks
Now we need a script that will put a specified disk on the treadmil.
#!/bin/bash

E_BADARGS=65

if [ ! -n “$1” ]
then
echo “Usage: `basename $0` vmdkpath”
exit $E_BADARGS
fi

echo “Copying file $1”
vmkfstools -i $1 $1.thin -d thin
echo “Deleting file $1”
vmkfstools -U $1
echo “Renaming file $1”
vmkfstools -E $1.thin $1
exit 0

Using VI, save this file to the VMware host (i.e. putty into the host, create the file and save the contents). Use chmod +x treadmill to mark the file as an executable. Now all that remains is to queue up the disks to change.

Execute
Open notepad and paste in all the paths from the Excel spreadsheet. At the beginning of each line, add a call to the treadmill script so that it looks like the following
./treadmill /vmfs/volumes/datastore1/server1/server1.vmdk
Once all the lines look like this, simply copy and paste them into your existing putty session. This will go through each VMDK, create a thin copy, delete the original, and rename the new to the original. This could take a long time depending on the size and number of disks

One thought on “VMware treadmill process

Leave a Reply