How to reduce the size of VMware disk
My Ubuntu image VMware disk has grown to 5GB physical file size. It's a dynamically growing disk with the maximum capacity of 8GB. I cleaned some stuff inside Linux distro and now inside it occupies 3GB. Obviously the physical file size didn't shrink back automatically. Is there a way (if possible free of charge) to shrink this disk back to ~3GB?
I need this to fit the image on the DVD.
There are three steps:
-
Defragment (no need to un/remount anything)
sudo e4defrag /
Ignore any errors. Some files like symlinks and device files can't be defragmented.
-
Zero-fill all unused space so VMware knows it's indeed unused:
dd if=/dev/zero of=wipefile bs=1M; sync; rm wipefile
-
Run the shrink operation:
sudo vmware-toolbox-cmd disk shrinkonly
I've found the solution – you have to compact your hard drive:
Virtual Machine - Settings - General - Clean Up Virtual Machine
Open VMware Toolbox in the guest (as root) and shrink the disk. (Documentation)
If you don't have VMware Tools, you can shrink the disk manually in two steps. First, clear the free space on the virtual disk using a tool like zerofree. Zerofree is available in Ubuntu, but since it requires the guest OS filesystem to be mounted read-only you may want to run it off a live CD. Parted Magic reportedly includes zerofree.
After zeroing the free space, open Virtual Machine Settings and compact the virtual disk.