The following shell script was implemented to display LUNs from an EMC disk array. The host had 2 QLE4060c HBA cards (from QLogics Corporation) connected to the iSCSI network. You can adapt this script to rescan your system as the host numbers will be different. You can also omit the last line as this is relevant to EMC navisphere command set.

#!/bin/sh
echo "Forcing Scan on HBA 1"
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "Forcing Scan on HBA 2"
echo "- - -" > /sys/class/scsi_host/host2/scan
echo "Dump HBA 1 data"
cat /proc/scsi/qla4xxx/1 | grep \(
echo "Dump HBA 2 data"
cat /proc/scsi/qla4xxx/2 | grep \(
echo "Dsplay LUNS"
powermt display dev=all

A more sophisticated example!

The following script from Kurt Garloff is a bit smarter and searches for the host then reports the devices found, the sample output is run on a VMWare instance of a Red Hat 4.7 server (yes its an old legacy install).

The script also takes command line parameters:

. ./rescan-scsi-bus.sh -h
Usage: rescan-scsi-bus.sh [-l] [-w] [-c] [host [host ...]]
-l activates scanning for LUNs 0 .. 7 [default: 0]
-w enables scanning for device IDs 0 .. 15 [def.: 0 .. 7]
-r enables removing of devices        [default: disabled]
-c enables scanning of channels 0 1   [default: 0]
If hosts are given, only these are scanned [default: all]

The script

#!/bin/bash
# Script to rescan SCSI bus, using the scsi add-single-device mechanism
# (w) 98/03/19 Kurt Garloff <kurt@garloff.de> (c) GNU GPL

# Return hosts. /proc/scsi/HOSTADAPTER/? must exist
findhosts ()
{
hosts=
for name in /proc/scsi/*/?; do
name=${name#/proc/scsi/}
if test ! $name = scsi
then hosts="$hosts ${name#*/}"
echo "Host adapter ${name#*/} (${name%/*}) found."
fi
done
}

# Test if SCSI device $host $channel $id $lun exists
# Outputs description from /proc/scsi/scsi, returns new
testexist ()
{
grepstr="scsi$host Channel: 0$channel Id: 0*$id Lun: 0$lun"
new=`cat /proc/scsi/scsi|grep -e"$grepstr"`
if test ! -z "$new"
then cat /proc/scsi/scsi|grep -e"$grepstr"
cat /proc/scsi/scsi|grep -A2 -e"$grepstr"|tail -2|pr -o4 -l1
fi
}

# Perform search (scan $host)
dosearch ()
{
for channel in $channelsearch; do
for id in $idsearch; do
for lun in $lunsearch; do
new=
devnr="$host $channel $id $lun"
echo "Scanning for device $devnr ..."
printf "OLD: "
testexist
if test ! -z "$remove" -a ! -z "$new"
then echo "scsi remove-single-device $devnr" >/proc/scsi/scsi
echo "scsi add-single-device $devnr" >/proc/scsi/scsi
printf "\r\x1b[A\x1b[A\x1b[AOLD: "
testexist
if test -z "$new"; then printf "\rDEL: \r\n\n\n\n"; let rmvd+=1; fi
fi
if test -z "$new"
then printf "\rNEW: "
echo "scsi add-single-device $devnr" >/proc/scsi/scsi
testexist
if test -z "$new"; then printf "\r\x1b[A"; else let found+=1; fi
fi
done
done
done
}

# main
if test @$1 = @--help -o @$1 = @-h
then
echo "Usage: rescan-scsi-bus.sh [-l] [-w] [-c] [host [host ...]]"
echo " -l activates scanning for LUNs 0 .. 7 [default: 0]"
echo " -w enables scanning for device IDs 0 .. 15 [def.: 0 .. 7]"
echo " -r enables removing of devices        [default: disabled]"
echo " -c enables scanning of channels 0 1   [default: 0]"
echo " If hosts are given, only these are scanned [default: all]"
exit 0
fi

# defaults
lunsearch="0"
idsearch="0 1 2 3 4 5 6 7"
channelsearch="0"
remove=""

# Scan options
opt="$1"
while test ! -z "$opt" -a -z "${opt##-*}"; do
opt=${opt#-}
case "$opt" in
l) lunsearch="0 1 2 3 4 5 6 7" ;;
w) idsearch="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" ;;
c) channelsearch="0 1" ;;
r) remove=1 ;;
*) echo "Unknown option -$opt !" ;;
esac
shift
opt="$1"
done

# Hosts given ?
if test @$1 = @; then findhosts; else hosts=$*; fi

declare -i found=0
declare -i rmvd=0
for host in $hosts; do dosearch; done
echo "$found new device(s) found.               "
echo "$rmvd device(s) removed.                 "

Sample Output

. ./rescan-scsi-bus.sh
Host adapter 0 (mptsas) found.
Scanning for device 0 0 0 0 …
OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 1 0 …
OLD: Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 2 0 …
OLD: Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 3 0 …
OLD: Host: scsi0 Channel: 00 Id: 03 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 4 0 …
OLD: Host: scsi0 Channel: 00 Id: 04 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 5 0 …
OLD: Host: scsi0 Channel: 00 Id: 05 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 0 0 6 0 …
OLD: Host: scsi0 Channel: 00 Id: 06 Lun: 00
Vendor: VMware   Model: Virtual disk     Rev: 1.0
Type:   Direct-Access                    ANSI SCSI revision: 02
0 new device(s) found.
0 device(s) removed.

Advertisements