How to Shrink VMDK Virtual Disk Size on VMWare ESXi
Overview
Expanding the capacity of VM disks is easy, but shrinking their size is not straightforward on VMWare ESXi GUI.Here, we will perform an action to reduce the disk size on VMWare ESXi using the command line.
Step-by-Step Guide
1. Shutdown the VM
Power off the virtual machine that contains the virtual disk you want to shrink and note that all snapshots of the VM need to be deleted before starting the action.
2. Enable SSH service on VMWare ESXi
3. Shrink VMDK Size on VMWare ESXi
Login to ESXi SSH console via Putty or other SSH client software.
Enter the VM storage directory (e.g., "/vmfs/volumes/Datastorage/
").
Edit the file named "hostname.vmdk
" using a text editor (e.g. vi VM_TEST.vmdk
).
In this case, the edited file was "VM_TEST.vmdk
".
Locate the "# Extent description
" of the content, which is shown below:
# Extent description
RW 209715200 VMFS "VM_TEST-flat.vmdk"
Suppose the VM's HDD current size is 100GB, which is equivalent to 209715200 of content. We would like to reduce the size by 40GB, which means shrinking it to 60GB. The new content number is "209715200 - (40*1024*1024) = 125829120".
Update the content of VM_TEST.vmdk to:
RW 125829120 VMFS "VM_TEST-flat.vmdk"
Save and close the text editor.
4. Start the VM
Power on the virtual machine and log in to the guest OS.
Open the "Disk Management".
The volume size is still 100GB, so take a "Shrink Volume..." action of the virtual disk.
Now, the virtual disk has been successfully shrunk to the new size.
5. Fix the Display Size (Optional)
Issue:
The STORAGE of the instance still displays 100GB, but the actual size has been shrunk to 60GB.
Solution:
To fix this, export and import the VM by OVF TOOL
.
Export the VM
ovftool.exe vi://root:"P@ssw0rd"@vms01/VM_TEST c:\tools\VM_TEST.ova
Import the VM
ovftool.exe --sourceType=OVA -n=VM_TEST -ds=Datastorage "c:\tools\VM_TEST.ova" vi://root:"P@ssw0rd"@vms01
Conclusion
To shrink the size of a VMDK virtual disk on VMWare ESXi using the command line. The guide is easy to follow but caution should be exercised and backups should be made before proceeding with the steps.
Una delle peggiori guide , in più incompleta , presente sul web...non è facile aver questi due primati insieme.
Stefano 2024-08-13 07:54
I'm confused. How does 100GB = 209715200 of content if 100*1024*1024 = 104857600? 209715200 is double that.
Note, I'm seeing the same in my own tests, but I'm just not understanding why the numbers are double what I'd expect.
Matthew McDonald 2023-12-12 02:11
Because the formula is wrong.
The correct one is: 100*1024*1024*1024 / 512, and than everything suits well.
NIjebitno Kijeto 2024-05-16 17:41