Shrinking Dynamic Virtual Disks
Recently I have gotten into virtualization and one amazing thing about virtual disks are their ability to dynamically grow. However once your disk reaches a certain size you may think you are unable to shrink it. This, fortunately is not true you CAN shrink your dynamically expanding or "Thinly Provisioned" disk space.
The following is an example of shrinking a dynamic disk for VirtualBox but I am sure there are methods for many of the other virtualization platforms.
Step 1 - Defragment the disk
In windows XP the process would be Start -> All Programs -> Accessories -> System Tools -> Disk Defragmenter.
This allows the drive to re-organize the files to cram them closer together so you can shrink your disk smaller
Step 2 - Zero out the free space
Zeroing is a process of writing zeros to a hard drive in order to wipe any remnants of data that may be left on the disk.
The way dynamic expanding works is it expands to the size where it thinks data is. So if you remove that data it feels that there is still data there as it is not actually zeroed out after deletion.
Zeroing can be achieved through using the following program: sdelete
The command used is:
sdelete -c c:/
Step 3 - Use the VBoxManage tool to compress the resulting zeroed space
cd to the location of your hard drive that virtualbox is installed to and run the following
VboxManage.exe modifyvdi /path/of/virtual/machine.vdi compact
Make a clone if this does not work
VboxManage.exe clonehd original.vdi clone.vdi