Compression of the vmdk file of the VMware virtual machine under Windows

To play virtual machines under Windows, generally everyone will install VMware software, and then install other operating system environments (such as Linux) through software to simulate various server environments. However, you can find such a problem during the use process, that is, the vmdk file in the disk directory of each operating system corresponding to the host will become larger and larger. Even if the disk size is cleared in the virtual environment, the vmdk file in the Windows host is still There is no change, so more and more host resources will be occupied, and eventually the virtual system will fail to start.

The first step is to clean up virtual system resources

Start the virtual system Linux, delete useless files in the disk, and clean up the root directory space.

Before cleaning, it is as follows:

After cleaning it is as follows:

But check the disk size occupied by the directory under the host system Windows, you can find that it is still the same.

Second step, zero fill unused space

Executing the fill command on the virtual system Linux zero-fills any unused space so that VMware can know that the space is indeed unused.

cat /dev/zero > zero.fill

Executing this command will fill all the unused space in the Linux system with 0 and generate the file zero.fill. After the execution is completed, the system will prompt a write error, and the system has no space available.

cat: write error: No space left on device

Use the df command to check the disk situation, you can see that it is full.

Delete the generated zero.fill file to restore the disk size to its pre-fill state.

So far, it can be seen that the disk size occupied by the directory under the host system Windows is still the same.

Turn off the virtual system Linux, and return to the host system Windows to perform the third step.

The third step is to compress the vmdk file

Open the cmd command window, find the installation directory of VMware, and execute the following command to compress the vmdk file.

cd C:\Program Files (x86)\VMware\VMware Workstation

vmware-vdiskmanager.exe -k "F:\soft\cluster\test1\test1.vmdk"

After successful execution, the result is as follows:

C:\Program Files (x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe -k "F:\soft\cluster\test1\test1.vmdk"
  Shrink: 100% done.
Shrink completed successfully.

Check the disk size occupied by the directory under the host system Windows again, and you can find that it becomes smaller instantly.

Good Luck!

Guess you like

Origin blog.csdn.net/tzhuwb/article/details/130660824