Posted by: Michael Khanin
shrink, virtual disk, vmdk
Recently I worked on building VM Appliance and when I was ready to convert my VM to appliance I’ve figured out that virtual disk is too big. So, I did what I usually do in this situation. And now I’d like to show how you can shrink the virtual disk files of your VMware virtual machines so that if you zip them, they will use much less space. It is then easier to upload and share them with other people.
Yes, I know, many of you now said “Misha is going to talk about Shrink”. You know what, you pretty true, but …
Everybody knows What the “shrink” does. Shrink removes an empty space from .VMDK file.
However, the problem is this: What is empty space?
When Windows deletes a file, it doesn’t actually delete the data on the disk, it just deletes the references/pointers in the file allocation table. So when “Shrink” is processing a vmdk and is looking at the raw disk, it’s seeing values that aren’t empty (non-zero), and exports them as such.
You can easily test this out. Create a new vmdk on a VM. Export the VMDK right after you’ve created it. The exported files will be very small. Now fill the vmdk up with files and export; it will be very big. Now, delete all the files in the vmdk and export; it’ll still be big! If you will try to do a “Shrink”, you will see that the vmdk file is still big.
So, before doing a Shrink, I’m always using a really cool command line tool developed by Mark Russinovich, SDelete. Simply, execute SDelete with parameter -c inside running Virtual machine, then shut down the Guest and do a Shrink.
Last note. Just in case you forget how to do a shrink . From command line go to C:\Programme\VMware\VMware Server\ and execute the vmware-vdiskmanager.exe as shown in following example:
“C:\Programme\VMware\VMware Server\vmware-vdiskmanager.exe” -k “ITSTUFF-SRV-1.vmdk”