Scan for New/Removed Luns Linux with QLogic FiberChannel HBA
This is the process I use to scan the QLogic Fibre Channel bus for new or removed LUNs. It was tested on Oracle Enterprise Linux 5 connected to a Compellent SAN, but I don’t see any reason it won’t work with another SAN.
Initially I was using a script from QLogic called “ql-dynamic-tgt-lun-disc.sh” but was having problems. Turns out that script is only for use with the QLogic Kernel module that you can download from QLogic. If you use that script with the default qla2xxx module that comes with the Linux kernel, the system will get unstable and often hang completely! Consider yourself warned!
# This is the process to add/remove LUNs on the Qlogic FC HBAs in Linux
# This assumes you’re using the default qla2xxx module from Linux and NOT
# the version of the module provided by QLogic
#################
# Add a new LUN #
#################
# On the SAN: Create Volume and MAP to server
# On the server you need to scan the FC Bus[s]:
# On my server, the FC HBAs are scsi host8 and host9
# You can determine the proper host#s by running:
more /sys/class/scsi_host/host*/state
# Any that show “Link Up – F_Port” are what you’re looking for.
# This does the actual scan on the server:
echo "- - -" > /sys/class/scsi_host/host8/scan
echo "- - -" > /sys/class/scsi_host/host9/scan
# Re-scans for multipathing the new device
multipath
# NOTE: Sometimes I have to run “multipath -F && multipath”
# or it won’t recognize the new paths. I don’t know why :(
# Verify that it sees the new volume
# /dev/mapper alias should match the volume serial number/WWN
# as listed on the SAN
ls -ltra /dev/mapper
# You may now mount your volume
##################
# Removing a LUN #
##################
umount /path/to/volume
# Get the drives associated with the LUN [ie sdc, sdj etc]
multipath -l <mpathalias>
# Flush the multipath list
multipath -F
# Verify that the above drives are no longer used by ANYTHING
# Do this for EACH drive
lsof /dev/sdX #Where X = drive designation above
# Delete the drives.
# Do this for EACH drive
echo 1 > /sys/bock/sdX/device/delete #Where X = drive designation above
# Unmap the volume on the SAN
# Re-scan then list multipath to make sure it doesn’t find the volume
# you just removed
multipath
multipath -l
# You should be done!
Comments
Comment from ender
Time June 11, 2010 at 12:35 pm
Yes, I believe everything is there. Some of the comments are pointing to things that need to be done on the SAN itself.
Some of the other comments assume some basic knowledge such as how to mount a volume. :)
Comment from Danny
Time June 14, 2010 at 1:56 pm
Thanks for the reply. I was specifically referring to:
# This assumes that the FC HBAs are scsi host8 and host9
# On the server run:
# Scans the FC Bus
Where there is no command under “On the Server run:”
Regards.
Comment from ender
Time June 14, 2010 at 2:05 pm
Oops. Yeah that was just left over from my original editing drafts.
I’ve re-written that part so hopefully it’s a bit more clear.
Thanks for pointing that out to me!
Comment from Danny
Time June 11, 2010 at 11:52 am
Are all the commands listed correctly for adding new LUN? I see comments with no commands under them.
Thanks for posting the info.