Creating RDM to LUN (SAN) mapping on VMware ESX 4, Vcenter.

In the past I have written articles about how to create a RDM to LUN disk mapping for VMware ESX 3.
http://www.gamescheat.ca/2009/10/scripts-to-automate-the-process-of-identifying-and-compiling-an-rdm-to-lun-mapping-list-for-vmware-esx-30/ and http://www.gamescheat.ca/2009/10/how-to-identify-and-compile-an-rdm-to-lun-mapping-list-for-vmware-esx-30/

The procedure to identify the path for the RDM (raw disk mapping) to LUN (disk on SAN) on Vmware ESX 4 is different from Vmware Esx 3. There are a few more steps in version 4. I will explain below how to determine the path for RDM to LUN in ESX 4.

Login to the console with root permission.

# find /vmfs/volumes -name **-rdm**
/vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1-rdmp.vmdk

Find all RDM file in .vmfs/volumes. Remove -rdmp from the result and that is the path you need for the next step.

# vmkfstools -q /vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1.vmdk
Disk /vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1.vmdk is a Passthrough Raw Device Mapping
Maps to: vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56

Use the vmkfstools -q command to find the vml id of the LUN, it is vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56.

# esxcfg-scsidevs -u | grep vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56
naa.60060e80058c7b0000008c7b0000310b vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56

Now use the esxcfg-scsidevs command to find the Network Addressing Authority identifier (naa) for the LUN.

# esxcfg-mpath -l –device=naa.60060e80058c7b0000008c7b0000310b
fc.2001001b3232c093:2101001b3232c093-fc.50060e80058c7b55:50060e80058c7b55-naa.60060e80058c7b0000008c7b0000310b
Runtime Name: vmhba2:C0:T0:L10
Device: naa.60060e80058c7b0000008c7b0000310b
Device Display Name: HITACHI Fibre Channel Disk (naa.60060e80058c7b0000008c7b0000310b)
Adapter: vmhba2 Channel: 0 Target: 0 LUN: 10
Adapter Identifier: fc.3001001b3232c093:2101001b3232c093
Target Identifier: fc.60060e80058c7b55:50060e80058c7b55
Plugin: NMP
State: active
Transport: fc
Adapter Transport Details: WWNN: 22:01:00:1b:32:32:c0:93 WWPN: 23:01:00:1b:32:32:c0:93
Target Transport Details: WWNN: 55:06:0e:80:05:8c:7b:55 WWPN: 56:06:0e:80:05:8c:7b:55

fc.2000001b3212c093:2100001b3212c093-fc.50060e80058c7b45:50060e80058c7b45-naa.60060e80058c7b0000008c7b0000310b
Runtime Name: vmhba1:C0:T0:L10
Device: naa.60060e80058c7b0000008c7b0000310b
Device Display Name: HITACHI Fibre Channel Disk (naa.60060e80058c7b0000008c7b0000310b)
Adapter: vmhba1 Channel: 0 Target: 0 LUN: 10
Adapter Identifier: fc.3000001b3212c093:2100001b3212c093
Target Identifier: fc.60060e80058c7b45:50060e80058c7b45
Plugin: NMP
State: active
Transport: fc
Adapter Transport Details: WWNN: 22:00:00:1b:32:12:c0:93 WWPN: 23:00:00:1b:32:12:c0:93
Target Transport Details: WWNN: 55:06:0e:80:05:8c:7b:45 WWPN: 56:06:0e:80:05:8c:7b:45

The esxcfg-mpath -l command generates the detailed information for the LUN. Because there are redundant path to the LUN on the SAN, the result is listed twice with different fiber channel HBA interfaces.

Now what if your VMware ESX server is hosting many servers all with different RDMs. It would be very tedious to manually compile a report for RDM to LUN mapping. I create a script that will automatically do all the above steps and will output the result to screen or you can redirect the result to a file. This will script will search for all the RDMs and create the mappings. Below is the script and explanation of how it works.

#!/bin/bash
# Andrew Lin
# August 4, 2010
# Pay Andrew Lin lot’s of money before you
# can use this script

date
hostname

find /vmfs/volumes -name **-rdm** | sed ‘s/-rdmp.vmdk/.vmdk/g’ | sed ‘s/-rdm.vmdk/.vmdk/g’ | sed ‘s/^/vmkfstools -q /g’ >> andrew-disk-map |
chmod 645 andrew-disk-map

file=andrew-disk-map
while read line
do
$line
$line | grep vml | sed ‘s/.*to:/esxcfg-scsidevs -u | grep/g’ > andrew_lin1

chmod 755 andrew_lin1
./andrew_lin1 | sed ‘s/ .*//g’
./andrew_lin1 | sed ‘s/ .*//g’ | sed ‘s/^/esxcfg-mpath -L –device=/g’ >andrew_lin2
# rm andrew_lin1

chmod 755 andrew_lin2
./andrew_lin2
# rm andrew_lin2

echo -e “\n”
done <$file

I will explain below what the above script does.

find /vmfs/volumes -name **-rdm**
/vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1-rdmp.vmdk

Search for all RDM (raw disk mapping), VMware1_1-rdmp.vmdk is found.

sed ‘s/-rdmp.vmdk/.vmdk/g’

Change the characters -rdmp.vmdk to .vmdk. The s/ means to substitute, and /g means globally apply the changes for all matches. Some RDM have the -rdmp.vmdk extension (not shown in the above example).

sed ‘s/-rdm.vmdk/.vmdk/g’

Change -rdm.vmdk to .vmdk for all matches.

sed ‘s/^/vmkfstools -q /g’

Add the command vmkfstools -q to the beginning of each line.

>> andrew-disk-map | chmod 645 andrew-disk-map

Redirect the output to the file andrew-disk-map. Change the file permission to 645 to make it executable.

Below is the result of the above command stored in andrew-disk-map.

vmkfstools -q /vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1.vmdk

file=andrew-disk-map

Define the variable called file which contains the name of the file andrew-disk-map.

while read line
do
..

….
done <$file

The while loop will read the contents of the file defined in the variable $file (which is andrew-disk-map). The file is read one line at a time and the commands defined within the while loop are executed for each line read.

$line

Execute the line read from the file andrew-disk-map and send the output to screen.

Command
vmkfstools -q /vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1.vmdk
Output
Disk /vmfs/volumes/4c20ca1e-d32d6ed6-96cb-001e4f3fdc36/VMware1/VMware1_1.vmdk is a Passthrough Raw Device Mapping
Maps to: vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56

$line | grep vml | sed ‘s/.*to:/esxcfg-scsidevs -u | grep/g’ > andrew_lin1

Grep will find the line that contains the characters vml, this is the unique LUN id. Replace all characters before and upto the characters to: with esxcfg-scsidevs -u | grep. The result will look like the below line which is redirected to the file andrew_lin1.

esxcfg-scsidevs -u | grep vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56

chmod 755 andrew_lin1

Chmod 755 will make the file andrew_lin1 executable.

./andrew_lin1 | sed ‘s/ .*//g’

Execute the file andrew_lin1. Sed ‘s/ .*//g’ will delete everything after the first space found, otherwise the output will look like the below.

Command executed (this is the content of the file andrew_lin1).
esxcfg-scsidevs -u | grep vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56
Output
naa.60060e80058c7b0000008c7b0000310b vml.02000a000060060e80058c7b0000008c7b0000310b4f50454e2d56

./andrew_lin1 | sed ‘s/ .*//g’ | sed ‘s/^/esxcfg-mpath -l –device=/g’ >andrew_lin2

Execute the file andrew_lin1, from the result remove everything after the LUN ID number (naa.60060e80058c7b0000008c7b0000310b). Then add the command esxcfg-mpath -L –device= in front of the LUN ID number, see below example. The output is redirected to the file andrew_lin2.
esxcfg-mpath -l –device=naa.60060e80058c7b0000008c7b0000310b

# rm andrew_lin1

You are done with file andrew_lin1 and can delete it. If you want to save the file for troubleshooting then comment out the above line with the # sign.

chmod 755 andrew_lin2

Make the file andrew_lin2 executable.

./andrew_lin2

Execute andrew_lin2. Which contains the command esxcfg-mpath -l –device=naa.60060e80058c7b0000008c7b0000310b. The output below is displayed on screen. Notice that there are redundant paths to the LUN on the SAN.

fc.2001001b3232c093:2101001b3232c093-fc.50060e80058c7b55:50060e80058c7b55-naa.60060e80058c7b0000008c7b0000310b
Runtime Name: vmhba2:C0:T0:L10
Device: naa.60060e80058c7b0000008c7b0000310b
Device Display Name: HITACHI Fibre Channel Disk (naa.60060e80058c7b0000008c7b0000310b)
Adapter: vmhba2 Channel: 0 Target: 0 LUN: 10
Adapter Identifier: fc.3001001b3232c093:2101001b3232c093
Target Identifier: fc.60060e80058c7b55:50060e80058c7b55
Plugin: NMP
State: active
Transport: fc
Adapter Transport Details: WWNN: 22:01:00:1b:32:32:c0:93 WWPN: 23:01:00:1b:32:32:c0:93
Target Transport Details: WWNN: 55:06:0e:80:05:8c:7b:55 WWPN: 56:06:0e:80:05:8c:7b:55

fc.2000001b3212c093:2100001b3212c093-fc.50060e80058c7b45:50060e80058c7b45-naa.60060e80058c7b0000008c7b0000310b
Runtime Name: vmhba1:C0:T0:L10
Device: naa.60060e80058c7b0000008c7b0000310b
Device Display Name: HITACHI Fibre Channel Disk (naa.60060e80058c7b0000008c7b0000310b)
Adapter: vmhba1 Channel: 0 Target: 0 LUN: 10
Adapter Identifier: fc.3000001b3212c093:2100001b3212c093
Target Identifier: fc.60060e80058c7b45:50060e80058c7b45
Plugin: NMP
State: active
Transport: fc
Adapter Transport Details: WWNN: 22:00:00:1b:32:12:c0:93 WWPN: 23:00:00:1b:32:12:c0:93
Target Transport Details: WWNN: 55:06:0e:80:05:8c:7b:45 WWPN: 56:06:0e:80:05:8c:7b:45

# rm andrew_lin2

Delete the file andrew_lin2 by removing the # comment.

echo -e “\n”

Enter a line space.

About Andrew Lin

Hi, I have always wanted to creat a blog site but never had the time. I have been working in Information Technology for over 15 years. I specialize mainly in networks and server technologies and dabble a little with the programming aspects. Andrew Lin

View all posts by Andrew Lin →