Finding informations about SCSI devices

The first problem when working with SCSI devices might be to map informations you got from /proc/scsi/scsi to the device names the kernel uses like /dev/sda and so on.

Or you can use lsscsi utlity. Here's an example:

# lsscsi
[0:0:0:0]    disk    ATA      SEAGATE ST31000N SU0E  /dev/sda
[0:0:1:0]    disk    ATA      SEAGATE ST31000N SU0E  /dev/sdb
...
[1:0:1:0]    disk    ATA      SEAGATE ST31000N SU0E  /dev/sdj
[1:0:2:0]    disk    ATA      SEAGATE ST31000N SU0E  /dev/sdk
[1:0:3:0]    disk    ATA      HITACHI H7210CA3 A3CB  /dev/sdl
[1:0:4:0]    disk    ATA      HITACHI HUA7210S AC5A  /dev/sdm
...
[5:0:7:0]    disk    ATA      SEAGATE ST31000N SU0D  /dev/sdav
[6:0:0:0]    mediumx IBM      TS3500           0104  /dev/sch0
[6:0:1:0]    tape    IBM      ULT3580-TD5      0104  /dev/st0
[6:0:2:0]    tape    IBM      ULT3580-TD5      0104  /dev/st1

You can find same info by checking /proc/scsi/scsi

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: SEAGATE ST31000N Rev: SU0E
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: ATA      Model: SEAGATE ST31000N Rev: SU0E
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: ATA      Model: SEAGATE ST31000N Rev: SU0E
  Type:   Direct-Access                    ANSI  SCSI revision: 05
...

In the example above

Host: scsi0 Channel: 00 Id: 01 Lun: 00 
is the same device of [0:0:0:0] in the output of lsscsi

Where the output

          h == hostadapter id (first one being 0)
          c == SCSI channel on hostadapter (first one being 0)
          t == ID
          l == LUN (first one being 0)

Rescan of a SCSI bus

Surely reboot a server will let the scsi device get rescanned. But this is not the prefered way. The easiest way is to rescan the whole SCSI bus which will enable the Linux kernel to detect new devices!

To issue a SCSI bus rescan you must know on which bus you've added the device. If you don't know which bus and if there are mutliple buses on the system you can rescan each bus which will be somehow annoying but will not interrupt the system.
To initiate a SCSI bus rescan type

echo "- - -" > /sys/class/scsi_host/host<H>/scan

where H stands for the SCSI bus you want to scan.

# lsscsi
...
[1:0:0:7]    disk    IBM      1814      FAStT  1060  /dev/sdb
[1:0:0:8]    disk    IBM      1814      FAStT  1060  /dev/sdc
[1:0:0:10]   disk    IBM      1814      FAStT  1060  /dev/sde
# echo "- - -" > /sys/class/scsi_host/host1/scan
# lsscsi
...
[1:0:0:7]    disk    IBM      1814      FAStT  1060  /dev/sdb
[1:0:0:8]    disk    IBM      1814      FAStT  1060  /dev/sdc
[1:0:0:9]    disk    IBM      1814      FAStT  1060  /dev/sdd
[1:0:0:10]   disk    IBM      1814      FAStT  1060  /dev/sde

Well done, we got /dev/sdd back.

By the way this does not only work for disks but also for SCSI CD/DVD devices.

You can still use the old way, to get sdd back

echo "scsi add-single-device 1 0 0 9" > /proc/scsi/scsi

For more devices, you have to repeat the same for all devices

Deletion of a SCSI Device

There might be the situation where you must remove a SCSI device from the system.

Easy by using

    echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete
    or
    echo 1 > /sys/block/<dev>/device/delete
    where <dev> is like sda or sdb etc..

Here's an example:

# echo 1 > /sys/block/sdau/device/delete 
# lsscsi | grep sdau
#

Now you see the device sdau is gone.

In old way, this is what you would like to do

echo "scsi remove-single-device h c t l" > /proc/scsi/scsi

Add a SCSI Device back

Surely this can be done just rescan the SCSI bus that the disk seats inuse wildcard like below

    echo "- - -" > /sys/class/scsi_host/host<h>/scan

You can also do this if you know the device SCSI location h:c:t:l

    echo "c t l" >  /sys/class/scsi_host/host<h>/scan

Old way

    echo "scsi add-single-device a b c d" > /proc/scsi/scsi

Rescan of a SCSI Device

The problem of a SCSI bus rescan is, that it will only detect new devices. Can a existing or missing device be rescanned?

Sure, here is it

echo 1 > /sys/block/sdau/device/rescan 
or
echo 1 > /sys/class/scsi_device/h:c:t:l/device/rescan

 In SAN environment, there is a easier way to manage SAN scsi devices, see Sysfs fibre channel tools