jump to navigation

Setting preferred paths in ESXi February 12, 2010

Posted by vneil in ESXi, scripts, VMware.

Quite a while ago, when I was setting up our current production environment, I had to think about how to set up the multipathing for the SAN LUNs. We have an FC SAN fabric connected to a couple of HDS storage systems and each of our ESXi host servers has 2 dual port FC HBAs. All LUNs would be visible on all four HBAs so each LUN ends up with 4 paths.

To make this simple when setting up the cluster we went for a standard 500GB size for the LUNs and had about 8 LUNs allocated to start with. We needed to somehow level the usage of these LUNs across the 4 paths.

These servers were running ESXi 3.5 and the round robin path policy was still experimental this left a decision of either Fixed or Most Recently Used (MRU) as the multipath policy to use. After some investigation I chose to use Fixed multipath as with MRU you could possibly end up with all LUNs on one path if several path failures go unnoticed.

To simplify the spreading of LUNs over the multiple paths the LUNs were each allocated a path in order, for example LUN 1 to path 1 , LUN 2 to path 2 ..etc and then LUN 5 would go to path 1 again. Then of course this needed to be set on 20 ESXi servers in the cluster and if any new LUNs were added this would have to be set as well.

Nowadays I would maybe look at doing this with Powershell but back then I was still quite new to it and as I was more comfortable in Unix I used the Vima appliance and setup a simple shell script and the vicfg-mpath command to do the work for me.

Here is the script (click on view source for a better view):

# Script to set preferred paths in rotational method
# Set VI_USERNAME and VI_PASSWORD environment variables before running.
esxhosts="esxhost1 esxhost2 esxhost3 esxhost4 esxhost5 esxhost6 esxhost7 esxhost8"
echo "===================== Start `date` =========================="
for esxhost in $esxhosts
   LUNs=`vicfg-mpath --server $esxhost -b | grep "vmfs/devices/disks" | cut -d\  -f1 | sort -u`
      if [ -z "$LUNs"  ] ; then
         echo "Error getting luns/paths for $esxhost"
         echo "Setting preferred paths for $esxhost "
         for LUN in $LUNs
             lunid=$( echo $LUN | cut -d: -f3)
             pathToSet=$(( $(($lunid % 4)) + 2 ))
             preferredPath=$(echo $LUN | sed "s/vmhba./vmhba${pathToSet}/")
# #debug#       echo Lun = $LUN  lunid = $lunid  path = $pathToSet preferredPath = $preferredPath
             echo Executing vicfg-mpath --server ${esxhost} --policy fixed --lun ${LUN} --path ${preferredPath} --preferred
             vicfg-mpath --server ${esxhost} --policy fixed --lun ${LUN} --path ${preferredPath} --preferred
echo "----------------------------------------------------------------------------------------"


1. VCAP-DCA Objective 8.3 – Administer vSphere Using the vSphere Management Assistant - August 8, 2010

[…] This blog entry shows off a little powershell for setting a preferred path. Most of the reference for storage multipathing will be from the below. Additionally the vSphere Troubleshooting course is a good target for this type of exercise. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: