I'm facing a strange issue with my virtual machine. I have an rhel 6.1 guest os running on VMware workstation (9.0.2 build-1031769) hosted on Windows 7 Enterprise 64 bit. The size of the vmdk file is around 65 GB whereas the total size of the guest os is only 11GB. What am I missing here ?

[root@praveenVM praveen]# df -h 
Filesystem        Size      Used  Avail  Use%  Mounted on
/dev/sda3         95G        11G   79G    12%   /
tempfs            499M      340K  499M     1%   /dev/shm
/dev/sda1         124M       61M   58M    52%   /boot

There was some temporary files in /var (Unnecessary logs), which I have deleted now and hence the used space is around 11GB. But why is that the vmdk file is around 65GB ? Having deleted all the unnecessary files in the Guest OS, the size of the vmdk should automatically decrease right ?

  • 1
    VMWare does not shrink the vmdk automatically. Only expand. How large did you create the original virtual harddisk? Did you allow dynamic expanding (sparse) when creating it? If so you can read here how to decrease it. You might need to run a defragmenter first. – Rik Oct 25 '13 at 7:43
  • You can also try right clicking on the VM going to manage and select "Clean up Disks..." pubs.vmware.com/workstation-9/… – JamesTheDev Oct 25 '13 at 12:23
  • Tried the cleanup disks option. But, I get the message "Cleanup is not necessary" – psteelk Oct 27 '13 at 5:49

All I did is re-import the VM into the workstation.

| improve this answer | |

It appears that VMware isn't able to do much to compact ext4-formatted drives. The solution is that you need to fill the drive with zeroes and then delete a file that you used to do that.


sudo su
cat /dev/zero > wipefile; rm -f wipefile
shutdown -h now

Basically, you become root, you create a file filled with zeroes and then you delete it and shutdown the machine.

I ran the above code a moment ago, and watched a few things as I did:

  • I suspected the vmdk file would grow to the size of the disk, but it didn't. It grew slightly, but not much. This was good because my host does not have space for the full vmdk file.
  • I suspected drive on the guest would fill up. It did. I watched it with:

    while :
      du -h
      sleep 2

The guest disk started at about 15% full, then climbed to 100%, at which point the cat command failed and the wipefile was rm'ed, bringing it back to 15% full.

I've seen a few posts that also say you should do this for /boot. Probably a good idea, but I don't think it's always necessary.

Once that's complete, go into the machine's settings > Hard Disk > Utilities > Compact..., and you should be all good.

| improve this answer | |
  • 2
    You can use the watch command instead of the while loop, less typing: watch -n2 "du -h". But I prefer an update every second: watch -n1 "du -h" – user423381 Feb 27 '15 at 19:15
  • I might be running into this issue specifically because my VM has an ext4-formatted volume. Do you know if there are other partition formats that are more easily managed by VMWare? I currently have a ~31GB VMDK file that's housing ~11GB worth of data, and can't find a way to shrink it. The zeroing process is my next approach, but it's not very convenient. – Craig Otis Apr 6 '17 at 11:08
  • Sorry, no idea. I suspect Windows file systems are better known to VMware, but at this point I forget the research I did for this post. – mlissner Apr 6 '17 at 13:25
  • 1
    No worries, figured it was a long shot. I ended up shrinking it by zeroing the empty space (via running in the VM cat /dev/zero > zerofile; rm zerofile) and then running the defrag and compact processes using the command line tool, as the GUI buttons didn't seem to really do anything. – Craig Otis Apr 6 '17 at 13:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.