Shrink VMDK Virtual Disk Size on VMWare ESXi – How to do it

por | 6 diciembre, 2021

Reduce the VMDK File Size of the VMWare Virtual Machine

In order to reduce the size of the VMDK file on the VMWare VMFS file system, our Support Techs suggests the following steps:

  1. Initially, we shut down the virtual machine we want to reduce disk size.
  2. Via SSH, we connect to the console of the ESXi host the VM is registered on
  3. Then we go to the directory the VMDK file of our VM is located in:cd /vmfs/volumes/datastore/test-VM
  4. We display the contents of the virtual disk configuration file (*.vmdk) using the cat command:# cat test_vm_3.vmdk
  5. The size of the vmdk disk is shown in the #Extent description section.
  6. To reduce the VMDK disk from 80 to 40 GB, we have to specify 83886080 in the Extent description section. Set the new size of the virtual disk using a text editor.
    For example,# vi test_vm_3.vmdk
  7. From the down arrow key, go to the line containing the disk size. Specify the new size, save the changes and close the file.
  8. Then we clone or migrate the virtual machine to another datastore. Once we move the virtual machine files, the new size of its virtual disk will display in its properties.
  9. Ensure the new size displays in the VM properties.
  10. Then start the VM, log in to the guest OS, and make sure that the unallocated area has disappeared and the disk size has been reduced.

  • Firstly, you need to log in and connect to the VMware vSphere Host ESXi server, which hosts the virtual machine.
  • Then, power OFF the Virtual Machine, to change to the data store path where the VMware virtual machine disk (VMDK) is located.

cd /vmfs/volumes/<datastore name>/<VM foldername>

Now, change the *.vmdk. It is the descriptor file and has the variables for the size of the *.-flat.vmdk. with the help of a cat. These are some things, which is a descriptor file contains:

  • The number highlighted above, under the heading #Extent explanation
  • After the letters, RW shows the VMware virtual disk (VMDK) size.

This value- 104,857,600 and it’s calculated as follows:

50 GB = 40 * 1024 * 1024 * 1024 / 512  =  104,857,600

We wanted to reduce the size of the VMware virtual machine disk (VMDK) from 50 GB to 25GB. Therefore, the value we need to enter into the descriptor file is-

25 GB = 20 * 1024 * 1024 * 1024 / 512 = 52,428,800
Now, you need to change the value of descriptor file with the help of vi and change the number from 104,857,600 to 52,428,800. Once you have done that click on the option of saving. With this, the process to reduce virtual machine size will be finished.