Thursday, October 04, 2012

shrinking a "growable" VMware disk (VMDK file)

Just a quick note on shrinking VMware VMDK files.  In short, it's an option WITHIN the VM guest, under VMware Tools or through vdiskmanager command line:
http://www.vmware.com/support/ws5/doc/ws_disk_shrink.html

















or a command like:
"C:\Program\VMware\VMware Server\vmware-vdiskmanager.exe" -k "XP.vmdk"

Backstory
I noticed my XP VM had ballooned to 200GB on the filesystem.  Woah!
[sodo@computer ~]$ ll Virtual\ Machines/XP
total 351188880
drwxr-xr-x. 3 sodo sodo        4096 Jul 25  2011 caches
--rw-rw-rw-  1 sodo sodo 199013260658 Oct  4 13:35 XP.vmdk


The size of single logical C: partition was set to 232GB and it utilized about 1/2 of that in actual files (about 120GB).  Wow.  Bloated!  I had to do something, but quick.  Here's what I did:
1) deleted all extraneous files (~45GB)
2) as I'll be migrating to Win7 soon, I deleted all my XP Hotfix uninstall directories.  This yielded an inCREDible 5GB of data..just in uninstall files!
3) defragged my XP guest

Resize NTFS and Create a Partition
At this point, there was about 45GB left in actual files.  I decided to do two things using gParted
1) resize the NTFS partition down as much as possible with room to spare for other files
2) create a second partition out of the blank space left over.  I did this because VMware Tools can't shrink empty partition space.  See a deeper technical discussion under "Disk Space" on this page.

1a) The resize from 232GB down to 74GB:






























2) Create a new partition



























My Shrink!
Once these two steps were completed, I was then able to go back and perform the shrink within the VM guest using VMware Tools, Shrink tab:

















The shrink took about two hours, but once completed, I was left with a 47GB VMDK!

[sodo@computer ~]$ ll Virtual\ Machines/XP
total 51222880
drwxr-xr-x. 3 sodo sodo        4096 Jul 25  2011 caches
--rw-rw-rw-  1 sodo sodo 49013260288 Oct  4 13:35 XP.vmdk


Awesome!
TAG

References

Feel free to drop me a line or ask me a question.