script to recalculate vmware disk size

#!/bin/bash
# Recalculate vmware thin disk size

# Creates zero-block file in all free disk space 
for i in $(df | grep '^/dev/' | awk '{print $6}'); do
  if [ $i == '/' ];then
    echo 'creating a file of blocks zeroed in:' ${i}zerofile
    dd if=/dev/zero of=${i}zerofile bs=4096; rm -f ${i}zerofile
  else
    echo 'creating a file of blocks zeroed in:' $i/zerofile
    dd if=/dev/zero of=$i/zerofile bs=4096; rm -f $i/zerofile
  fi
done

After run the command with the machine turned off in ESXi Host

vmkfstools --punchzero /vmfs/volumes/path-to-disk.vmdk
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s