WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automating Dead Space Reclamation in ESXi 5.0u1

Automating Dead Space Reclamation in ESXi 5.0u1

03.24.2012 by William Lam // 4 Comments

VMware released vSphere 5.0 Update 1 last week, which mainly included bug fixes but it also brought back one very cool feature that was initially introduced with the release of vSphere 5.0 called Thin Provisioning UNMAP primitive for an ESXi host. You can read more about the details in this article by my colleague Cormac Hogan.

As you can see from From Cormac's article, the process of reclaiming of dead space on a thin provisioned LUN is currently a manual process, but does it have to be? The answer is, No of course, we can can definitely automate this!

Disclaimer: This script is not officially supported by VMware, please test this in a development environment before using on production system. This script is provided as an example on you can automate this manual process.

Before you proceed, please understand that the UNMAP operation can potentially take a few minutes up to a few hours depending on the size of your datastore and how your array handles this operation. You should consider performing this operation during a maintenance window or during off peak hours else you could impact VMs residing on the datastore. You should also ensure you have a VAAI-capable storage array before performing running this script.

I wrote a simple shell script called reclaimMyDeadsSace.sh which needs to be executed on the ESXi Shell via SSH. The script will also perform some validation such as ensuring you are running ESXi 5.0 Update 1 and that your host is in maintenance mode as a per-caution to ensure no running VMs are on the host during this process.

You will only need to run the script on one of the hosts connected to all the datastores you wish to reclaim dead space on. You may use scp or WinSCP to transfer the script to your ESXi host and ensure you set the execute permission on the script (chmod +x reclaimMyDeadSpace.sh)

The script can be executed in two ways:

  1. Identify ALL VMFS3 and VMFS5 volumes and perform the reclaim based on the percentage entered by the user
  2. Reclaim on specific datastores specified by the user as well as the percentage to be reclaimed (this is recommended, that way script does not choose all datastores including local ones)

Here is an example of selecting ALL VMFS3 and VMFS5 datastores to reclaim 60% of free space:

Here is an example of selecting just 4 datastores specified in a file and we will be reclaiming 60% of free space:

In this example, we created a file called "datastore_list.txt" (you may name the file anything you want) which contains the following:
iSCSI-1
iSCSI-2
iSCSI-3
iSCSI-4

So if you are using thin provisioned LUNs and would like to reclaim some of that dead space back and have a VAAI-capable storage array, be sure to check out the UNMAP functionality in ESXi 5.0u1.

More from my site

  • How to Automate the disabling of the VAAI UNMAP primitve in ESXi 5
  • Want to issue a VAAI UNMAP operation using the vSphere Web Client?
  • w00t! VMware Tools for Nested ESXi!
  • Disabling IPv6 via Command-Line For ESXi 5.1 (Without Automatic Host Reboot)
  • How to Deploy ESXi 5 Using Razor & Puppet

Categories // Uncategorized Tags // ESXi 5.0, unmap, vaai, vmkfstools, vSphere 5.0

Comments

  1. *protectedvExpert2011 says

    03/28/2012 at 4:10 pm

    William, does this apply to NFS datastores?

    thanks

    Reply
  2. *protectedWilliam says

    03/29/2012 at 11:42 pm

    @vExpert2011,

    This is only applicable to block storage

    Reply
  3. *protectedDominguez says

    10/24/2014 at 12:44 pm

    Hi Mr lam,
    I want to automate "vmkfstools –y 90", you script reclaimMyDeadSpace.sh work on ESXi 5.1?
    Thank for you time

    Reply
  4. *protectedChris Brothers says

    06/06/2017 at 7:49 am

    Hey William,

    I used to use this script in the 5.0 and 5.1 days and it worked great (thanks for the work, this helped me out a lot!). Unfortunately, this doesn't seem to want to run on 5.5 and 6.0 and it doesn't seem like ESXi/VMWare is cleaning up dead blocks. Do you have any insight? Can this be adapted to work on later versions, or is there something doing garbage collection that I missed?

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025