Scripts to automate the process of identifying and compiling an RDM to LUN mapping list for VMware ESX 3.0

In an earlier posting I listed a copy of the article explaining how to manually create a RDM to LUN mapping for VMware ESX. I have created scripts to completly automate this process, ftp the result and email the result file.

Save the below commands in a file and make it executable. Name the file find-rdm.

# Andrew Lin, 2009
# This script identifies all VMware RDM disks and creates a second
# script to identify the corresponding LUN to which the RDM is mapped.

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

Here is an explanation of what the script does.

find /vmfs/volumes -name **-rdm**

This command will find all files in the directory /vmfs/volumes which have the characters -rdm. These files are the RDM disks. The result is then redirected to the next command with the pipe ‘|’ sign.

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

Sed is a special editor for modifying files automatically. In this case I am modifying the result of the previous command before it is stored into a file. In the above example the /s means to substitute -rdmp.vmdk with .vmdk. The /g means to substitute every occurance of the word -rdmp.vmdk that Sed finds, otherwise Sed will only change the first occurance of the word it finds.

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

some of the RDM files have the extension -rdm.vmdk, the -rdm needs to be stripped as well using the Sed command.

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

The ^/ means the beginning of a line, in this case Sed will insert vmkfstools -q at the beginning of each line.

> RDM-disk | chmod 645 RDM-disk

The results of the previous commands is then redirect with the > symbol to the file RDM-disk. The command chmod 645 RDM-disk will make the file executable. You can now run this file from the command line and the raw device mapping to LUN will be displayed on screen, or redirecting the output to a file for later viewing.

I took the whole thing further by scheduling the scripts to run through a cron job and then upload the files to an ftp server. My ftp server is a windows machine and I had the blat executable scehduled to email the file to me.

By default the ftp outbound ports are disabled on the VMware server, you will need to open up the outbound ports. I have posted all the scripts and instructions required to fully automate this in other articles, here are the links:

(1) Open Ftp outbound ports on VMware server
(2) Install and configure Blat
(3) Automate ftp upload of files

Note: When the script RDM-disk is scheduled through a cron job, then it must have root privileges, otherwise you will get no result. Below is what my cron job looks like

00 8 * * * /scripts/find-rdm
10 8 * * * /bin/su – root -c “/scripts/RDM-disk > /scripts/rdm-lun-mapping”
20 8 * * * /scripts/ftp-scripts

2 comments for “Scripts to automate the process of identifying and compiling an RDM to LUN mapping list for VMware ESX 3.0

Comments are closed.