Error message "Exceeded the number of devices that can be detached. Clean up all stale detach entries" appears when detaching a LUN from ESXi (59254)
KB:
https://kb.vmware.com/s/article/59254
1.Run this command to verify if there are 512 devices listed already:
vsish -e ls /storage/scsifw/persistDeviceAttrs/uids | wc -l
2.List out LUN/RDM disks currently in use in esxi host
Get-VMHost XXX |Get-ScsiLun -LunType disk | Export-Csv c:\temp\XXX_lun.csv
3.List out the LUN/RDM disks stored in the VSI node
vsish -e ls /storage/scsifw/persistDeviceAttrs/uids >> /tmp/vsi.txt
Then import the 2 lists in excel and found the LUN/RDM disks in VSI node that not currently in used.
Remove the perennially reserved for the LUN/RDM disksthat is not existed.
PS Script
--------------------------------------------------------------------------------------------------------------------------
#Connect ESXi server
Connect-viserver 10.172.x.x
#Import LUN/RDM list which need to remove the perennially reserved in ESXi host
$NaaList = Import-CSV "C:\Temp\Naalist.csv"
foreach ($id in $Naalist){
#Assign Variables
$Naaid = $id.WWN
#Remove the perennially reserved flag on the host
$myesxcli = get-esxcli -VMHost 10.172.x.x
$myesxcli.storage.core.device.setconfig($false, "$Naaid", $false)
}
--------------------------------------------------------------------------------------------------------------------------
4.Run this command on ESXi host to check again:
vsish -e ls /storage/scsifw/persistDeviceAttrs/uids | wc -l
Afterthat, detached the LUNs again.