Unlike expanding a disk of a VMWare virtual machine, it is more complicated to shrink VMDK Virtual Disk Size on the VMWare ESXi hypervisor.
It is impossible to do it via the vSphere Web Client graphical interface. It does not allow to specify a smaller virtual disk size.
As part of our Server Management Services, we assist our customers with several VMWare queries.
Today, let us see how to reduce the size of a virtual disk (vmdk) file of the virtual machine running on VMWare ESXi.
Shrink VMDK Virtual Disk Size on VMWare ESXi
Before we reduce the size, we need to do the following on the VMWare ESXi host:
- Delete all snapshots of the virtual machine not to damage the virtual disk
- Create a full backup of the virtual machine or a copy of the vmdk and flat files we want to shrink.
cp vmname.vmdk backup_vmname.vmdk cp vmname-flat.vmdk backup_vmname-flat.vmdk
The process to reduce a virtual disk size consists of two steps:
- Shrink the partition inside the guest OS
- Reduce the size of the VMDK file of the VMWare virtual machine on the VMFS (NFS) datastore.
How to Shrink the Partition Size in the Guest OS?
Initially, we need to reduce the size of the disk partition in the guest operating system.
If the virtual machine runs Windows OS, we use the Disk Manager diskmgmt.msc or third-party tools. Failure of which may lead to a file system crash.
For instance, if we want to reduce the disk size by 40 GB, the volume size must reduce by 40960 MB (40 GB x 1024). We enter this value in the corresponding field of the Shrink Volume wizard. Once done, there will be some unallocated space to the right of our partition.
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:
- Initially, we shut down the virtual machine we want to reduce disk size.
- Via SSH, we connect to the console of the ESXi host the VM is registered on
- Then we go to the directory the VMDK file of our VM is located in:
- We display the contents of the virtual disk configuration file (*.vmdk) using the cat command:
# cat test_vm_3.vmdk
- The size of the vmdk disk is shown in the #Extent description section.
- 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.
# vi test_vm_3.vmdk
- From the down arrow key, go to the line containing the disk size. Specify the new size, save the changes and close the file.
- 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.
- Ensure the new size displays in the VM properties.
- 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.
Shrink a VMDK Using VMware vCenter Converter Standalone
GUI tool VMware vCenter Converter Standalone is another way to reduce a virtual disk size of a VMWare virtual machine.
- V2V conversion is slow
- Need enough space on the datastore to save the new VM
- The new virtual machine will have a new MAC address.
- We do not need to open the vCenter or ESXi host console
- Creates an exact copy of a VM
- The source disk cannot be damaged in case of any errors in conversion task settings.
Instead of Suspend, we have to Shut down the virtual machine we want to change the disk size.
- Initially, we specify the ESXi host address and select the source VM.
- Then we set the parameters of the new VM.
- Go to the disk edit mode (Data to copy -> Edit).
- Select the copy mode: Select volumes to copy.
- We specify the new disk size for the new VM.
- Once we run the VM conversion process, we can power off the source VM and power on the new one.
- Ensure the disk size has been reduced. After that, we can remove the original VM.
[Need help to shrink the size? We’d be happy to assist]
In short, we saw how our Support Techs shrink VMDK Virtual Disk Size on VMWare ESXi.