How to Safely Unmount a LUN and Detach a Datastore from ESXi Hosts

This comprehensive guide walks you through the process of safely unmounting a LUN or detaching a datastore from ESXi 5.x/6.x/7.x hosts. These operations must be performed on each ESXi host that has access to the storage device.

Prerequisites and Important Considerations

Before proceeding with the unmount process, ensure the following requirements are met:

  • Migrate all data: Move all virtual machines, templates, snapshots, and files off the target datastore
  • Remove RDM mappings: If the LUN is used as a Raw Device Mapping (RDM), remove it from VM configurations first
  • Disable Storage DRS: Ensure the datastore is not part of a datastore cluster
  • Check HA heartbeat: Verify the datastore isn’t used for vSphere HA heartbeating
  • Stop active I/O: Confirm no applications or processes are actively using the datastore

Step 1: Identify the Target Datastore and LUN

List All Mounted Datastores

First, identify the datastore you want to unmount by listing all current datastores:

esxcli storage filesystem list


Sample Output:

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/4e414917-a8d75514-6bae-0019b9f1ecf4 LUN01        4e414917-a8d75514-6bae-0019b9f1ecf4 true     VMFS-5  146028888064 4266131456


Find the LUN’s Unique Identifier

Next, obtain the NAA ID (unique identifier) for the LUN housing your target datastore:

esxcfg-scsidevs -m


This command maps VMFS datastores to their underlying storage devices. Note the NAA_ID for your target datastore as you’ll need it for the detach operation.

Step 2: Unmount the Datastore

Unmount Using Command Line

Unmount the datastore using one of the following methods:

By Label:

esxcli storage filesystem unmount -l LUN01


By UUID:

esxcli storage filesystem unmount -u 4e414917-a8d75514-6bae-0019b9f1ecf4


By Path:

esxcli storage filesystem unmount -p /vmfs/volumes/4e414917-a8d75514-6bae-0019b9f1ecf4


Verify Unmount Success

Confirm the datastore is unmounted by running:

esxcli storage filesystem list


Expected Output for Unmounted Datastore:

Mount Point  Volume Name  UUID                                 Mounted  Type                Size  Free
------------ ------------ ------------------------------------ -------- ------------------- ----- ----
             LUN01        4e414917-a8d75514-6bae-0019b9f1ecf4 false    VMFS-unknown version 0     0


Key indicators of successful unmount:

  • Mounted field shows false
  • Type field shows VMFS-unknown version
  • Mount Point is empty

Troubleshooting Unmount Issues

If you encounter errors during unmount, check the VMkernel logs for messages like:

WARNING: VC: 637: unmounting opened volume ('4e414917-a8d75514-6bae-0019b9f1ecf4' 'LUN01') is not allowed.
VC: 802: Unmount VMFS volume ... : Busy


This indicates active I/O or unmet prerequisites. Ensure all VMs and processes have been moved off the datastore.

Step 3: Detach the LUN

Set Device to Offline State

Once the datastore is successfully unmounted, detach the underlying LUN:

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


Replace NAA_ID with the actual identifier you noted earlier.

Verify Device Detachment

Confirm the device is offline:

esxcli storage core device list -d NAA_ID


Sample Output:

naa.60a98000572d54724a34655733506751
   Display Name: NETAPP Fibre Channel Disk (naa.60a98000572d54724a34655733506751)
   Has Settable Display Name: true
   Size: 1048593
   Device Type: Direct-Access
   Multipath Plugin: NMP
   Status: off
   Is RDM Capable: true
   Is Local: false
   Is Offline: false


The Status field should show off, indicating successful detachment.

Additional Verification

You can also verify detachment using the partedUtil command:

partedUtil getptbl /vmfs/devices/disks/NAA_ID


Expected Output:

Error: Could not stat device /vmfs/devices/disks/NAA_ID - No such file or directory.
Unable to get device /vmfs/devices/disks/NAA_ID


This error message confirms the device is no longer accessible to the host.

Step 4: Storage Array Management

After detaching the LUN from all ESXi hosts, coordinate with your storage administrator to:

  1. Unpresent the LUN from the SAN fabric
  2. Remove LUN mappings from the storage array
  3. Decommission the LUN if it’s no longer needed

Step 5: Rescan Storage Adapters

Perform Storage Rescan

After the LUN is unpresented from the SAN, rescan all storage adapters on each affected ESXi host:

esxcli storage core adapter rescan --all


Or rescan a specific adapter:

esxcli storage core adapter rescan -A vmhba2


This removes the detached device from the Storage Adapters list and updates the host’s storage view.

Important: Perform this rescan on all hosts that previously had visibility to the removed LUN.

Step 6: Permanent Device Removal (Optional)

If the LUN is being permanently decommissioned, you can clean up the device configuration:

List Detached Devices

esxcli storage core device detached list


Sample Output:

Device UID                           State
------------------------------------ -----
naa.50060160c46036df50060160c46036df off
naa.6006016094602800c8e3e1c5d3c8e011 off


Remove Device Configuration

esxcli storage core device detached remove -d NAA_ID


Example:

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


Important Notes and Best Practices

Persistence Behavior

  • Unmounted state persists across reboots by default
  • For temporary unmounting, use the --no-persist flag:
  • esxcli storage filesystem unmount -l datastore_name --no-persist

Re-attaching Devices

If you need to bring a detached device back online:

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


Safety Considerations

  1. Always perform these steps in order: unmount first, then detach
  2. Coordinate with your team: Ensure no other administrators are working on the same storage
  3. Document the process: Keep records of which LUNs were removed and when
  4. Test in non-production: Practice these procedures in a lab environment first

Cluster-Wide Operations

When working with clustered environments:

  • Perform these steps on each host in the cluster
  • Consider using vCenter Server for coordinated operations
  • Ensure all hosts are in maintenance mode if performing major storage changes

This methodical approach ensures safe removal of storage devices without impacting your virtual infrastructure or causing data loss.

Leave a comment