Scanning for new LUNs on Linux servers

Storage management, the joys! Storage administration is one of those tasks that every admin does, and depending on your growth it may be something that consumes a lot of your time. If your servers are connected to a Fibre channel or iSCSI SAN, you probably need to periodically poke your systems to see new storage that is made available to them. There are several tools that can be used to do this. QLogic provides the scli utility and a rescan shell script, the sg3utils package comes with the script and you can always roll your own script to do this.

I use a mix of all of the tools above. On older systems I use the QLogic scli utility, on servers that have Emulex adapters or recent Operating Systems I use, and in other cases I use the following script to prod the sysfs scan and issue_lip entries directly:



echo "Scanning all fibre channel host adapters"

for i in `ls /sys/class/fc_host`
    echo "Rescanning /sys/class/fc_host/${i}:"

    echo "  Issuing a loop initialization on ${i}:" 
    echo "1" > /sys/class/fc_host/${i}/issue_lip

    echo "  Scanning ${i} for new devices:"
    echo "- - -" > "/sys/class/scsi_host/${i}/scan"

    echo "Sleeping for ${SLEEP_INTERVAL} seconds"
    sleep ${SLEEP_INTERVAL}

This is the nice thing about Linux. There is a tool to do just about everything, and if there isn’t one available you can usually cobble something together in short order to do what you need. Isn’t life as a Linux admin grand! :)

6 thoughts on “Scanning for new LUNs on Linux servers”

  1. This is dangerous script as it initializes all fc ports almost at the same time. You should consider add “sleep” after scan command or you may loose access to already mapped LUNs.

  2. @kombor — that is a good point. I’ve never had an issue with this script, but it’s always best to play things safe. I added a sleep to the script as an added precaution. Thanks for the feedback!

  3. Matty as kombor mentioned you will want to stagger your initialization. lip resets cause your fc ports to sign back onto the fabric.

    I ran into a few issues myself a while back. MPIO doesn’t fair to well with you cut all the paths at once.

    Keep up the great work.

  4. You would only want to run this if you presented new luns, right? and on a modern switched SAN you wouldn’t have to do any LIPs, and thus not worry about:

    “L O O S I N G” access.

Leave a Reply

Your email address will not be published. Required fields are marked *