VMware Virtual Machine Disk Space Optimization

When installing a development system with VMware virtual machines, it’s generally recommended to allocate extra disk space. Over time, the local disk space consumed by the VM will far exceed the actual size of its files.

Scenario Description

The df -h command revealed that the current machine was using 60GB of disk space, and after deleting all snapshots and clone images, the local virtual machine still occupied significantly more than 60GB, further straining the already limited hard drive.

Prerequisites

  • When installing the virtual machine, do not select “pre-allocate disk.”
  • The local hard drive where the virtual machine is stored must have sufficient free disk space greater than the currently used space of the virtual machine.
  • If there isn’t enough space, consider temporarily moving the virtual machine to a portable hard drive, optimize the disk, and then migrate it back.

Tools

The official provides the open-vm-tools package, which can be installed via yum or by installing the VMware-Tools image package.

Commands

vmware-toolbox-cmd disk shrink /

After execution, the virtual machine will automatically shut down, and the VMware host program will perform disk compression. The execution time depends on the volume of the virtual machine and the speed of the disk access.

The effect is quite good; the disk space occupied by the virtual machine is essentially equal to the disk information as shown in df -h.

Licensed under CC BY-NC-SA 4.0
Last updated on Jun 02, 2025 20:54
A financial IT programmer's tinkering and daily life musings
Built with Hugo
Theme Stack designed by Jimmy