When installing a VMware virtual machine development system, it’s common practice to reserve extra disk space. Over time, the local disk space occupied far exceeds the actual content of the virtual machine files.
Scene description
The df -h
command shows the disk information of the current machine, which is actually using 60GB. After deleting all snapshots and clone images, the local virtual machine still occupies far more than 60GB of disk space, adding insult to injury for a hard drive that was already not spacious enough.
Prerequisites
- The virtual machine was installed without allocating the disk space in advance
- The hard drive where the virtual machine is stored has remaining disk space greater than the space currently occupied by the virtual machine
The remaining space is insufficient; you could consider temporarily moving the virtual machine to an external hard drive, and then migrate it back after optimizing the disk
Tools
The official provider offers the open-vm-tools
package, which can be installed via yum or through the VMware Tools ISO image
Command
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 size of the virtual machine and the access speed of the disk.
The execution result is still very good, and the virtual machine’s disk space usage is basically equal to the disk information from df -h