Fearthepenguin.net

Diary of a Lazy SysAdmin

Skip to: Content | Sidebar | Footer

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]:

# This does the actual scan on the server – this will
scan any fiber channel links you have:


for host in `ls /sys/class/fc_host`; do
echo "- - -" > /sys/class/scsi_host/${HOST}/scan
done

# 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/block/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!

Edit: 2012-06-07 – Edited to simplify ‘finding’ and scanning the fiber channel busses.

Comments

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.

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 Alfredo
Time March 24, 2011 at 9:49 am

Great post buddy. You saved me a lot of time!

BTW, you have a typo on “echo 1 > /sys/bock/sdX/”. You wrote “bock” instead of block.

Comment from Joel
Time June 4, 2012 at 12:20 pm

I know this is kind of an old post but I figured I’d add this as a more direct way of finding your fibrechannel scsi_host instances:

[root@cms ~]# ls /sys/class/fc_host
host1 host2

The above is from a RHEL 5 box.

Comment from ender
Time June 7, 2012 at 10:47 am

Excellent, yeah that exists on our Oracle Enterprise Linux systems as well. It’ll at least tell you which ‘hosts’ are the fiber channel links.

Comment from towster
Time December 7, 2012 at 3:47 pm

Make it slightly easier to delete..

## to delete all SDxx devices on a single LUN..
for P in `ls /sys/block/dm-19/slaves/*/device/delete` ; do
echo $P
echo 1 > $P
done

Comment from ender
Time December 7, 2012 at 4:03 pm

Oh that’s cool. I’ll have to test that. Thanks!

Comment from kazaalite hosts
Time July 30, 2014 at 3:52 pm

Тhis blog was… Һow do you say it? Relevant!!
Finally Ι’ve found sometɦing that helped mе.
Cheers!

Write a comment