How to detach a LUN device from ESXi host via CLI

Loading

We’ve already covered in detail how to unmount a lun via the GUI in our previous blog.

In this blog we will focus or attention on the cli side.

At a high level, we will go through these steps to unmount a datastore from an ESXi host. The procedure extends to cover how to detach a datastore with an extent attached.

  • Step 1 – Evacuate all the VM’s and files
  • Step 2 – Unmount the datastore
  • Step 3 – Detach the LUNs from ESXi host
  • Step 4 – Unmap the LUN from Storage Array
  • Step 5 – Rescan the adapters

List of all datastores mounted to an ESXi host

# esxcli storage filesystem list

The output, which lists all VMFS datastores, is similar to:

To find the unique identifier of the LUN housing the datastore to be removed, run this command:

# esxcfg-scsidevs -m

This command generates a list of VMFS datastore volumes and their related unique identifiers. Make a note of the unique identifier (NAA_ID) for the datastore you want to unmount as this will be used later on.

Unmount the datastore by running the command:

# esxcli storage filesystem unmount [-u UUID | -l label | -p path ]

For example, use one of these commands to unmount the LUN01 datastore:

# esxcli storage filesystem unmount -l <datastorename>


# esxcli storage filesystem unmount -u <VMFS-UUID>


# esxcli storage filesystem unmount -p /vmfs/volumes/UUID

To verify that the datastore has been unmounted, run the command:

# esxcli storage filesystem list

To detach the device/LUN, run the command:

# esxcli storage core device set –state=off -d NAA_ID6.     

To verify that the device is offline, run the command:

# esxcli storage core device list -d NAA_ID

The output, which shows that the Status of the disk is off

To rescan that the device adapter , run the command:

# esxcli storage core adapter rescan [ -A vmhba# | –all ]

The devices are automatically removed from the Storage Adapters.

To bring the device back online, run the command:

# esxcli storage core device set –state=on -d NAA_ID


If the device is to be permanently decommissioned from an ESXi host, (that is, the LUN has been or will be destroyed), remove the NAA entries from the host configuration by running these commands:a.     

To list the permanently detached devices:

# esxcli storage core device detached list

The output is similar to:

Device UID                            State
—————————-  —–
naa.50060160c46036df50060160c46036df  off
naa.6006016094602800c8e3e1c5d3c8e011  offb.     

To permanently remove the device configuration information from the system , run the command:

# esxcli storage core device detached remove -d NAA_ID

For example:

# esxcli storage core device detached remove -d naa.50060160c46036df50060160c46036df

The reference to the device configuration is permanently removed from the ESXi host’s configuration.

Finally, you will now need to login to your Storage array and unmap the lun.

References

https://kb.vmware.com/s/article/2004605

(Visited 1,469 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.

Leave a Reply