WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple

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.

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

vSphere 4.1 Is the Gift That Keeps On Giving

07.23.2010 by William Lam // 3 Comments

While doing some testing on ghettoVCB earlier this week, I noticed a new command line argument to vmkfstools utility called "--fix" in vSphere 4.1. From the man pages for vmkfstool, it states the following:


-x, --fix -[check|repair]
This option will check and/or repair the virtual disk in case of an unclean shutdown.

Here is an example of running the command against a VM's VMDK:

[root@esx4-1 ~]# vmkfstools --fix check /vmfs/volumes/esx4-1-local-storage-1/dummy/dummy.vmdk
Disk is error free

What surprised me next while looking up this new parameter in the man pages, I discovered another new argument called "--miscop":


-J, --miscop [setuuid | getuuid]
´setuuid´ option creates a unique identifier (UUID) for the
virtual disk and stores the UUID in the descriptor file of the
virtual disk. If the descriptor file already contains a UUID,
it will be overwritten with a new one. Please make sure that the
virtual disk does not have a UUID before using this option.
´getuuid´ option displays the UUID of the virtual disk.

The "--miscop" command is listed in the man pages but is not displayed when running "vmkfstools --help".

At this point, I thought there might be more hidden commands that VMware is holding out on us. I decided to use a well known UNIX/Linux utility called "strings" which looks for printable string in files and apply that to the vmkfstools binary. After sifting through the massive output, I found the following additional command line parameters that are not documented:

  • dumpfs
  • numfiles
  • force
  • recursivelock
  • recover
  • vmfsscan
  • physicalmapping
  • logicalmapping
  • allocateblock
  • clearlazyzero
  • parseimage
  • createarro
  • createmirrordisks
  • createmultiextent
  • trackvdisk
  • activehosts

Here are some of the command syntax which I have been able to verify:

dumpfs can be used by specifying either "-D | --dumpfs" and specifying a VMFS volume, file or folder.


[root@esx4-1 ~]# vmkfstools -D /vmfs/volumes/esx4-1-local-storage-1/

Lock [type 10c00001 offset 4292608 v 33, hb offset 3440640
gen 11, mode 0, owner 00000000-00000000-0000-000000000000 mtime 2509]
Addr <4, 0, 0>, gen 1, links 4, type dir, flags 0, uid 0, gid 0, mode 1755
len 1260, nb 1 tbz 0, cow 0, zla 1, bs 1048576

[root@esx4-1 ~]# vmkfstools --dumpfs /vmfs/volumes/esx4-1-local-storage-1/

Lock [type 10c00001 offset 4292608 v 33, hb offset 3440640
gen 11, mode 0, owner 00000000-00000000-0000-000000000000 mtime 2509]
Addr <4, 0, 0>, gen 1, links 4, type dir, flags 0, uid 0, gid 0, mode 1755
len 1260, nb 1 tbz 0, cow 0, zla 1, bs 1048576

activehosts can be used by specifying "--activehosts" and specifying a VMFS volume


[root@esx4-1 ~]# vmkfstools --activehosts /vmfs/volumes/esx4-1-local-storage-1/
Found 1 actively heartbeating hosts on volume '/vmfs/volumes/esx4-1-local-storage-1/'
(1): MAC address 00:50:56:92:3f:86

For the other parameters, I have not been able to figure out the additional arguments to make them work. If anyone or VMware has further insight into these other options, I would love to know what they are used for.

Categories // Uncategorized Tags // vmkfstools, vSphere 4.1

  • « Previous Page
  • 1
  • 2

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