Tuesday, December 18, 2007

How to scan the SCSI bus with a 2.6 kernel

If you are playing with SCSI devices (like Fibre Channel, SAS, ..) you sometimes need to rescan the SCSI bus to add devices or to tell the kernel a device is gone. Well, this is the way to do it in CentOS with versions that have a 2.6 kernel. This means CentOS 5 and CentOS 4 (starting from update 3).
  1. Find what's the host number for the HBA:
    ls /sys/class/fc_host/
    (You'll have something like host1 or host2, I'll refer to them as host$NUMBER from now on)

  2. Ask the HBA to issue a LIP signal to rescan the FC bus:
    echo 1 >/sys/class/fc_host/host$NUMBER/issue_lip
  3. Wait around 15 seconds for the LIP command to have effect

  4. Ask Linux to rescan the SCSI devices on that HBA:
    echo - - - >/sys/class/scsi_host/host$NUMBER/scan
    The wildcards "- - -" mean to look at every channel, every target, every lun.
That's it. You can look for log messages at "dmesg" to see if it's working, and you can look at /proc/scsi/scsi to see if the devices are there. In CentOS 5 there is also the "lsscsi" command that will show you the know devices plus the device entries that point to those devices (very usefull).

For more information about how this works see the the upstream release notes for 4.3.

136 comments: