Before you can remove a LUN, you must detach the corresponding device by using the vSphere Web Client, or the esxcli storage core device set command.

Detaching a device brings a device offline. Detaching a device does not impact path states. If the LUN is still visible, the path state is not set to dead.

Prerequisites

  • Make sure you are familiar with virtual machine migration. See the vCenter Server and Host Management documentation.
  • Make sure you are familiar with datastore mounting and unmounting. See Mount a Datastore with ESXCLI.

Procedure

  1. Migrate virtual machines from the device you plan to detach.
  2. Unmount the datastore deployed on the device.
    If the unmount fails, ESXCLI returns an error. If you ignore that error, you will get an error when you attempt to detach a device with a VMFS partition still in use.
  3. If the unmount failed, check whether the device is in use.
    esxcli storage core device world list -d <device>
    If a VMFS volume is using the device indirectly, the world name includes the string idle0. If a virtual machine uses the device as an RDM, the virtual machine process name is displayed. If any other process is using the raw device, the information is displayed.
  4. Detach the storage device.
    esxcli storage core device set -d naa.xxx... --state=off

    Detach is persistent across reboots and device unregistration. Any device that is detached remains detached until a manual attach operation. Rescan does not bring persistently detached devices back online. A persistently detached device comes back in the off state.

    ESXi maintains the persistent information about the device’s offline state even if the device is unregistered. You can remove the device information by running esxcli storage core device detached remove -d naa.12.

  5. (Optional) To troubleshoot the detach operation, list all devices that were detached manually.
    esxcli storage core device detached list
  6. Perform a rescan.
    esxcli <conn_options> storage core adapter rescan