Identifying virtual disks pointing to Raw Device Mappings (RDMs) on ESX

Purpose

This article provides advanced users with a method to list all of the virtual disks pointing to a physical disk (Raw Device Mapping, or RDM) from PowerCLI and from the ESX/ESXi host console.

This method does not explicitly state the virtual machine which is using the raw device mapping pointer file, though it can be inferred from the directory name. It will instead provide the LUN to RDM mapping. To obtain a list of registered virtual machines and the associated RDMs, see Identifying virtual machines with Raw Device Mappings (RDMs) using PowerCLI (2001823).

Note: This method is generally time-consuming, as all Datastores must be searched iteratively for VMDK files. If those VMDK files are locked, such as by a running virtual machine, inquiring for the target device fails. In this case, it is better to search for registered virtual machines.

 

Resolution

 

To list all virtual disks pointing to an RDM device using PowerCLI:

This operation is generally time-consuming, as PowerCLI must iteratively inquire about the disk type of every VMDK file on the remote hosts. Checking locked files adds a few seconds of delay. The device which the RDM points to cannot be determined without a virtual machine attached.

  1. Open the vSphere PowerCLI command-line. For more information, see the vSphere PowerCLI Documentation.
     
  2. Run the command:

    Get-Datastore | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select "Filename","CapacityKB" | fl

    Example output:

    Filename    : [DatastoreName] DirectoryName/virtualrdm.vmdk
    CapacityKB  : 5760

    Note: The mapped device is not exposed, only the existence of the RDM. To determine the target device which it is mapped to, add this virtual disk to a virtual machine or use the console method.
     

To list all virtual disks pointing to an RDM device using the local console:

This operation is generally quick, as there is no overhead of network communication.

  1. Open a console to the ESX or ESXi host. For more information, see Unable to connect to an ESX host using Secure Shell (SSH) (1003807) or Using Tech Support Mode in ESXi 4.1 (1017910).
     
  2. Run the command:

    #find /vmfs/volumes/ -type f -name '*.vmdk' -size -1024k -exec grep -l '^createType=.*RawDeviceMap' {} \; > /tmp/rdmsluns.txt

    #for i in `cat /tmp/rdmsluns.txt`; do vmkfstools -q $i; done

    Example output:

    • Virtual Mode RDM:

      Disk /vmfs/volumes/.../virtualrdm.vmdk is a Non-passthrough Raw Device Mapping
      Maps to: vml.02000000006006048000019030091953303030313253594d4d4554

    • Physical Mode RDM:

      Disk /vmfs/volumes/.../physicalrdm.vmdk is a Passthrough Raw Device Mapping
      Maps to: vml.02000000006006048000019030091953303030313253594d4d4554

    Note: For more information on identifying the mapped device, see Identifying disks when working with VMware ESX/ESXi (1014953).

Additional Information

Note: This process may be useful before engaging in a resignaturing process. For more information about resignaturing, see Resignaturing VMFS3 volumes on VMware ESX 3.x via the VMware Infrastructure Client (9453805).
 
To query a specific virtual disk pointing to an RDM device using the local console, run the command:
 # vmkfstools –q <path_to_rdm_vmdk>
 
For example:
# vmkfstools –q  /vmfs/volumes/mydatastore/myvm/physicalrdm.vmdk
Disk /vmfs/volumes/…/physicalrdm.vmdk is a Passthrough Raw Device Mapping
Maps to: vml.02000000006006048000019030091953303030313253594d4d4554
 
Finally. we still cannot know which LUN are mapping to vml.02000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
But, we can use command esxcfg-scsidevs  -l > scsidevs.txt for get system scsi deivce list and command esxcfg-mpath -l > mpath.txt for get scsi path list.
Then can search vml.xxx with scsidevs.txt then search the mapped naa.xxxx with mpath.txt for know which RDM mapped SCSI LUN.
 

Write down script

#!/bin/sh
if [ -f /tmp/rdm_vmdks.txt ]
then
   rm /tmp/rdm_vmdks.txt]
fi
find /vmfs/volumes/ -type f -name '*.vmdk' -size -1024k -exec grep -l '^createType=.*RawDeviceMap' {} \; > /tmp/rdm_vmdks.txt

if [ -f /tmp/rdm_vmdk_maps.txt ]
then
  rm /tmp/rdm_vmdk_maps.txt
fi
for i in `cat /tmp/rdm_vmdks.txt`; do vmkfstools -q $i >> /tmp/rdm_vmdk_maps.txt ; done

if [ -f /tmp/rdm_scsi_luns.txt ]
then
   rm /tmp/rdm_scsi_luns.txt
fi

#query system scsi device and mpath list
esxcfg-scsidevs  -l > /tmp/scsidevs.txt
esxcfg-mpath -l > /tmp/mpath.txt

for i in `grep vml /tmp/rdm_vmdk_maps.txt | awk '{print $3}'`
do
  # echo "the i = $i that grep vml of /tmp/rdm_vmdk_maps.txt"
   for j in `grep $i /tmp/scsidevs.txt -B13 | grep '^naa'`
   do
   #  echo "$the j = $j that grep i of /tmp/scsidevs.txt -B13 and grep ^naa"
     grep $j /tmp/mpath.txt -B1 | grep Runtime| awk '{print $NF}' >>  /tmp/rdm_scsi_luns.txt
   done
done

echo "Download /tmp/rdm_scsi_luns.txt  and /tmp/rdm_vmdk_maps.txt for maping RDM disk naming"