Latest Posts



Translate

Total Pageviews

Tuesday, 17 July 2012

Unpresenting a LUN in ESXi 5.x


Purpose

This article provides steps on how to unpresent a LUN from an ESXi 5.x host.

Resolution

Removing a LUN in ESX/ESXi 4.x is complex. Improvements have been made in ESXi 5.x to streamline the procedure to make it easier for Administrators to remove LUNs.

Unpresenting a LUN Checklist

Before unpresenting a LUN, ensure that:
  • If the LUN is being used as a VMFS datastore, all objects (such as virtual machines and templates) stored on the VMFS Datastore are unregistered or moved to another datastore.

    Note: All CD/DVD images located on the VMFS datastore must also be unregistered from the virtual machines.
  • The datastore is not part of a datastore cluster. For more information on datastore clusters, see the vSphere Resource Management Guide.
  • The datastore is not managed by Storage DRS. For more information on Storage DRS, see the vSphere Resource Management Guide.
  • Storage I/O Control is disabled for the datastore. For more information, see Managing Storage I/O Resources in thevSphere Resource Management Guide.
  • The datastore is not used for vSphere HA heartbeat.
  • No third party scripts or utilities running on the ESXi host can access the LUN in question. If the LUN is being used as a datastore, unregister all objects (such as virtual machines and templates) stored on the datastore.
  • If the LUN is being used as an RDM, remove the RDM from the virtual machine. Click Edit Settings, highlight the RDM hard disk, and select Remove. Ensure that Delete from disk is selected and click OK.

    Note
    : This destroys the mapping file, but not the LUN content.
  • Check if the LUN/Datastore is used as the persistent scratch location for the host. For more information on persistent scratch, see Creating a persistent scratch location for ESXi (1033696).

    This PowerCLI script can be used to check the current scratch location:

    $vcServer = "vCenter01"
    $cluster = "CL01"
    $esxCred = Get-Credential
    Connect-VIServer $vcServer | Out-Null
    #Connect to ESX hosts in cluster
    foreach ($esx in Get-Cluster $cluster | Get-VMHost) {
    Connect-VIServer $esx -Credential $esxCred | Out-Null
    Get-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation"
    }

Getting the NAA ID of the LUN to be removed

From the vSphere Client, this information is visible from the Properties window of the datastore.

From the ESXi host, run the command:

# esxcli storage vmfs extent list


The output is similar to: 

Volume Name VMFS UUID                           Extent Number Device Name                           Partition
----------- ----------------------------------- ------------- ------------------------------------  ---------
datastore1  4de4cb24-4cff750f-85f5-0019b9f1ecf6             0  naa.6001c230d8abfe000ff76c198ddbc13e        3
Storage2    4c5fbff6-f4069088-af4f-0019b9f1ecf4             0  naa.6001c230d8abfe000ff76c2e7384fc9a        1
Storage4    4c5fc023-ea0d4203-8517-0019b9f1ecf4             0  naa.6001c230d8abfe000ff76c51486715db        1
LUN01       4e414917-a8d75514-6bae-0019b9f1ecf4             0 naa.60a98000572d54724a34655733506751        1

Make a note of the NAA ID of the datastore, as this information is required later. 

Note: Alternatively, you can run the esxcli storage filesystem list command, which lists all file systems recognized by the ESX host.

Unpresenting a LUN from vSphere Client

To unpresent a LUN from an ESXi 5.0 host using vSphere Client:
  1. If the LUN is an RDM, skip to Step 2. Otherwise, in the Configuration tab of the ESXi host, click Storage. Right-click the datastore being removed, and click Unmount.

    A Confirm Datastore Unmount window appears. When the prerequisite criteria have been passed, click OK.

    Note: To unmount a datastore from multiple hosts, from the vSphere Client select Hosts and Clusters, Datastores and Datastore Clusters view (Ctrl+Shift+D). Perform the umount task and select the appropriate hosts that should no longer access the datastore to be unmounted.
  2. Choose the Devices View (Under Configuration > Storage):


  3. Right-click the NAA ID of the LUN (as noted above) and click Detach. A Confirm Device Unmount window is displayed. When the prerequisite criteria have been passed, click OK.

    Note: If you choose the Delete option after unmounting the LUN, it will delete all data from the LUN and remove the partition table from it.
  4. Under the Operational State of the Device, the LUN will be listed as Unmounted.
  5. The LUN can now be unpresented from the SAN. For more information, contact your storage array vendor.
  6. Perform a rescan on all ESXi hosts which had visibility to the LUN. The device is automatically removed from the Storage Adapters.
When the device is detached, it stays in an unmounted state even if the device is represented (that is, the detached state is persistent). To bring the device back online, the device needs to be attached.

If the device is to be permanently decommissioned from an ESXi servers(s) , you may have to manually remove the NAA entries from the host configuration by issuing these commands:
  1. 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  off 

  2. To permanently remove the device configuration information from the system:

    # esxcli storage core device detached remove -d NAA_ID


    For example:

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

Unpresenting a LUN from the command line 

To unpresent a LUN from an ESXi 5.0 host from the command line:
  1. If the LUN is an RDM, skip to step 4. Otherwise, to get a list of all datastores mounted to an ESXi host, run the command:

    # esxcli storage filesystem list


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

    Mount Point                                       Volume Name UUID                                Mounted Type         Size         Free
    ------------------------------------------------- ----------- ----------------------------------- ------- ------ -----------  -----------
    /vmfs/volumes/4de4cb24-4cff750f-85f5-0019b9f1ecf6 datastore1  4de4cb24-4cff750f-85f5-0019b9f1ecf6    true  VMFS-5   140660178944   94577360896
    /vmfs/volumes/4c5fbff6-f4069088-af4f-0019b9f1ecf4 Storage2    4c5fbff6-f4069088-af4f-0019b9f1ecf4    true  VMFS-3   146028888064    7968129024
    /vmfs/volumes/4c5fc023-ea0d4203-8517-0019b9f1ecf4 Storage4    4c5fc023-ea0d4203-8517-0019b9f1ecf4    true  VMFS-3   146028888064  121057050624
    /vmfs/volumes/
    4e414917-a8d75514-6bae-0019b9f1ecf4 LUN01       4e414917-a8d75514-6bae-0019b9f1ecf4    true  VMFS-5   146028888064   4266131456
  2. 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 LUN01
    # esxcli storage filesystem unmount -u
     4e414917-a8d75514-6bae-0019b9f1ecf4
    # esxcli storage filesystem unmount -p /vmfs/volumes/
    4e414917-a8d75514-6bae-0019b9f1ecf4
    Note: If the VMFS filesystem you are attempting to unmount has active I/O or has not fulfilled the prerequisites to unmount the VMFS datastore, the vmkernel logs show this error:

    WARNING: VC: 637: unmounting opened volume ('4e414917-a8d75514-6bae-0019b9f1ecf4' 'LUN01') is not allowed.
    VC: 802: Unmount VMFS volume f530 28 2
     4e414917a8d7551419006bae  f4ecf19b 4 1 0 0 0 0 0 : Busy
  3. To verify that the datastore has been unmounted, run the command:

    # esxcli storage filesystem list

    The output is similar to:

    Mount Point                                       Volume Name UUID                                Mounted Type         Size         Free

    ------------------------------------------------- ----------- ----------------------------------- ------- ------ -----------  -----------
    /vmfs/volumes/4de4cb24-4cff750f-85f5-0019b9f1ecf6 datastore1  4de4cb24-4cff750f-85f5-0019b9f1ecf6    true  VMFS-5   140660178944   94577360896
    /vmfs/volumes/4c5fbff6-f4069088-af4f-0019b9f1ecf4 Storage2    4c5fbff6-f4069088-af4f-0019b9f1ecf4    true  VMFS-3   146028888064    7968129024
    /vmfs/volumes/4c5fc023-ea0d4203-8517-0019b9f1ecf4 Storage4    4c5fc023-ea0d4203-8517-0019b9f1ecf4    true  VMFS-3   146028888064  121057050624
                                                     
    LUN01       4e414917-a8d75514-6bae-0019b9f1ecf4   false  VMFS-unknown version    0     0
    Note that the Mounted field  is set to false, the Type field is set to VMFS-unknown version, and that no Mount Point exists.

    Note
    : The unmounted state of the VMFS datastore persists across reboots. This is the default behavior. However, it can be changed by appending the --no-persist flag.
  4. To detach the device/LUN, run this command:

    # esxcli storage core device set --state=off -d NAA_ID

  5. To verify that the device is offline, run this command:

    # esxcli storage core device list -d NAA_ID

    The output, which shows that the status of the disk is off, is similar to:

    naa.60a98000572d54724a34655733506751
       Display Name: NETAPP Fibre Channel Disk (naa.60a98000572d54724a34655733506751)
       Has Settable Display Name: true
       Size: 1048593
       Device Type: Direct-Access
       Multipath Plugin: NMP
       Devfs Path: /vmfs/devices/disks/naa.60a98000572d54724a34655733506751
       Vendor: NETAPP
       Model: LUN
       Revision: 7330
       SCSI Level: 4
       Is Pseudo: false
       Status: off
       Is RDM Capable: true
       Is Local: false
       Is Removable: false
       Is SSD: false
       Is Offline: false
       Is Perennially Reserved: false
       Thin Provisioning Status: yes
       Attached Filters:
       VAAI Status: unknown
       Other UIDs: vml.020000000060a98000572d54724a346557335067514c554e202020


    Running the partedUtil getptbl command on the device shows that the device is not found.

    For example:

    # partedUtil getptbl /vmfs/devices/disks/naa.60a98000572d54724a34655733506751

    Error: Could not stat device /vmfs/devices/disks/
    naa.60a98000572d54724a34655733506751- No such file or directory.
    Unable to get device /vmfs/devices/disks/
    naa.60a98000572d54724a34655733506751
  6. The LUN can now be unpresented from the SAN. For more information, contact your storage array vendor.
  7. To rescan all devices on the ESXi host, run the command:

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


    The devices are automatically removed from the Storage Adapters.

    Note
    : A rescan needs to be run on all hosts that had visibility of the removed LUN.

    Note: When the device is detached, it stays in an unmounted state even if the device is represented (that is, the detached state is persistent). To bring the device back online, the device needs to be attached. To do this via the command line, run the command:

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

  8. If the device is to be permanently decommissioned from an ESXi servers(s), (that is, the LUN has been destroyed), remove the NAA entries from the host configuration by issuing these commands:

    1. 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  off 


    2. To permanently remove the device configuration information from the system:

      # esxcli storage core device detached remove -d NAA_ID

      For example:

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

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