VMware vSphere

 View Only

 Shrinking thin VM hard

Reza Fathi's profile image
Reza Fathi posted Jun 16, 2024 11:56 AM

Hi

I have a VM on esxi 6 server and I wanted to shrink its vmdk hard. I did these steps:

1- used sdelete -z c:

2- powered off the vm

3- ssh to esxi host and used vmfsktools -K DC2.vmdk

4- powered on the VM

After those steps, esxi showed 52GB hard usage and that was fine. (before was 110 GB) but when I used ls -lh on esxi , it shows DC2-flat.vmdk file with 400GB size. Is this size real? if not , is that occupying that size?

a_p_'s profile image
a_p_

What you see in that column is the provisioned size. To see the real disk space usage run e.g. ls -lisa, which will show you the used disk space in the second column.

André

Reza Fathi's profile image
Reza Fathi

Thanks. That 400gb is not occupied the storage by vm right?

What is the best practice to use sdelete to shrink vm hard? Is that safe to use on windows installed drive?

a_p_'s profile image
a_p_

Correct, the 400GB is the provisioned disk size, i.e. the size that's configured in the VMs settings, and the maximum that the .vmdk file can grow to.

sdelete is usually save to use, because it writes to a file until the disk fills up, and then deletes that file.

André

Reza Fathi's profile image
Reza Fathi

I have many vms on esxi 8. Is this method works on esxi 8 too?

a_p_'s profile image
a_p_

This should work regardless of the ESXi version.

Just make sure that the VM does not have active snapshots !!!

André

Reza Fathi's profile image
Reza Fathi

I have a vm hard added as .mvmdk so can i use sdelete and then vmkfstool -K on this too?

Casey's profile image
Casey

Have you tried to do a storage migration and selecting each disk and changing it to Thin Provisioned? 

Casey's profile image
Casey

The DC2-flat.vmdk file you see listed with a size of 400GB is the actual size of the virtual disk as it is allocated on the datastore. This does not necessarily mean it is using that entire space for data, especially if you have performed steps to zero out and shrink the disk.

Here's a breakdown of what's happening:

  1. SDelete: Running sdelete -z inside the guest OS zeros out free space, making it possible to reclaim unused space at the VMFS level.
  2. VMKFSTools: The command vmkfstools -K DC2.vmdk is used to punch out zeroed blocks and reclaim space on a thin-provisioned virtual disk.

After performing these steps, the space within the VM should be reclaimed, and the size shown in vSphere (52GB) reflects the used space within the VM. However, the ls -lh command shows the allocated size on the datastore.

Thin-Provisioned Disks

If your VMDK is thin-provisioned:

  • The actual used space on the datastore should be less than the allocated size. This discrepancy is normal and indicates that the space within the disk is not entirely occupied by data.

Verifying Actual Usage

To verify the actual space usage, you can use the following command:

du -h /vmfs/volumes/your_datastore/your_vm_directory/DC2-flat.vmdk

This command will show you the actual disk usage, which should reflect the reclaimed space.

Thin-Provisioning Check

Ensure your disk is thin-provisioned by using the following command:

vmkfstools -D /vmfs/volumes/your_datastore/your_vm_directory/DC2.vmdk

Look for a line indicating if the disk is thin-provisioned.

Shrink Command

Ensure that the vmkfstools -K command was successful. You can also use vmkfstools -p to see the current allocation of blocks.

Conclusion

The size shown by ls -lh (400GB) is the provisioned size, not the actual used space. To ensure this space is not occupied, verify with du and confirm the thin-provisioned status with vmkfstools.

If this is still the case, try doing a storage migration to another DS and selecting each disk and changing it to "Thin Provisioning". 

I am very interested to see how this goes. Please follow up. 

a_p_'s profile image
a_p_

>>> I have a vm hard added as .mvmdk ..

Is this ".mvmdk" just a typo? Please share details.

André

Reza Fathi's profile image
Reza Fathi

no that is not a typo.

a_p_'s profile image
a_p_

To me, this looks like someone renamed the virtual disks manually (e.g. using the vmkfstools -E .... command), and accidentally entered ".mvmdk" instead of ".vmdk".

André