I use VMWare Server on several different computers to run virtualized Linux webservers for developing websites and for testing various versions of Internet Explorer. I recently needed to reduce the size of a Linux virtual disk to fit it onto a USB stick to copy to another machine but simply deleting files does not reduce the size of the disk image. This post links to another article offsite which shows how to do this and adds a couple of notes about it.
How to shrink VMware virtual disk files (.vmdk)
The first thing to do is to delete all the big files you do not need. As I noted above this will not actually make the vmdk files any smaller so a command line tool on Windows called vmware-vdiskmanager.exe or on Linux called vmware-vdiskmanager needs to be run to shrink the virtual disk files to reclaim unused space.
The process about how to do this can be found in the article how to shrink VMware virtual disk files (.vmdk) at HowtoForge.
When I first followed the instructions there I didn’t read all the steps fully and missed out running the “cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill” command on the Linux guest. This is a critical step. If the command is not run then the virtual disk files will be the same size after the vdiskmanager command has completed running.
Once the free space is zeroed out (which doesn’t take very long) and the vdiskmanager command is run on the shut down guest’s virtual disk the files will be reduced to just that actually used by the virtual machine.
When I ran this myself, I reduced the size of my virtual disk files from 10.9GB to 5.1GB, the latter being more or less what “df -h” was reporting inside the virtual machine.