After playing around with different VMware Appliances and VMware Server, I noticed that the disk space consumed by the virtual machines were rapidly increasing. It's a well known fact that when a vmdk is defined you set a max disk size, and you can chose not to allocate all the disk space at once, and it'll expand the virtual disk as needed when you run the VM. All thats fine and dandy, and it helps keeping the filesize of distributed VMs low. But, what happens when you fill a virtual disk and then delete files from it again? Does the virtual disk shrink in size? No, it doesn't.
There is a perfectly logical explanation to that, as explained by rtfm-ed.co.uk
Well, when Windows deletes a file, it doesn't actually delete the data in the disk; it just deletes the references/pointers in the file allocation table. So when ESX is exporting a VMDK and is looking at the raw disk, it's seeing values that aren't empty (non-zero), and exports them as such. The result is more disk space is used and takes longer to export the disk.
VMware Workstation as well as Server and ESX server all include a tool to "shrink" a disk, but VMware Player doesn't. … I've been looking for an "offline" VMware disk shrink utility, but I'm unable to find one.
documented on: August 16, 2006
The VMWare command line utility, vmware-vdiskmanager.exe, does perform offline image shrinking. You simply issue the command "vmware-vdiskmanager -k mydisk.vmdk" (while the VM is NOT running) and it will shrink it. This utility sounds like it's included with VMWare Server (although I haven't confirmed this yet), which can be downloaded for free. If that's true, then all the necessary tools for this procedure are available free of charge.
Please note that this only covers the second step in the two step process of shrinking a virtual disk. The first step requires wiping (zero-filling) all the unused space on the disk including any previously deleted files. This step varies depending on the guest OS and must be done from INSIDE the running VM.
For Linux (and probably most *nix-like OSs), a simple series of commands can accomplish this task, such as "cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill". This will create an enormous zero-filled file that completely fills the disk and then deletes that file. In most file systems (but not all), this will zero-over all the unused disk space including anything left over from previously deleted files.
For Windows guest OSs, there are probably a lot of freeware apps that can accomplish the same thing. Note: You may want to empty out the recycle bin before zero-filling the free space to maximize the amount of space recovered.
Once the free space has been zero-filled, shut down the VM and run the vmware-vdiskmanager tool on the target vmdk file.
documented on: November 24th, 2006 by Guest