VMware Cloud Community
dinny
Expert
Expert
Jump to solution

What (if any) effect do the various LUN rescan commands have on running VMs

Hiya,

In the past I've often used the rescan option in the VC VI client to check for newly attached LUNs.

I've always just presumed that it would leave any existing LUNs alone, and that it would just check for, and then add any new LUNs.

Hence I have often run it when VMs have been powered on on the ESX server - and have never gone in to maintenance mode first etc.

As far as I know this has never caused any problems.

However I was recently testing out a build script using the "esxcfg-rescan vmhba0" command on one of my test ESX servers.

The output from this seemed to suggest that it actually drops all the existing LUNs first and then reconnects them all.

Which I guess makes sense as it is also checking if any LUNs have been removed as well as added.

I guess if that is the case - it is probably better to only run such commands when no VMs are powered on?

I'm also looking at using the VI Perl toolkit to write a script to trawl round all the ESX servers in my datacentre and do a rescan.

This presumely invokes the same command as the VI client.

I was presuming that I would be able to run this script whenever a new LUN was added to my ESX environment without any impact on running VMs.

Now I'm not so sure...

Does anyone know what the implication of both types of rescan command are on existing LUNs and running VMs?

Cheers

Dinny

Reply
0 Kudos
1 Solution

Accepted Solutions
sbeaver
Leadership
Leadership
Jump to solution

Here you go

PREVIOUS="vmhba0"

echo "Starting HBA Balance....."

case "$1" in

-c)

  1. Show current config

echo >> /root/PostInstall/PostInstall.log

echo "****** CURRENT HBA/LUN CONFIG ******"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

esxcfg-mpath -q --lun=$\{LUN} | grep FC

echo

done

;;

-p)

  1. Show new config

echo

echo "****** PREVIEW NEW BALANCED HBA/LUN CONFIG ******"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

CURRENT=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{CURRENT} = $\{PREVIOUS} ]]

then

NEW=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{NEW} = vmhba1 ]]

then

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}') "active preferred"

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}')

else

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}')

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}') "active preferred"

fi

PREVIOUS=$\{NEW}

echo

else

if [\[ $\{CURRENT} = vmhba1 ]]

then

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{CURRENT})

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{CURRENT})

else

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{CURRENT})

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{CURRENT})

fi

PREVIOUS=$\{CURRENT}

echo

fi

done

;;

-e)

  1. Execute new config

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

CURRENT=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{CURRENT} = $\{PREVIOUS} ]]

then

NEW=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

NEWPATH=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}')

esxcfg-mpath --lun=$\{LUN} --path=$\{NEWPATH} --preferred

PREVIOUS=$\{NEW}

else

PREVIOUS=$\{CURRENT}

fi

done

echo

echo "****** NEW HBA CONFIG *****"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

esxcfg-mpath -q --lun=$\{LUN} | grep FC

echo

done

echo

echo "****** \"active\" flag will be moved after disk activity *****"

echo

;;

*)

echo $"Usage: balancelun \{-c (current config)| -p (preview new config) -e (implement new config)}"

exit 1

esac

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**

View solution in original post

Reply
0 Kudos
7 Replies
sbeaver
Leadership
Leadership
Jump to solution

I have a script that scans for new luns and then balances the paths. I run this any time and have never had a problem

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
jketron
Enthusiast
Enthusiast
Jump to solution

In the past I have used the rescan command with success and only a few times did I ever have an issue where a LUN would disappear or the hosting server have other issues that caused me to reboot.

waynegrow
Expert
Expert
Jump to solution

I have never had an issue with a LUN rescan, except the rescan might time out or I have to run it twice to see a new LUN.

dinny
Expert
Expert
Jump to solution

Thanks for that,

I've also got a script I use for load balancing the paths.

I've run both scripts last week with no problems (as far as I'm aware).

Sometime over last weekend though I got an issue with three of my LUNs whereby they seemed to get a scsi reservation lock on them.

Nothing could access them during this time - the LUNs showed up - but no ESX server could see the VMFS 3 partition.

Rebooting all the ESX servers (and the VCB server) still didn't free it.

In the end I found the -L lunreset option in vmkfstools which did remove the reservation. But I still have no idea what did cause it.

I'm 99% certain it was not related to the rescan script - but it did start me wondering....

Out of interest I don't suppose your script uses the perl toolkit does it?

I wanted to run both the rescan and the loadbalance via that - but I couldn't find any methods to loadbalance HBA paths in the VI API.

You don't happen to know what they are do you?

In the end I used a separate script using esxcfg-mpath[/b] to load balance the HBA paths - based on a post Mittel made a while ago.

Dinny

Reply
0 Kudos
trojanjo
Enthusiast
Enthusiast
Jump to solution

I am interested in seeing a script to load balance the paths. Can someone send me a link or some code? I am not much of a perl scripter actually not at all.

---- Visit my blog. http://www.2vcps.com
Follow me: http://twitter.com/jon_2vcps
Reply
0 Kudos
sbeaver
Leadership
Leadership
Jump to solution

Here you go

PREVIOUS="vmhba0"

echo "Starting HBA Balance....."

case "$1" in

-c)

  1. Show current config

echo >> /root/PostInstall/PostInstall.log

echo "****** CURRENT HBA/LUN CONFIG ******"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

esxcfg-mpath -q --lun=$\{LUN} | grep FC

echo

done

;;

-p)

  1. Show new config

echo

echo "****** PREVIEW NEW BALANCED HBA/LUN CONFIG ******"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

CURRENT=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{CURRENT} = $\{PREVIOUS} ]]

then

NEW=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{NEW} = vmhba1 ]]

then

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}') "active preferred"

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}')

else

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}')

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{NEW} | awk '\{print " " $1, $2, $3, $4, $5}') "active preferred"

fi

PREVIOUS=$\{NEW}

echo

else

if [\[ $\{CURRENT} = vmhba1 ]]

then

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{CURRENT})

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{CURRENT})

else

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v $\{CURRENT})

echo $(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep $\{CURRENT})

fi

PREVIOUS=$\{CURRENT}

echo

fi

done

;;

-e)

  1. Execute new config

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

CURRENT=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

if [\[ $\{CURRENT} = $\{PREVIOUS} ]]

then

NEW=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}' | awk -F ":" '\{print $1}')

NEWPATH=$(esxcfg-mpath -q --lun=$\{LUN} | grep FC | grep -v "preferred" | awk '\{print $4}')

esxcfg-mpath --lun=$\{LUN} --path=$\{NEWPATH} --preferred

PREVIOUS=$\{NEW}

else

PREVIOUS=$\{CURRENT}

fi

done

echo

echo "****** NEW HBA CONFIG *****"

echo

for LUN in $(esxcfg-vmhbadevs | tail +2 | awk '\{print $1}')

do

esxcfg-mpath -q --lun=$\{LUN} | grep FC

echo

done

echo

echo "****** \"active\" flag will be moved after disk activity *****"

echo

;;

*)

echo $"Usage: balancelun \{-c (current config)| -p (preview new config) -e (implement new config)}"

exit 1

esac

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Thanks for all your comments.

I've awarded some points - I've given the "correct" for the script as I guess that was the most useful post for trojano and perhaps for other browsers...

Dinny

Reply
0 Kudos