Linux – rely on scsi host numbers to always stay the same

hard drivelinuxscsi

I want to detect whether a disk is attached to the correct sata-port. While lsscsi gives me some useful information about the used host, I was wondering whether the SCSI host number will always stay the same:

[0:0:0:0]    disk    ATA      2.5" SATA SSD 3M P130  /dev/sda 
[1:0:0:0]    disk    ATA      2.5" SATA SSD 3M P130  /dev/sdb 
[4:0:0:0]    disk    ATA      SATADOM D150SV-L 1209  /dev/sdc 

A small test showed that neither rebooting the system nor a removal of one of the disks affects one of the other host numbers. In addition, I found the following at http://www.tldp.org/HOWTO/SCSI-2.4-HOWTO/scsiaddr.html:

The SCSI adapter number is typically an arbitrary numbering of the adapter cards on the internal IO buses (e.g. PCI, PCMCIA, ISA etc) of the computer. […] SCSI adapter numbers are issued by the kernel in ascending order starting with 0.

Both together leads me to the assumption that the SCSI host number should always stay the same on a system as the bus is always enumerated the same way? Is this correct?

UPDATE:
It seems that attaching an ATA Pass Through (ATP) device can change the host numbers of all devices.

Best Answer

I would never rely on the HCTL numbers to be stable. The host may change by addition of a new host or detection of a new device that will expose a new host that was unused until that moment. The kernel may have slightly different timings which will cause different hosts to be detected in a different order and devices being removed and reinserted may get different target numbers with each reinsert.

The values are only meaningful as a temporary identification but should not be used for persistent reference.

Related Topic