In this article we will show how to reduce the size of a virtual disk (vmdk) file of the virtual machine running on VMWare ESXi. Unlike expanding a disk of a VMWare virtual machine you can do on-the-fly without shutting the virtual machine down, it is more complicated to reduce the size of a vmdk file on the VMWare ESXi hypervisor, and you cannot do it via the vSphere Web Client graphical interface. The vSphere Client doesn’t allow you to specify a smaller virtual disk size.
Prior to reducing the size of a virtual disk, do the following on your VMWare ESXi host:
- Delete all snapshots of the virtual machine (otherwise, you may damage the virtual disk);
- Create a full backup of the virtual machine, or create a copy of the vmdk and flat files you want to shrink. Use these commands:
cp vmname.vmdk backup_vmname.vmdk
cp vmname-flat.vmdk backup_vmname-flat.vmdk
The procedure of reducing 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?
First of all, reduce the size of the disk partition in the guest operating system. If your virtual machine is running Windows OS, use the Disk Manager
diskmgmt.msc (the Shrink Volume operation is available in all supported Windows versions;
sdelete tool is used in older Windows versions to reduce the partition size) or third-party tools (like Acronis Disk Director). If you don’t do it, after then your file system may crash after shrinking the virtual disk size.
Suppose, you want to reduce the disk size by 40 GB. So the volume size must be reduced by 40960 MB (
40 GB x 1024). Enter this value in the corresponding field of the Shrink Volume wizard. After reducing the partition size, there will be some unallocated space (40 GB in our example) to the right of your partition.
Reduce the VMDK File Size of the VMWare Virtual Machine
Then reduce the size of the VMDK file on the VMWare VMFS file system.
- Shut down the virtual machine you want to reduce disk size;
- Using SSH, connect to the console of the ESXi host the VM is registered on (you can use putty or the built-in Windows SSH client);
- Go the directory the VMDK file of your VM is located in (you can get a path to it in the virtual disk properties of the vSphere client):
- 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 (after the RW characters). In this case, it is 167772160 (
80 GB *1024*1024*1024 / 512);
- I want to reduce my VMDK disk from 80 to 40 GB. It means that I have to specify 83886080 (
40 GB*1024*1024*1024 / 512) in the Extent description section. Set a new size of your virtual disk using a text editor (vi or nano);
- I am using vi:
# vi test_vm_3.vmdk
- Using the down arrow key, go to the line containing the disk size and press
i(to edit it). Specify the new size of the virtual disk. Press ESC to exit the edit mode and then type
:wq-> Enter to save the changes;
- Then just clone or migrate (using Storage vMotion) the virtual machine to another datastore. After moving the virtual machine files, the new size of its virtual disk will be displayed in its properties.Tip. If you have only one ESXi host, one VMFS datastore, you won’t be able to use the Storage vMotion. Then you can clone vmdk using this command:
vmkfstools -i test_vm_3.vmdk test_vm_3_newsize.vmdk
Remove the source VMDK disk, clone the reaming VMDK disk again and rename it by specifying its original name:
vmkfstools -i test_vm_3_newsize.vmdk test_vm_3.vmdk
- Make sure that the new size of the virtual disk is now displayed in the VM properties.
- Then start the VM, login the guest OS and make sure that the unallocated area has disappeared, and the disk size has been reduced.
- Reducing the virtual disk size by converting a virtual machine using VMware vCenter Converter. Specify a disk size smaller than the source one to convert it (we will show it in the next section);
- You can clone virtual disk contents using third-party software (like Acronis True Image or Symantec Ghost32). This task in performed by adding a new smaller disk to the virtual machine and cloning the contents of a larger disk to it. You can remove the larger disk then.
Shrinking a VMDK Using VMware vCenter Converter Standalone
Another way to reduce a virtual disk size of a VMWare virtual machine is to use a free GUI tool VMware vCenter Converter Standalone.
- V2V conversion is slow;
- There must be enough space on the datastore to save the new VM;
- The new virtual machine will have a new MAC address.
- You don’t need to open the vCenter or ESXi host console;
- An exact copy of a VM is created;
- The source disk cannot be damaged in case of any errors in conversion task settings.
Specify the ESXi host address.
Select the source VM.
Set the parameters of your new VM.
Go to the disk edit mode (Data to copy -> Edit).
Select the copy mode: Select volumes to copy.
Specify the new disk size for your new VM. As you can see, 48 GB is occupied in the guest OS, and the disk size is 150 GB. We will reduce the size of the virtual disk to 60 GB.
Run the VM conversion process. Then you can power off the source VM and power on the new one. Make sure that the disk size has been reduced. After that the original VM may be removed.