Shrink a thin-provisioned VMDK

If you’ve thin-provisioned a VMDK under ESXi and need to reduce it for whatever reason, the official VMware documentation suggest to migrate the VM to another datastore using VMware converter which is not always practical, thankfully an alternative exists.

If you have enabled Change Block Tracking (CBT) be sure to disable it by adjusting the ctkEnabled option on the virtual machine and consolidating disks before you begin.

To reclaim space you need to fill all unallocated space with zeros. On Windows you can use SDelete or the following command on Linux:

cat /dev/zero > zero.dat;sync;sleep 1;sync;rm -f zero.dat

Once the space has been filled with zeros you can shrink the partition as required. I usually use GParted for this. With your partitions shrunk the next step is to reclaim the space, shut-down the VM and SSH into your ESXi host. “CD” to the directory containing the VM and identify the file you need to shrink for example:

# cd /vmfs/volumes/SXi01-local/SRVGEN02
/vmfs/volumes/53930418-064abd7c-45c9-002590dbfde4/SRVGEN02 # ls -lsah
total 119558160
     8 drwxr-xr-x    1 root     root        2.6K Feb 21 11:01 .
  1024 drwxr-xr-t    1 root     root        2.6K Jan 15 13:27 ..
  8192 -rw-------    1 root     root        7.5M Feb 21 11:00 SRVGEN02-000001-ctk.vmdk
  1024 -rw-------    1 root     root      244.0K Feb 21 11:00 SRVGEN02-000001-delta.vmdk
     0 -rw-------    1 root     root         387 Feb 21 11:00 SRVGEN02-000001.vmdk
  8192 -rw-------    1 root     root        7.5M Feb 21 10:59 SRVGEN02-ctk.vmdk
119531520 -rw-------    1 root     root      120.0G Feb 21 10:59 SRVGEN02-flat.vmdk
  1024 -rw-------    1 root     root        8.5K Feb 21 10:59 SRVGEN02.nvram
     0 -rw-------    1 root     root         589 Feb 21 10:59 SRVGEN02.vmdk
     0 -rw-r--r--    1 root     root          77 Feb 21 11:01 SRVGEN02.vmsd
     8 -rwxr-xr-x    1 root     root        3.0K Feb 21 11:00 SRVGEN02.vmx
     0 -rw-r--r--    1 root     root         263 Jan 17 13:55 SRVGEN02.vmxf
  1024 -rw-r--r--    1 root     root      353.9K Feb 21 10:52 vmware-10.log
  1024 -rw-r--r--    1 root     root      182.9K Feb 21 10:59 vmware-11.log
  1024 -rw-r--r--    1 root     root      182.2K Feb 19 18:53 vmware-6.log
  1024 -rw-r--r--    1 root     root      182.3K Feb 19 19:01 vmware-7.log
  1024 -rw-r--r--    1 root     root      182.3K Feb 19 19:10 vmware-8.log
  1024 -rw-r--r--    1 root     root      183.2K Feb 21 10:46 vmware-9.log
  1024 -rw-r--r--    1 root     root      104.2K Feb 21 10:59 vmware.log

Next, run “vmkfstools –punchzero DISK_NAME.vmdk” to actually shrink the file. How long this takes will depend on the underlying storage, on a reasonably fast SSD this took less than ten minutes for me to shrink 110GB:

/vmfs/volumes/53930418-064abd7c-45c9-002590dbfde4/SRVGEN02 # vmkfstools --punchzero SRVGEN02.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 100% done.

Cisco Device Info now open source

Cisco Device Info, my popular SNMP application for getting information from Cisco network devices has now been released as free software. It is now free to use at home, and in commercial environments. Further to that change I have licensed the software under the LGPL 2.1, allowing developers to contribute to the code and make changes of their own.

The sourcecode has been hosted at Github and is available from its public repository.

Controlling a British Gas WR1 Receiver with an Arduino

Over the holiday season I started looking at whether my boiler, a Worcester Bosch Greenstar 28i, was compatible with the Nest thermostat. After some Googling I began to wonder whether I could make my own controller and began investigating how the existing wireless programmer might function. The programmer currently in use is a British Gas WR1, which looks to be a re-branded Drayton Digistat device.

British Gas WR1

After removing the programmer from its wall mounting plate I immediately noticed a sticker indicating it operated using 433MHz. Thankfully this is part of the unlicensed spectrum meaning transmitters are likely to be readily available. Sure enough, there are 433MHz transmitter/receiver pairs available in the UK for just £2 on eBay. I immediately bought myself an Arduino, some cables, a breadboard and waited eagerly for everything to arrive.

My plan was to create a single channel logic analyser as described in Steven Hale’s excellent blog post, using the soundcard in my laptop to capture what my existing programmer transmits. My soldering ability leaves a lot to be desired, so I’ll spare you a photo and include a diagram that is likely to be much more useful:
Sound card logic analyser
Continue reading Controlling a British Gas WR1 Receiver with an Arduino