lsscsi utility for Linux
Keywords: lsscsi, linux storage scan, SCSI, sysfs

# lsscsi

1. lsscsi
   1. Introduction
   2. Overview
   3. Command line interface
   4. Transports
      1. FC
      2. 1394
      3. iSCSI
      4. SAS
      5. SPI
   5. lsscsi version 0.15 to 0.21 notes
   6. Download and Build information

## Introduction

The lsscsi command lists information about SCSI devices in Linux. Using SCSI terminology, lsscsi lists SCSI logical units (or SCSI targets when the '--transport' option is given). The default action is to produce one line of output for each SCSI device currently attached to the system.
When the '--hosts' option is given the lsscsi command lists information about SCSI hosts attached to the system. A host can be actual hardware (sometimes referred to as Host Bus Adapters (HBAs)) or virtual. An example of a virtual host is USB mass storage that bridges between USB and the SCSI subsystem. In SCSI parlance, a host is referred to as an SCSI initiator.
The lsscsi command scans the sysfs pseudo file system that was introduced in the 2.6 linux kernel series. Since most users have permissions to read sysfs (usually mounted at /sys ) then meta information can be found on some or all SCSI devices without a user needing elevated permissions to access special files (e.g. /dev/sda ). The lsscsi command can also show the relationship between a device's primary node name, its scsi generic (sg) node name and its kernel name.

## Overview

When executed without any options lsscsi outputs one line for each SCSI device attached to the system:
`$ lsscsi
[0:0:8:0] disk FUJITSU MAM3184MP 0105 /dev/sda
[2:0:0:0] cd CREATIVE CD5233E 1.00 /dev/scd0``
[3:0:5:0] tape HP C5713A H910 /dev/st0
[3:0:5:1] mediumx HP C5713A H910 -
` `[4:0:0:0] disk Linux scsi_debug 0004 /dev/sdb`
The first entry on each line is the scsi_host,channel,target_number,lun tuple. It is placed in brackets and each element is colon separated. When there are multiple SCSI devices their entries are sorted in ascending tuple order. The next column is the SCSI peripheral type; rather than using the formal name (e.g. "direct access device") a shorter name is used. Then follows the vendor name, the model name and the revision string. The last entry is the primary device node name. The "primary" device node name is associated with the upper level SCSI driver that "owns" the device. Examples of upper level SCSI drivers are sd (for disks), sr (for optical drives whose devices are often named /dev/scd<n> ) and st (for tapes). Some SCSI devices have peripheral types that either don't have upper level drivers to control them, or the associated driver module is not loaded. Such devices have '-' given for their device node name. All SCSI devices can be accessed via their corresponding scsi generic (sg) device node name (e.g. /dev/sg<n> ) which can be seen by adding a '--generic' option to the above lsscsi invocation.
Here is a "long" variant of this command. The '-l' (or '--long') option can be used multiple time for more output.
$ lscssi -l
`[0:0:1:0] disk FUJITSU MAM3184MP 0105 /dev/sda
state=running queue_depth=16 scsi_level=4 type=0 device_blocked=0 timeout=30`
The device node major and minor numbers can also be output with the '-d' option:
`$ lsscsi -d
[0:0:1:0] disk FUJITSU MAM3184MP 0105 /dev/sda[8:0]`
The '-g' (or '--generic') option can be used to show the corresponding scsi generic device name:
`$ lsscsi -g
[0:0:1:0] disk FUJITSU MAM3184MP 0105 /dev/sda /dev/sg0`
In "classic" mode lsscsi outputs a listing very similar to 'cat /proc/scsi/scsi'. This form of output should be familiar:
`$ lsscsi -c
Attached devices:`
`Host: scsi0 Channel: 00 Id: 08 Lun: 00
Vendor: FUJITSU Model: MAM3184MP Rev: 0105
Type: Direct-Access ANSI SCSI revision: 03
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: CREATIVE Model: CD5233E Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 02
Host: scsi3 Channel: 00 Id: 06 Lun: 00
Vendor: SONY Model: SDT-7000 Rev: 0192
Type: Sequential-Access ANSI SCSI revision: 02
Host: scsi4 Channel: 00 Id: 00 Lun: 00
Vendor: Linux Model: scsi_debug Rev: 0004
Type: Direct-Access ANSI SCSI revision: 03`
SCSI host information can be listed with the '-H' option:
$ lsscsi -H
[0] scsi_debug
[1] aha152x
$ lsscsi -Hl
[0] scsi_debug
cmd_per_lun=3 host_busy=0 sg_tablesize=64 unchecked_isa_dma=0
[1] aha152x
cmd_per_lun=1 host_busy=0 sg_tablesize=255 unchecked_isa_dma=0
$ lsscsi -Hlv
[0] scsi_debug
cmd_per_lun=3 host_busy=0 sg_tablesize=64 unchecked_isa_dma=0
dir: /sys/class/scsi_host/host0
device dir: /sys/devices/pseudo_0/adapter0/host0
[1] aha152x
cmd_per_lun=1 host_busy=0 sg_tablesize=255 unchecked_isa_dma=0
dir: /sys/class/scsi_host/host1
device dir: /sys/devices/platform/host1
For transport information see the section of that name below. Online there is a "man" page (invoked by 'man lsscsi') which contains information specific to the version of lsscsi installed on a machine. The command also contains usage information that can be output by using "lsscsi -h" or "lsscsi --help".

## Command line interface

The lsscsi command has this command line interface:
lsscsi [options] [filter]
The command line options are shown in table 1.
The filter argument is designed to select a subset of available devices (or hosts when the '--hosts' option is given [added version in 0.19]). The filter can comprise of up to four numbers, separated by ":" or spaces; alternatively it can be of the form "host<n>" where <n> is a host number. The four numbers represent host number, channel (or bus) number, target number and logical unit number (i.e. lun) respectively. The "-" symbol is used to represent a wildcard. For device listings, no filter argument is equivalent to "-:-:-:-". Numbers missing from the filter are treated as wildcards: hence "5:0:1" and "5:0:1:-" are the same.

Table 1. lsscsi command line options
long option format | short option format | version added | description
--classic | -c |  | generate output similar to 'cat /proc/scsi/scsi'
--device | -d |  | show device node's major and minor numbers
--generic | -g |  | show scsi generic device node name
--help | -h |  | print usage message then exit
--hosts | -H |  | rather than list SCSI devices (logical units), list SCSI hosts instead
--kname | -k | 0.15 | show kernel name (as found in sysfs) instead of device node name (as found in the /dev directory)
--list | -L | 0.19 | show <attribute>=<value> pairs, one per line, indented by two or more spaces
--long | -l |  | show <attribute>=<value> pairs, several to a line. can be used multiple times for more output and different format.
--transport | -t | 0.19 | show transport information. If '--hosts' not given then this will be for targets. If '--hosts' is given then this will be for initiators (i.e. hosts). More information shown when used with '--list'.
--verbose | -v |  | increase verbosity of output. May be used multiple times to further increase verbosity.
--version | -V |  | print out the version and the date of last code change then exits

The lsscsi man page and the usage message in the executable also show the command line syntax.

## Transports

When the '--transport' (or '-t') option is given lsscsi attempts to determine the transport being used and outputs information specific to that transport. In the case of modern transports that may include a world wide unique name or identifier. The transports for which extra information is provided are:

- Fibre channel (FC): substantial amount both for target and host
- IEEE 1394 (SBP): target and host
- iSCSI: target only
- SCSI Parallel Interface (SPI): trivial
- Serial Attached SCSI (SAS): substantial amount for both target and host

Even though lsscsi, in the absence of the '--hosts' option, shows logical unit information, once the '--transport' option is specified the output relates to the target which contains the logical unit. This occurs since the computer (and thus sysfs) see a "transport" (or interconnect) whose near end is a host (i.e. a SCSI initiator) and whose far end is a target. A target may contain one or more logical units (and in special cases a target may contain no logical units). SCSI initiators and targets can also have one or more ports. Linux tends to show each port of a target (that contains one logical unit) as two devices; to be more precise, linux shows a different device for each distinct path to a logical unit.
When the '--transport' option is given the SCSI INQUIRY strings (vendor, product and revision) usually output by lsscsi are replaced by a target name or identifier. Annex A in the SAM-4 document has been used as a guide for the appropriate initiator (i.e. host) and target names and identifiers to display.

### FC

For FC devices (logical units), the '--transport' option will show the port name and the port identifier instead of the SCSI INQUIRY "strings". For example:
$ lsscsi -g
[3:0:0:0] enclosu HP A6255A HP04 - /dev/sg3
[3:0:1:0] disk HP 36.4G ST336753FC HP00 /dev/sdd /dev/sg4
[3:0:2:0] disk HP 36.4G ST336753FC HP00 /dev/sde /dev/sg5
$ lsscsi -g --transport
[3:0:0:0] enclosu fc:0x50060b00002e48a3,0x0b109b - /dev/sg3
[3:0:1:0] disk fc:0x21000004cf97de68,0x0b109f /dev/sdd /dev/sg4
[3:0:2:0] disk fc:0x21000004cf97e385,0x0b10a3 /dev/sde /dev/sg5
Notice that the port name for the enclosure is naa-5 while the port names for the disks are naa-2. Since SAS also uses naa-5 the leading "fc:" indicates that the transport has been identified as FC. When '--list' is added, more transport information is provided in "name=value" pairs, indented by two or more spaces. The output is restricted to one disk by added the 3:0:2:0 filter:
$ lsscsi -t --list [3:0:2:0]
[3:0:2:0] disk fc:0x21000004cf97e385,0x0b10a3 /dev/sde
transport=fc
node_name=0x20000004cf97e385
port_name=0x21000004cf97e385
port_id=0x0b10a3
port_state=Online
roles=FCP Target
scsi_target_id=2
supported_classes=Class 3
dev_loss_tmo=35
When the '--hosts' option is used with '--transport' then transport information for the initiator (port) is output:
$ lsscsi --hosts --transport 3
[3] qla2xxx fc:0x50060b00741cc28e,0x0b1900
This shows for host 3 the driver is called qla2xxx, the transport is FC, the initiator's port name is in naa-5 format with the final (hex) number being the initiator's port identifier. Adding '--list' will again add "name=value" pairs:
$ lsscsi -H -t --list 3
[3] qla2xxx fc:0x50060b00741cc28e,0x0b1900
transport=fc
node_name=0x50060b00741cc28f
port_name=0x50060b00741cc28e
port_id=0x0b1900
port_type=NPort (fabric via point-to-point)
speed=2 Gbit
supported_classes=Class 3
tgtid_bind_type=wwpn (World Wide Port Name)
The "name=value" pairs are fetched from a sysfs directory (apart from "transport=fc") so the meaning should be what is defined by the transport. Too see which directory (or directories) provide this information add '-vvv'.

### 1394

There are two versions of the SBP SCSI standard known as SBP-2 and SBP-3 for conveying SCSI command sets over a IEEE 1394 transport. The SCSI commands sets are typically for accessing storage devices. Hence the acronym "SBP" is often associated with the IEEE 1394 transport in the storage context.
SBP defines world wide unique names for a target and initiator (host) using EUI-64 format. These names are what the lsscsi command fetches when the '-t' option is given:
$ lsscsi
[6:0:1:0] sim dsk QUANTUM FIREBALL SE3.2A /dev/sdk
$ lsscsi -t
[6:0:1:0] sim dsk sbp:00043b000000071d:1:0 /dev/sdk
$ lsscsi -t -L
[6:0:1:0] sim dsk sbp:00043b000000071d:1:0 /dev/sdk
transport=sbp
ieee1394_id=00043b000000071d:1:0
$ lsscsi -t -H
[6] sbp2 sbp:005042b500004a48
$ lsscsi -t -H -L
[6] sbp2 sbp:005042b500004a48
transport=sbp
The SBP standard requires that disks (typically ATA disks in an external enclosure) use the SCSI peripheral device type: "simplified direct access device". The is abbreviated by the lsscsi command to "sim dsk".

### iSCSI

The lsscsi command won't show anything iSCSI related on a machine with a iSCSI target running (either as a kernel driver or as a user space daemon). The following output is from a machine running a iSCSI initiator with a session established:
$ lsscsi
[2:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sda
$ lsscsi -t
[2:0:0:0] disk iqn.2001-04.com.example:sda.sdb.sdc,t,0x1 /dev/sda
$ lsscsi -t -L
[2:0:0:0] disk iqn.2001-04.com.example:sda.sdb.sdc,t,0x1 /dev/sda
transport=iSCSI
targetname=iqn.2001-04.com.example:sda.sdb.sdc
tpgt=1
data_pdu_in_order=1
data_seq_in_order=1
erl=0
first_burst_len=65536
initial_r2t=1
max_burst_len=262144
max_outstanding_r2t=1
recovery_tmo=120
$ lsscsi -t -H
[2] iscsi_tcp iscsi:
$ lsscsi -t -H -L
[2] iscsi_tcp iscsi:
transport=iSCSI
As can be seen, there is no useful host information (e.g. the iSCSI initiator name) when the '-H' option (or the '--hosts' option) is given. The information given for the target is session related. An iSCSI session is made up of 1 or more connections which have available information in sysfs but the lsscsi command doesn't output them currently.

### SAS

For SAS devices (logical units), the '--transport' option will show the target's SAS address instead of the SCSI INQUIRY "strings". For example:
$ lsscsi -t
[4:0:3:0] disk sas:0x5000d50001b02139 /dev/sdd
[4:0:4:0] disk sas:0x5000d500005208ed /dev/sde
[5:0:0:0] disk sas:5000d50001b02139 /dev/sdf
[5:0:1:0] disk sas:5000d500005208ed /dev/sdg
The SAS address is prefixed by "sas:" to identify the transport. The are currently two different representations and lsscsi prints out whatever is in the relevant sysfs attribute. When a '--list' (or '-L) option is added more information is output:
$ lsscsi -t -L [4:0:4:0]
[4:0:4:0] disk sas:0x5000d500005208ed /dev/sde
transport=sas
initiator_port_protocols=none
initiator_response_timeout=10000
I_T_nexus_loss_timeout=1744
phy_identifier=11
ready_led_meaning=1
sas_address=0x5000d500005208ed
target_port_protocols=ssp
# lsscsi -t -L [5:0:1:0]
[5:0:1:0] disk sas:5000d500005208ed /dev/sdg
transport=sas
sub_transport=sas_class
device_name=0000000000000000
dev_type=end device
iproto=
iresp_timeout=0x2710
itnl_timeout=0x07d0
linkrate=3,0 Gbps
max_linkrate=3,0 Gbps
max_pathways=1
min_linkrate=3,0 Gbps
pathways=1
ready_led_meaning=1
rl_wlun=0
sas_addr=5000d500005208ed
tproto=SSP
transport_layer_retries=0
Both 4:0:4:0 and 5:0:1:0 are the same logical unit accessed via the same target port but from different hosts. The two drivers (one for each host) choose to represent the same (target port) information in different ways.
When the '--hosts' option is added, then the SAS address of the initiator is output. In the case of SAS a Linux host corresponds to a initiator device (not one of its ports):
$ ./lsscsi -t -H
[0] sata_nv
[1] sata_nv
[2] sata_nv
[3] sata_nv
[4] mptsas sas:0x500605b000f6f260
[5] aic94xx sas:50000d100f2dc000
Adding a '--list' option will print multiple 'name=value' pair lines, each indented with two or more spaces.

### SPI

The SCSI parallel interface (SPI) can be detected (as indicated by the "spi:" prefix) but sysfs provides no world wide unique names (there may be some in the device identification VPD page). The only thing that is available in sysfs is the target identifier which is usually a number between 0 and 15 inclusive. The initiator (host) identifier is not provided by by convention it is usually 7. Following are some examples of target and host transport information for SPI:
$ lsscsi [0:0:1:0]
[0:0:1:0] disk HP 36.4G ST336753LC HPC7 /dev/sdb
$ lsscsi -t [0:0:1:0]
[0:0:1:0] disk spi:1 /dev/sdb
$ lsscsi -t -L [0:0:1:0]
[0:0:1:0] disk spi:1 /dev/sdb
transport=spi
target_id=1
dt=1
max_offset=127
max_width=1
min_period=6.25
offset=63
period=6.25
width=1
$ lsscsi -t -H [0:0:1:0]
[0] mptspi spi:
$ lsscsi -t -H -L [0:0:1:0]
[0] mptspi spi:
transport=spi
signalling=unknown

## lsscsi version 0.15 to 0.21 notes

These versions attempt to find the device name used in the /dev directory rather than the kernel generated name. The kernel generated name of the first SCSI disk discovered is /dev/sda . However in the lk 2.6 series kernels udev may be used to give this device some other name in the /dev directory, for example /dev/root_disk . By default this version will search for the device node name in the /dev directory whose type (i.e. block or char), major and minor numbers match the kernel device information found in sysfs. This change makes a SCSI (or USB, Firewire, etc) CD/DVD drive appear with a name like /dev/scd0 (as most distributions now use) rather than its kernel device node name of sr0 used by sysfs. There are other ways this could be done which would be more efficient in CPU usage, for example by lsscsi using the udevinfo facilities internally. This version of lsscsi can be given a '--kname' option to show the kernel (i.e. sysfs) device node name instead. Note that sysfs and SCSI errors and warning sent to the system log continue to use the kernel device node name.
By default lsscsi lists all SCSI devices (or hosts). This version allows select arguments to reduce the number of devices listed. For example "lsscsi 1" will list all channels, targets and luns within host1. A single SCSI device can be listed with 'lsscsi 1 0 0 0' (or 'lsscsi 1:0:0:0' or 'lsscsi [1:0:0:0]'). See man page for more information. This version of lsscsi uses the facilities of the scandir() library call to both select (filter) and sort the SCSI devices (or hosts) it finds in sysfs. Since libsysfs (version 1.2) doesn't have the ability to filter then this version of lsscsi uses scandir() [and not libsysfs]. Evidently a new version 2.0 API for libsysfs is under development (and I have requested a scandir() like select+sort facility).
Extra SCSI device and host attributes (as found in lk 2.6.12) can be seen by using the '--long' option twice (or more conveniently using '-ll'). Attributes are listed as "<name>=<value>" pairs, one per line (indented two spaces) when the '--list' option is given.

## Download and Build information

Here is a table of the versions of lsscsi available for the lk 2.6 series.

tarball | binary rpm **+ deb | source rpm ** | notes
lsscsi-0.11.tgz | lsscsi-0.11-1.i386.rpm | lsscsi-0.11-1.src.rpm | suitable for lk 2.6.1
lsscsi-0.12.tgz | lsscsi-0.12-1.i386.rpm | lsscsi-0.12-1.src.rpm | lk 2.6.6, add '-d' for device major+minor
lsscsi-0.13.tgz |  |  | lk 2.6.7 add timeout value to --long option
lsscsi-0.14.tgz | lsscsi-0.14-1.i386.rpm | lsscsi-0.14-1.src.rpm | port to use sysfsutils-1.2.0 or later
lsscsi-0.15.tgz | lsscsi-0.15-1.i386.rpm | lsscsi-0.15-1.src.rpm | lk 2.6.12 with optional select arguments and /dev scanning. Does not use libsysfs.
lsscsi-0.16.tgz | lsscsi-0.16-1.i386.rpm | lsscsi-0.16-1.src.rpm | lk 2.6.14, fixes for osst and ch devices, debian build. Does not use libsysfs.
lsscsi-0.17.tgz | lsscsi-0.17-1.i386.rpm | lsscsi-0.17-1.src.rpm | lk 2.6.16, kernel (sysfs) change that first appeared in lk 2.6.16-rc1 requires this version to see block devices
lsscsi-0.18.tgz | lsscsi-0.18-1.i386.rpm | lsscsi-0.18-1.src.rpm | allow for "generic" and "tape" symlinks to be dropped in sysfs.
lsscsi-0.19.tgz 20070125 | lsscsi-0.19-1.i386.rpm lsscsi_0.19-0.1_i386.deb | lsscsi-0.19-1.src.rpm | add transport information, '--list' option, fixes for lk 2.6.20
lsscsi-0.20.tgz 20080709 | lsscsi-0.20-1.i386.rpm lsscsi_0.20-0.1_i386.deb | lsscsi-0.20-1.src.rpm | for lk 2.6.26 when CONFIG_SYSFS_DEPRECATED_V2 not defined
lsscsi-0.21.tgz 20080910 | lsscsi-0.21-1.i386.rpm lsscsi_0.21-0.1_i386.deb | lsscsi-0.21-1.src.rpm | more changes for lk 2.6.26

Here is the most recent ChangeLog .

** Some browsers (e.g. firefox) may interpret a file with an extension of "rpm" as an audio file. In which case press the right button over the link and select "Save link as ..." to download the file.

Doug Gilbert (dgilbert@interlog.com)
Last updated: 10th july 2008