lsscsi
Introduction
In the 2.6 linux kernel series a new pseudo file system call sysfs
reflects the way that various devices and their drivers are configured
in the system. Sysfs support has been added to the SCSI subsystem (as
well as most other driver subsystems) so that a reasonable amount of
information can be deduced by scanning the sysfs tree. The lsscsi
command scans the sysfs tree and outputs information about SCSI
devices (or SCSI hosts) that are attached.
Details
The lsscsi command accesses
the sysfs file system (usually mounted under /sys ) to obtain information
rather than opening the SCSI device nodes (e.g. /dev/sda ) in the system.
Reading information within the sysfs file system is usually available
to all users (as is the information in procfs). However the permissions
on SCSI device nodes are necessarily tight which precludes normal users
from directly interrogating these devices. The lsscsi command will typically be
available to all users.
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/sr0
[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_id,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 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 device file node name. This assumes that the naming of
files in the /dev directory follows Linux conventions (if in doubt use
the '-d' option to see the device node's major and minor numbers). Note
that some distributions favour
the "/dev/scd0" over the older "/dev/sr0" form for CD/DVD devices. Also
note that the tape medium
exchanger does not have a primary device name and thus can only be
accessed via its corresponding scsi generic (sg) device name.
Here is a "long" variant of this command:
$ 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' 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
See "man lsscsi" for more information. The command also contains
usage information that can be output by using "lsscsi -h" or "lsscsi
--help".
lsscsi version 0.15 and 0.16 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 '-lll' option is given.
Download and Build information
Here is a table of the versions of lsscsi available for the lk 2.6
series.
Related utilities
In lk 2.6 various sysfs utilities are (becoming) available. See the sysfsutils
package for the systool utility that is more
generic than lsscsi.
Doug Gilbert (dgilbert@interlog.com)
Last updated: 30th December 2005