15 June 2009

How To Shrink VMware Virtual Disk Files (.vmdk) (Windows OS installed as Guest).

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"



Follow ITstuff.ca on Twitter

If you enjoyed this post consider subscribing via rssrectangle ITStuff.ca | Tips and Tricks for IT Staff or ITStuff.ca | Tips and Tricks for IT Staff Email


Bookmark and Share ITStuff.ca

5 comments:

  1. Pretty cool ! Thanks, I'll try it (have a couple of VMs that will be a lot lighter in space occupation.

    ReplyDelete
  2. very useful and there are tricks for unix as well (sdelete equivalent). Just be aware that this usually hammers the undelying disk during the procedure. If you can not sustain thedisk crunch, tread lightly.

    ReplyDelete
  3. Thanks for the good post. Here's the Linux/Unix solution http://www.howtoforge.com/how-to-shrink-vmware-virtual-disk-files-vmdk which I used to shrink a 30GB VM disk down to 5.5GB.

    Just doing the Windows VM right now.

    ReplyDelete
  4. Great article. I think ideals data room service will help to solve your problem!

    ReplyDelete