VMware: Unmount a datastore/volume from an ESXi Server at command line

Hi,

these steps describe the steps to unmount an datastore from an ESXi host. If you tried it with the GUI and you got an error:

The resource ‘my_esxdatastore’ is in use. Cannot unmount volume ‘esxdatastore_F00’ because “One or more virtual machines are still registered on it”.

Try the following steps to identify the open files:

Get the vmfs path and UUID of the datastore

~ # esxcli storage filesystem list
Mount Point                                        Volume Name                                 UUID                               
-------------------------------------------------  ------------------------------------------  -----------------------------------
/vmfs/volumes/561227ad-f2b4c56c-affd-001122334455  my_esxdatastore                             561227ad-f2b4c56c-affd-001122334455

Check which hosts have open files respectively activity on the volume:

~ # vmkfstools --activehosts /vmfs/volumes/561227ad-f2b4c56c-affd-001122334455
Scanning for VMFS-3/VMFS-5 host activity (512 bytes/HB, 2048 HBs).
Found 1 actively heartbeating hosts on volume
(1): MAC address 00:11:22:33:44:55, IP 10.10.100.5

Connect to the host by ssh and check for open files on the volume

~ # lsof | grep -i 561227ad-f2b4c56c-affd-001122334455
5280614     vmx   cwd  -1   /vmfs/volumes/561227ad-f2b4c56c-affd-001122334455/vCLS-13

in this example the vSphere Cluster Services has still open handles an the datastore. Since 7.0.1x the vCLS are no longer visible in the vSphere GUI.

You have to delete all vCLS and enable the Retreat Mode (this has some restictions! See the article below).
vCenter Cluster Retreat mode

You can use these powercli script

PS D:\> Connect-VIServer myVCenter.mydomain.org
PS D:\> $oCluster=Get-Cluster myCluster
PS D:\> $sAdvancedKeyName=[string]::Format("config.vcls.clusters.domain-{0}.enabled",$oCluster.Id.Replace("ClusterComputeResource-domain-",""))
PS D:\> write-host "KeyName:" $sAdvancedKeyName
config.vcls.clusters.domain-c12345.enabled
PS D:\> $oAdvancedSettingVCLS=Get-AdvancedSetting -Entity $global:DefaultVIServer -Name $sAdvancedKeyName
PS D:\> if($oAdvancedSettingVCLS) {
    $oAdvancedSettingVCLS | Set-AdvancedSetting -Value "False" 
}
else
{
    New-AdvancedSetting -Entity $global:DefaultVIServer -Name $sAdvancedKeyName -Value "False"
}

Unmount the volume/datastore

~ # esxcli storage filesystem unmount -p /vmfs/volumes/561227ad-f2b4c56c-affd-001122334455

and disable the Retreat Mode. Note: Once created you cannot remove the AdvancedSettings “config.vcls.clusters.domain-c12345.enabled” just created. You must set it to True.

PS D:\> write-host "KeyName:" $sAdvancedKeyName
config.vcls.clusters.domain-c12345.enabled
PS D:\> Get-AdvancedSetting -Entity $global:DefaultVIServer -Name $sAdvancedKeyName | Set-AdvancedSetting -Value "True"

Michael

Leave a Reply Cancel reply