Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Virtualization / VMWare / Shrinking VMDK Virtual Disk Size on VMWare ESXi

September 15, 2022 VirtualizationVMWare

Shrinking VMDK Virtual Disk Size on VMWare ESXi

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.

Contents:
  • How to Shrink the Partition Size in the Guest OS?
  • Reduce the VMDK File Size of the VMWare Virtual Machine
  • Shrinking a VMDK Using VMware vCenter Converter Standalone

Important. This guide is not an officially supported solution on how to reduce the size of vmdk disks in VMWare. However, I used this method dozens of times. VMWare ESXi 6.7 is used in this article.

Shrink a VMware Virtual Machine Disk (VMDK)

Prior to reducing the size of a virtual disk, do the following on your VMWare ESXi host:

  1. Delete all snapshots of the virtual machine (otherwise, you may damage the virtual disk);
  2. 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.

shrink volume in Windows

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.

specify the amount of space to shrink in MB

Note that the OEM or Windows Recovery partition may sometimes prevent extending or reducing the disk.

windows partition unallocated space

In Linux, you can reduce the partition size using parted. If LVM logical volumes are used, the scenario is different.

Reduce the VMDK File Size of the VMWare Virtual Machine

Then reduce the size of the VMDK file on the VMWare VMFS file system.

  1. Shut down the virtual machine you want to reduce disk size;
  2. 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);
  3. 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):
    cd /vmfs/volumes/datastore/test-VM
    vmware vm file on vmfs datastore
  4. 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); vmware vmdk file size
  5. 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);
  6. I am using vi: # vi test_vm_3.vmdk
  7. 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; shrink vmdk file size on vmware datastore
  8. 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.vmdkvmkfstools - clone file with reducing file size
    Remove the source VMDK disk, clone the reaming VMDK disk again and rename it by specifying its original name:
    rm test_vm_3.vmdk
    rm test_vm_3-flat.vmdk
    vmkfstools -i test_vm_3_newsize.vmdk test_vm_3.vmdk

  9. Make sure that the new size of the virtual disk is now displayed in the VM properties. new size of the virtual disk is now displayed in the vmware VM properties
  10. Then start the VM, login the guest OS and make sure that the unallocated area has disappeared, and the disk size has been reduced. Shrink a Hard Drive Volume in Windows
Tip. If you have used vmkfstools in the previous step, reconnect the virtual disk in the VM settings, since its new size may not be displayed correctly.
Note. The following methods are often used to reduce the size of VMDK disks:

  • 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.

Cons:

  • 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.

Pros:

  • 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.
Note. The virtual machine you want to convert (change disk size, etc.) must be shut down (using Shut down or Power Off, instead of Suspend).

Specify the ESXi host address.

vmware converter connect vcenter

Select the source VM.

select vm to convert

Set the parameters of your new VM.

set VM properties

Go to the disk edit mode (Data to copy -> Edit).

edit disk properties in vmware converter

Select the copy mode: Select volumes to copy.

copy all disks and mainntain layuout

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.

mainttain disk size vm converter Shrink a VMDK using VMware Converter

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.

Note. In the latest versions of Microsoft Hyper-V, you can use Hyper–V Online VHDX Resize tool to dynamically resize (both expanding and shrinking) virtual disks.

16 comments
3
Facebook Twitter Google + Pinterest
previous post
How to Run Windows File Explorer Elevated (as Administrator)?
next post
Mapped Network Drives are Not Showing in Elevated Programs

Related Reading

Reset Root Password in VMware ESXi

October 12, 2023

How to Fix ‘An Operating System Wasn’t Found’...

July 14, 2023

Unmounting an NFS Datastore from VMware ESXi

April 21, 2023

How to Increase Virtual Machine Disk Size in...

April 6, 2023

How to Install Free VMware Hypervisor (ESXi)

January 24, 2023

16 comments

T ray June 15, 2021 - 5:24 pm

Thanks for article. Note that ssh won’t connect to the ESXi host by default for security purposes.
https://kb.vmware.com/s/article/1019852

Reply
Rohan June 19, 2021 - 11:42 am

For some reason i do not get that second option on my VMware vCenter Converter Standalone. Dont know if that is a license thing or something else. Do i perform same procedure for a linux vm ?

Reply
Kevin August 3, 2021 - 4:08 pm

Thank you! better service than some premier support I won’t mention

Reply
Robert August 12, 2021 - 4:36 pm

Thank you for this helpful article. I’ve used it a few times now. Some comments:
– It seems like the “Pros” and “Cons” above are transposed
– If you use vVols in your environment, you may wish to move the VM to regular storage first as resulting VM may not tolerate snapshots
– I usually shrink the drive in Windows more than needed, then come back at the end and expand it just to be safe

Reply
laxrosse August 31, 2021 - 11:59 pm

Successfully shrunk my HDD, thanks!
But there is still unallocated space.
How can I delete it?
I’ve tried reconnecting the HDD in the VM settings.

Reply
laxrosse September 1, 2021 - 12:38 am

I converted the VM with the remaining unallocated space into a template.
The unallocated area disappeared from the deployed VM.
I think I’ll deal with this for now.
Sorry for the inconvenience.
– use translation tool

Reply
max September 1, 2021 - 8:50 am

Perhaps you just needed to refresh the data in the disk management console.

Reply
PacoBell January 28, 2022 - 11:17 pm

This worked amazingly well. It’s just too bad it only works on offline VMs. If there was a way to do this online, that would be wizard!

Reply
bclaesen March 8, 2022 - 12:31 pm

After having shrinked one of the disk of a VM (edit vmdk file) I’m unable to Storage vMotion the VM. Get the following error: “Failed waiting for data. Error 195887107. Not found.” Any idea?

Reply
admin March 9, 2022 - 11:36 am

Have you checked the following VMware kb? You should disable the multi-writer attribute on your vmdk drives (the Sharing option).
Storage vMotion fails with Error 195887107 (66850)
https://kb.vmware.com/s/article/66850

Reply
JOHNNY-FLASH April 5, 2022 - 10:15 pm

Thank you for these instructions.
Reducing the VMDK worked well for guests running Windows.
With Ubuntu guests and LVM I had to manually correct and repair the GPT table before the machine would boot correctly

Reply
Steini April 11, 2022 - 2:27 pm

Thanks, I was able to clone physical Dell W10LTSC to Dell ESXi standalone host with to small datastore. Used sysprep, Clonezilla. New VM in ESXi overprovison size(to enable restore with Clonezilla). In VM, cmd.exe diskpart and “select volume x” and “delete volume x override”(recovery etc partitions), shrink c:, ssh to ESXi, resize in vmdk conf file. Unregister/register VM in ESXi to have it show the right size. 😀

Reply
Michael Tuma May 17, 2022 - 2:49 am

This worked great for me – almost. The drives on the VM are the correct size, and the disks on the VM configuration are the right size, but the Datastore files are still reporting the original size for the VMDKs. How do fix this?

Reply
Alec Garcia May 24, 2022 - 4:48 pm

If it is a thin provisioned disk you may have to run this command on the ESXi host on that VMDK file. vmkfstools -K disk_name.vmdk
I had to do this to get my thin provisioned VMDK file back down in size after deleting a bunch of files. Check this KB for the steps I took. https://kb.vmware.com/s/article/2136514

Reply
Mark Katalinic May 15, 2023 - 2:30 am

This unfortunately does not work for NFS datastores and without sufficient space on a vmfs datastore to migrate the vm to you’re stuck with creating a new drive, copying the data and deleting the old or using v2v.

Reply
Harry B. February 8, 2023 - 6:30 pm

this seems to work well for MBR based disks. for GPT based ones, i had to shrink the main partition at least 2MB more than the projected total size of the disk (i even shrunk it 128MB more.. to be on the safe side). after manipulating the VMDK file and migrating the VM, i booted a GParted live distro and used gdisk’s (r)ecovery option to rebuild the backup GPT. in detail: i used the d option [use main GPT header (rebuilding backup)] and then (w)rote the GPT to the disk. hope this keeps someone from growing grey hair 😉

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • Recovering a Deleted VMFS Datastore on VMware ESXi/vSphere
  • Match Windows Disks to VMWare VMDK Files
  • Using iPerf to Test Network Speed and Bandwidth
  • How to Install Windows 11 on a Hyper-V Virtual Machine
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top