Linux Scan for New Scsi Device to Detect New Lun Without Reboot

Once storage lun are mapped or allocated, its linux admin to verify on its available on the server. Reboot is one option to see the allocated disk and another option is to scan. This article I will show which command needs to be used on linux server.

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

Scan for new disk

Now to rescan the bus, use the following command

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

Now let us verify if new disks appear on existing 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/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 sectors
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
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

or with the fdisk command

# 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

You can see on the last line /dev/sdc: 10.7 GB and /dev/sdd: 14.0 GB which are our new disks detected.

The three dash ("-  -  -") of the command

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

act as wildcards meaning rescan everything. Remember that the three values normally stand for channel, SCSI target ID, and 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

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

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 use this one for Fibre Channel lun

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

When you add new disks, first find your host bus number with the command below

# 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

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

Conclusion

To scan new FC LUNS and SCSI disks in Linux without rebooting the server, you can use the echo script command for a manual scan. 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. It is important to know the two methods because most of the time, rescan script can not be available to scan new disks and you will need to go with echo command.

Bobbin Zachariah 11:42 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.