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 rescan-scsi-bus.sh 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 rescan-scsi-bun.sh, and in other cases I use the following script to prod the sysfs scan and issue_lip entries directly:

#!/bin/bash

SLEEP_INTERVAL=300

echo "Scanning all fibre channel host adapters"

for i in `ls /sys/class/fc_host`; do
    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}
done

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! :)

This article was posted by Matty on 2011-08-26 13:56:00 -0400 -0400