How to Scan/Detect New LUNs on Linux

Written by: Bobbin Zachariah   |   Last updated: June 28, 2022

When you are running RedHat 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 will display all the newly created LUNs that have been mapped to the host. In this guide, I will show commands to scan and detect (outputs to check) new luns attached to the Centos/RHEL server.

To scan new FC LUNS and SCSI disks in Linux, you can use the echo script command for a manual scan that doesn't require a system reboot. But, from Redhat Linux 5.4 onwards, Redhat introduced /usr/bin/rescan-scsi-bus.sh script to scan all the LUNs and update the SCSI layer to reflect new devices.

Check the 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 following 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

or

# fdisk -l | grep sd
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Disk /dev/sdd: 14.0 GB, 13958643712 bytes, 27262976 sectors

Related Read: How to Check LUN or SAN Disk in Linux

1. Using /sys class file

You can use the echo command to scan each scsi host device as below. Now to rescan the bus, use the following command

# echo "- - -" >  /sys/class/scsi_host/host0/scan

The three dash ("-  -  -") of the command act as wildcards meaning rescan everything. Remember that the three values normally stand for channel, SCSI target ID, and LUN.

# echo "c t l" >  /sys/class/scsi_host/hosth/scan

where

  • h is the HBA number
  • c is the channel on the HBA
  • t is the SCSI target ID
  • l is the LUN.

If you don't have the host bus number, you must list all the existing host bus number on your system with the command

# ls /sys/class/scsi_host
host0 host1 host2

Then you will scan every iscsi disk found and scan after every scanning if the new disk was detected. It means

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan

or

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

It may look very simple as we perform this operation but the system has much work to do in the background when you execute storage scanning commands.

Method to find Channel Routes

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

Another Method

If you don't have the host bus number, you must list all the existing host bus number on your system with the command

# ls /sys/class/scsi_host
host0 host1 host2

or try

# grep mpt /sys/class/scsi_host/host?/proc_name
/sys/class/scsi_host/host0/proc_name:mptspi

On the output, host0 is the relevant field. As we have said earlier, we need to have the host bus number to determine what to scan

Then you will scan every iscsi disk found and scan after every scanning if the new disk was detected. It means

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan

If you have too many hosts (from host0 to host20 for example), you can use the command below

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

or you can try (this one for Fibre Channel)

# for host in `ls /sys/class/fc_host/`; do
echo "1" >/sys/class/fc_host/${host}/issue_lip;
done

Can devices be rescanned in Linux OS without reloading the Linux driver?

There is a procedure which forces the driver to rescan the targets and to allow a new device which is to be added. This triggers the driver to initiate a LUN discovery process.

To force a rescan from the command line, type the following command:

# echo "scsi-qlascan" > /proc/scsi/

where,

- = qla2100, qla2200, qla2300 (2.4 kernel drivers) or qla2xxx (2.6 kernel drivers)
- = the instance number of the HBA

After executing this command, force the SCSI mid layer to do its own scan and build the device table entry for the new device by typing the following command:

# echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi

where,

- "0 1 2 3" = your "Host Channel ID LUN"

The scanning must be done in the above-mentioned order; first the driver (qla2300/qla2200 driver, etc.) and then the Linux SCSI mid-layer (i.e. OS scan).

2. Scan lun with multipath/powermt

You can check the 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.

I hope you have enjoyed reading and let us know if you found any other method to scan storage disk devices.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is an experienced Linux engineer who has been supporting infrastructure for many companies. He specializes in Shell scripting, AWS Cloud, JavaScript, and Nodejs. He has qualified Master’s degree in computer science. He holds Red Hat Certified Engineer (RHCE) certification and RedHat Enable Sysadmin.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment