SCSI
- Concepts
- Applications
- lsscsi – list SCSI devices (or hosts) and their attributes
- sg_map – displays mapping between Linux sg and other SCSI devices
- sg_reset – sends SCSI device, target, bus or host reset; or checks reset state
- sg_logs – access log pages with SCSI LOG SENSE command
- scsi_id – retrieve and generate a unique SCSI identifier
- Tasks
Concepts
Devices naming
Tape drives are named /dev/st<num> or /dev/nst<num> where <num> starts at zero.
CD, DVD and BD readers (and writers) are named /dev/sr<num> where <num> start at zero.
There is also a SCSI device driver which offers alternate generic access to SCSI devices. It uses names of the form /dev/sg<num> where <num> starts at zero.
There’s also a block SCSI generic driver with names are of the form /dev/bsg/<h:c:t:l> where h, c, t and l are numbers.
Initiator and target
a SCSI initiator is the endpoint that initiates a SCSI session, that is, sends a SCSI command.
a SCSI target is the endpoint that does not initiate sessions, but instead waits for initiators’ commands and provides required input/output data transfers. The target usually provides to the initiators one or more LUNs, because otherwise no read or write command would be possible.
https://en.wikipedia.org/wiki/SCSI_initiator_and_target
Logical unit number
LUN = logical unit number (disk, tape drive, whatever)
H:C:T:L
- ‘H’ is the host number
- ‘C’ is the controller number
- ”T’ is the target number
- ‘L’ is the Logical Unit Number (LUN)
Applications
lsscsi – list SCSI devices (or hosts) and their attributes
lsscsi
lsscsi --classic
lsscsi --hosts
lsscsi -t --hosts
-g, –generic: Output the SCSI generic device file name. Note that if the sg driver is a module it may need to be loaded otherwise ‘-‘ may appear.
lsscsi -g
sg_map – displays mapping between Linux sg and other SCSI devices
$ sg_map
/dev/sg0
/dev/sg1 /dev/sda
/dev/sg2 /dev/nst0
/dev/sg3 /dev/nst1
/dev/sg4
/dev/sg5 /dev/sdb
/dev/sg6
/dev/sg7 /dev/sdc
/dev/sg8
/dev/sg9 /dev/sdd
/dev/sg10
/dev/sg11 /dev/sde
/dev/sg12
/dev/sg13 /dev/sdf
/dev/sg14
/dev/sg15 /dev/sdg
/dev/sg16
/dev/sg17 /dev/sdh
/dev/sg18
/dev/sg19 /dev/sdi
/dev/sg20
sg_reset – sends SCSI device, target, bus or host reset; or checks reset state
sg_reset --device /dev/sg5
sg_reset --host /dev/sg5
sg_logs – access log pages with SCSI LOG SENSE command
sg_logs -a /dev/tape/by-id/scsi-3500110a00169f43e-nst
scsi_id – retrieve and generate a unique SCSI identifier
This thing is not in the PATH so you have to use the full path to it: /lib/udev/scsi_id
By default all devices are assumed black listed, the --whitelisted
option must be specified on the command line or in the config file for any useful behavior.
Documentation: https://linux.die.net/man/8/scsi_id
How to get the WWID of a device
Local SATA drive:
$ sudo /lib/udev/scsi_id --whitelisted --device=/dev/sdb
350025388a09c1ac7
Fiber attached drive (the end result includes the fiber controller information):
$ sudo /lib/udev/scsi_id --whitelisted --device=/dev/sdj
3600d02310009005d1d40b1687687dfe0
Documentation: https://linux.die.net/man/8/scsi_id
Tasks
Delete a LUN ( [11:0:2:1] ):
echo 1 > '/sys/class/scsi_host/host8/device/rport-8:0-10/target8:0:10/8:0:10:0/delete'
After removing a LUN (here my fiber card is host5):
echo "- - -" > /sys/class/scsi_host/host5/scan
If the size of a LUN changed:
echo 1 > /sys/block/sdX/device/rescan
Delete a block device:
echo 1 > /sys/block/sdaa/device/delete
Documentation: