How to Scan/Detect New LUNs on Redhat Linux

When you are running Hat Enterprise Linux 5, 6, and 7 series system with DM-Multipath and the software iSCSI initiator, you can discover new LUNs by rescanning the iSCSI service on the host. Rescanning the service displays all the newly created LUNs that have been mapped to the host. This article I will show commands to scan and detect (outputs to check) new luns attached to the Centos/RHEL server.

Check number of attached disks

You use the below commands to identify existing LUNs and how to add newly mapped LUNs to Linux.

# cat /proc/scsi/scsi | egrep -i 'Host:' | wc -l
7

You can use the command to have better output of all the disks

# fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-|type|identifier'
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 sectors
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sde: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdf: 7516 MB, 7516192768 bytes, 14680064 sectors

1) Using /sys class file

You can use the echo command to scan each scsi host device as below

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

And check if there are new disk added with fdisk command

Some notes below :

If we know the channel, target ID and LUN address, we can scan using that. Here, we have 4 HBA emulex cards 0, 1, 2 and 3.

server1:/proc/scsi/lpfc# ls
0  1  2  3

Through card 0 and 2,

server1:/proc/scsi/lpfc# cat 0
lpfc0t00 DID d200ef WWPN 50:06:01:68:39:a0:43:65 WWNN 50:06:01:60:b9:a0:43:65
lpfc0t01 DID d201ef WWPN 50:06:01:61:39:a0:43:65 WWNN 50:06:01:60:b9:a0:43:65
server1:#/proc/scsi/lpfc# cat 1
server1:/proc/scsi/lpfc# cat 2
lpfc2t01 DID ed0cef WWPN 50:06:01:69:39:a0:43:65 WWNN 50:06:01:60:b9:a0:43:65
lpfc2t00 DID ed0def WWPN 50:06:01:60:39:a0:43:65 WWNN 50:06:01:60:b9:a0:43:65
server1:/proc/scsi/lpfc# cat 3

It has the same WWNN (World Wide Node Name) for all the 4 WWPN (World Wide Port Name).

server1:/proc/scsi/lpfc# cat /sys/class/fc_transport/*/node_name
0x50060160b9a04365
0x50060160b9a04365
0x50060160b9a04365
0x50060160b9a04365

We can do a depth research by filtering the WWPN (World Wide Port Name) to have more information

server1:/proc/scsi/lpfc# grep 50060160b9a04365 /sys/class/fc_transport/*/node_name
/sys/class/fc_transport/target0:0:0/node_name:0x50060160b9a04365
/sys/class/fc_transport/target0:0:1/node_name:0x50060160b9a04365
/sys/class/fc_transport/target2:0:0/node_name:0x50060160b9a04365
/sys/class/fc_transport/target2:0:1/node_name:0x50060160b9a04365

This indicates there are four Fibre Channel routes to this target.

Line 1 : Thru host 0 channel 0 target 0
Line 2 : Thru host 0 channel 0 target 1
Line 3 : Thru host 2 channel 0 target 0
Line 4 : thru host 2 channel 0 targer 1

So now, you can scan for LUNs as follows and addresss "8" is given by storage team.

echo "0 0 8" > /sys/class/scsi_host/host0/scan
echo "0 1 8" > /sys/class/scsi_host/host0/scan
echo "0 0 8" > /sys/class/scsi_host/host2/scan
echo "0 1 8" > /sys/class/scsi_host/host2/scan

The output of SCSI file is illustrated for your reference:

Host: scsi0 Channel: 00 Id: 00 Lun: 08
Vendor: DGC      Model: RAID 5           Rev: 0326
Type:   Direct-Access                    ANSI SCSI revision: 04
Host: scsi0 Channel: 00 Id: 01 Lun: 08
Vendor: DGC      Model: RAID 5           Rev: 0326
Type:   Direct-Access                    ANSI SCSI revision: 04
Host: scsi2 Channel: 00 Id: 00 Lun: 08
Vendor: DGC      Model: RAID 5           Rev: 0326
Type:   Direct-Access                    ANSI SCSI revision: 04
Host: scsi2 Channel: 00 Id: 01 Lun: 08
Vendor: DGC      Model: RAID 5           Rev: 0326
Type:   Direct-Access                    ANSI SCSI revision: 04

2) Scan lun with multipath / powermt

You can check current multipath setup using multipath or powermt command.

# multipath -l
mpath2 (36006016015501c0018c07c18e0d8dc11)
[size=68 GB][features="1 queue_if_no_path"][hwhandler="1 emc"]
\_ round-robin 0 [active]
\_ 0:0:0:2 sdc 8:32  [active]
\_ round-robin 0 [enabled]
\_ 1:0:0:2 sdi 8:128 [active]

mpath1 (36006016015501c0084227c0ee0d8dc11)
[size=68 GB][features="1 queue_if_no_path"][hwhandler="1 emc"]
\_ round-robin 0 [active]
\_ 1:0:0:1 sdh 8:112 [active]
\_ round-robin 0 [enabled]
\_ 0:0:0:1 sdb 8:16  [active]

....................
....................

mpath3 (36006016015501c0019c07c18e0d8dc11)
[size=68 GB][features="1 queue_if_no_path"][hwhandler="1 emc"]
\_ round-robin 0 [active]
\_ 1:0:0:3 sdj 8:144 [active]
\_ round-robin 0 [enabled]
\_ 0:0:0:3 sdd 8:48  [active]

If EMC powerpath is installed, check the disk/multipath status as below:

# powermt display dev=all | more
Pseudo name=emcpowerb
CLARiiON ID=APM00080503154 [cl10083]
Logical device ID=6006016023041F003AB6ED708885DD11 [LUN 3]
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP A, current=SP A       Array failover mode: 1
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
3 qla2xxx                   sde       SP A2     active  alive      0      1
3 qla2xxx                   sdh       SP B3     active  alive      0      0
6 qla2xxx                   sdk       SP A3     active  alive      0      1
6 qla2xxx                   sdn       SP B2     active  alive      0      0
..............................
..............................
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
3 qla2xxx                   sdd       SP A2     active  alive      0      1
3 qla2xxx                   sdg       SP B3     active  alive      0      0
6 qla2xxx                   sdj       SP A3     active  alive      0      1
6 qla2xxx                   sdm       SP B2     active  alive      0      0

Multipath daemon will automatically add attached devices if it's configured properly. For powermt, we need to run below command manually.

# powermt config

3) Using Script

You can rescan using the SCSI rescan script which will detect new luns and add it to your server automatically.  You can find this script in sg3_utils package.

# /us/bin/rescan-scsi-bus.sh -a
Scanning SCSI subsystem for new devices
Scanning host 0 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
..................
..................
1 new or changed device(s) found. 
 [0:0:5:0]
0 remapped or resized device(s) found. 
0 device(s) removed.

Conclusion

For storage(Netapp,equallogic) that use iscsi target, command iscsiadm -m session --rescan could be used to rescan when new lun added to the target. I would recommend always to use vendor specific script or tools to scan Luns. Hope you have enjoyed this article. Let us know if you found any other work around to scan storage devices.

Bobbin Zachariah 8:52 am

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.

8 Comments