lsscsi命令

本文转自:http://sg.danny.cz/scsi/lsscsi.html#mozTocId782775

  1. lsscsi
  2. Introduction
  3. Overview
  4. Command line interface
  5. Transports
    1. ATA
    2. FC
    3. 1394
    4. iSCSI
    5. SAS
    6. SATA
    7. SPI
    8. SRP
    9. USB
  6. Examples
  7. 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.

The lsscsi command works in the 2.6 and 3 Linux kernel series.

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.

By adding the '--size' option ('-s' in its short form) the size of disks is shown to the right of each line:
# lsscsi -s
[0:0:0:0]    cd/dvd  PIONEER  DVD-RW  DVR-212D 1.22  /dev/sr0        -
[1:0:0:0]    disk    ATA      ST3320620AS      3.AA  /dev/sda    320GB
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdb   2.00TB

If the device is not a disk or its size is not available than '-' is output instead of a size.

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


Most modern storage devices have world wide unique identifiers. For an ATA or SATA disk this is known as a WWN. For a SCSI device the formal term is an Logical Unit (LU) name which comes in several forms including NAA and EUI-64 numbers and SCSI name strings as used by iSCSI. The '-u (or '--unit') option will show the LU_name/WWN in place of the manufacturer, product and revision strings:
$ lsscsi
[5:0:0:0]    disk    FreeBSD  iSCSI Disk       0123  /dev/sdb
$ lsscsi -u
[5:0:0:0]    disk    iqn.2011-03.org.example.istgt:12_ /dev/sdb

The url type name used by iSCSI (called an IQN) is too large to fit where the manufacturer, product and revision strings were so it is truncated to the right with the underscore as an indication of that truncation. To see the whole IQN (and the device name to the right is dropped) use:
$ lsscsi -uuu
[5:0:0:0]    disk    iqn.2011-03.org.example.istgt:1200ssd-tgt,lun,0

In "classic" mode lsscsi outputs a listing very similar to 'cat /proc/scsi/scsi' as often used in the Linux 2.4 series. This form of output should be familiar to long term users of Linux:
$ 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".

Currently bsg device node names are not shown by lsscsi but are quite simple to construct from the information provided. bsg node names start with '/dev/bsg/' followed by a scsi_host,channel,target_number,LUN tuple. For example for this device:
[4:0:0:0]    disk    Linux    scsi_debug       0004  /dev/sdb

the bsg node name is '/dev/bsg/4:0:0:0'. Note that the shell may interpret ":" as a special character in certain contexts so it may need to be escaped or placed between quotes.

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 "-", "*" or "?" symbols is used to represent a wildcard. If "-" is used as a wild card then the filter argument should be prefixed by "-- " in order to distinguish it from an option lead-in character. When "*" or "?" are used as wildcard the filter should be surrounded by single or double quotes to stop shell filename expansions. 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 formatshort option formatversion
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-k0.15show kernel name (as found in sysfs) instead of device node name (as found in the /dev directory)
--list-L0.19show <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.
--lunhex-x0.27show the LUN part of the tuple as hex following T10 (SAM-5) conventions.
--protection-p0.22show protection information (T10-DIF).
--protmode-P0.25show negotiated protection information mode
--scsi_id-i0.27show udev derived information in /dev/disk/by-id/ directory
--size-s0.25show disk size in human readable form
--sysfsroot=PATH-y0.23Uses PATH as sysfs mount point (default sysfs mount point is '/sys')
--transport-t0.19show 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'.
--unit-u0.28show the LU name in the place of the manufacturer, model and revision. Needs lk >= 3.15
--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
--wwn-w0.26show the WWN for disks in the place of the manufacturer, model and revision

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:

  • ATA
  • Fibre channel (FC): substantial amount both for target and host
  • IEEE 1394 (SBP): target and host
  • iSCSI: target only
  • Serial Attached SCSI (SAS): substantial amount for both target and host
  • SATA
  • SCSI Parallel Interface (SPI): trivial
  • SCSI RDMA (Remote Direct Memory Access) Protocol (SRP)
  • USB

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.

From lsscsi version 0.28 the '--unit' option will show Logical Unit (LU) name derived from device identification VPD page which first became available in sysfs in lk 3.15 . For most modern SCSI devices the LU name should be a world wide unique number (or string in the case of iSCSI).

ATA

The detection of  parallel ATA devices is somewhat crude and is performed after checks are made for more traditional SCSI transports. The identification of an ATA transport is made on the basis of the low level driver name that the device or host uses. A similar mechanism is used to detect SATA devices and there is some overlap since some drivers support both SATA and PATA devices. No other attributes are provided. For example:
$ lsscsi
[0:0:0:0]    disk    ATA      FUJITSU MHY2160B 0000  /dev/sda
[3:0:0:0]    cd/dvd  MATSHITA DVD/CDRW UJDA775 CB03  /dev/scd0
[5:0:0:0]    disk    USB 2.0  SD/MMC Reader          /dev/sdb
[6:0:0:0]    disk    JetFlash TS2GJFVxx        8.01  /dev/sdc
$ lsscsi -t
[0:0:0:0]    disk    sata:                           /dev/sda
[3:0:0:0]    cd/dvd  ata:                            /dev/scd0
[5:0:0:0]    disk    usb: 7-1:1.0                    /dev/sdb
[6:0:0:0]    disk    usb: 7-2.4:1.0                  /dev/sdc
$ lsscsi -Ht
[0]    ahci          sata:
[1]    ahci          sata:
[2]    ahci          sata:
[3]    ata_piix      ata:
[4]    ata_piix      ata:
[5]    usb-storage   usb: 7-1:1.0
[6]    usb-storage   usb: 7-2.4:1.0

In this case the device at 3:0:0:0 (and device node /dev/scd0) is a DVD/CD drive whose transport is (parallel) ATA. That device is attached to host3 which is associated with the ata_piix driver.

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 (port) 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.

SATA

The detection of serial ATA (SATA) devices is somewhat crude and is performed after checks are made for more traditional SCSI transports. The identification of an SATA transport is made on the basis of the low level driver name that the device or host uses. A similar mechanism is used to detect  parallel ATA devices and there is some overlap since some drivers support both SATA and PATA devices. No other attributes are provided. See the example in the ATA section, specifically device 0:0:0:0 and the associated host0.

SPI

The SCSI parallel interface (SPI) can be detected and is indicated by the "spi:" prefix. Sysfs provides no world wide unique names (until lk 3.15 when it provides the device identification VPD page). The only thing that is available 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

SRP

The SCSI RDMA Protocol (SRP) transport can be detected and is indicated by the "srp:" prefix. Support was added in lsscsi version 0.28 . Here are some examples from its contributor, Bart Van Assche:

$ ibstat | grep 'Port GUID'
                Port GUID: 0x0002c90300a05281
                Port GUID: 0x0002c90300a05282
                Port GUID: 0x0002c90300a02d71
                Port GUID: 0x0002c90300a02d72

$ lsscsi -t
[0:0:0:0]    disk                                    /dev/sda
[0:3:0:0]    storage                                 -
[1:0:0:0]    disk    srp:0002:c903:00a0:5281         /dev/sdb
[1:0:0:1]    disk    srp:0002:c903:00a0:5281         /dev/sdc
[1:0:0:2]    disk    srp:0002:c903:00a0:5281         /dev/sdd
[1:0:0:3]    disk    srp:0002:c903:00a0:5281         /dev/sde
[1:0:0:4]    disk    srp:0002:c903:00a0:5281         /dev/sdf
[1:0:0:5]    disk    srp:0002:c903:00a0:5281         /dev/sdg
[1:0:0:6]    disk    srp:0002:c903:00a0:5281         /dev/sdh
[1:0:0:7]    disk    srp:0002:c903:00a0:5281         /dev/sdi

$ lsscsi --list -t | head
[0:0:0:0]    disk                                    /dev/sda
[0:3:0:0]    storage                                 -
[1:0:0:0]    disk    srp:0002:c903:00a0:5281         /dev/sdb
  transport=srp
  orig_dgid=f452:1403:0015:6021
  dgid=f452:1403:0015:6021
[1:0:0:1]    disk    srp:0002:c903:00a0:5281         /dev/sdc
  transport=srp
  orig_dgid=f452:1403:0015:6021
  dgid=f452:1403:0015:6021

USB

When a USB transport is detected the device or host summary line will contain "usb:" followed by a USB device name. The USB device name has the form "<b>-<p1>[.<p2>]+:<c>.<i>" where <b> is the USB bus number, <p1> is the port on the host. <p2> is a port on a host connected hub, if  present. If needed <p3> is another USB hub port closer to the USB storage device. <c> refers to the configuration number while <i> is the interface number. There is a separate USB SCSI host for each USB (SCSI) target. A USB SCSI target may contain multiple logical units. Thus the same "usb: <device_name>" string appears for a USB SCSI host and all logical units that belong to the USB SCSI target associated with that USB SCSI host. See the example in the ATA section, specifically devices 5:0:0:0 and 6:0:0:0 . 5:0:0:0 is connected directly to a laptop while 6:0:0:0 is connected via an external hub.

Examples

Here is the output from a not so typical machine. It has a directly attached SATA DVD drive and one SATA disk (/dev/sda). The remaining devices are attached via an external SAS expander which has its own SES management device [6:0:2:0] :

# lsscsi
[0:0:0:0]    cd/dvd  PIONEER  DVD-RW  DVR-212D 1.22  /dev/sr0
[1:0:0:0]    disk    ATA      ST3320620AS      3.AA  /dev/sda
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdb
[6:0:1:0]    disk    ATA      ST3500418AS      CC34  /dev/sdc
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -       
[6:0:3:0]    disk    SEAGATE  ST373455SS       2189  /dev/sdd

Below are some examples of filters:

# lsscsi -- 1:-:-:-
[1:0:0:0]    disk    ATA      ST3320620AS      3.AA  /dev/sda

# lsscsi "*:*:2"
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -

# lsscsi 0
[0:0:0:0]    cd/dvd  PIONEER  DVD-RW  DVR-212D 1.22  /dev/sr0

# lsscsi 2
#

# lsscsi 6
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdb
[6:0:1:0]    disk    ATA      ST3500418AS      CC34  /dev/sdc
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -       
[6:0:3:0]    disk    SEAGATE  ST373455SS       2189  /dev/sdd


Now let's look at the sizes of the disks using the '--size' or '-s' option. The size of a DVD disk, even if there is one in the drive and it is mounted, is not shown. And there is no size associated with the enclosure (SES) device:

# lsscsi -s
[0:0:0:0]    cd/dvd  PIONEER  DVD-RW  DVR-212D 1.22  /dev/sr0        -
[1:0:0:0]    disk    ATA      ST3320620AS      3.AA  /dev/sda    320GB
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdb   2.00TB
[6:0:1:0]    disk    ATA      ST3500418AS      CC34  /dev/sdc    500GB
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -               -
[6:0:3:0]    disk    SEAGATE  ST373455SS       2189  /dev/sdd   73.4GB

So how to access that enclosure (SES) device? Use the '--generic' or '-g' option to see the corresponding SCSI generic device names:

# lsscsi -g
[0:0:0:0]    cd/dvd  PIONEER  DVD-RW  DVR-212D 1.22  /dev/sr0   /dev/sg0
[1:0:0:0]    disk    ATA      ST3320620AS      3.AA  /dev/sda   /dev/sg1
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdb   /dev/sg2
[6:0:1:0]    disk    ATA      ST3500418AS      CC34  /dev/sdc   /dev/sg3
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -          /dev/sg4
[6:0:3:0]    disk    SEAGATE  ST373455SS       2189  /dev/sdd   /dev/sg5

So the enclosure device can be accessed via /dev/sg4 (e.g. with a command like 'sg_ses /dev/sg4'). The lsscsi utility does not show the bsg device name but it is easily constructed from the above information; in this case it will be '/dev/bsg/6:0:2:0'. Note, depending on the context, those ":" characters may need to be escaped lest the shell interprets them as special characters.

Version 0.26 adds the '--wwn' option to display the World Wide Number of a disk (i.e. Logical Unit name in SCSI terminology), typically in NAA-5 format. Following is lsscsi invoked with no option, the '--wwn' option then the '--transport' option:

# lsscsi
[1:0:0:0]    disk    ATA      ST3160812AS      3.AA  /dev/sda
[6:0:0:0]    disk    ATA      ST3500418AS      CC34  /dev/sdb
[6:0:1:0]    disk    SEAGATE  ST32000444SS     0006  /dev/sdc
[6:0:2:0]    enclosu Intel    RES2SV240        0600  -

# lsscsi --wwn
[1:0:0:0]    disk    ATA      ST3160812AS      3.AA                                  /dev/sda
[6:0:0:0]    disk    ATA      ST3500418AS      CC34 
0x5000c500120bfe84              /dev/sdb
[6:0:1:0]    disk    SEAGATE  ST32000444SS     0006 
0x5000c500215725bf              /dev/sdc
[6:0:2:0]    enclosu Intel    RES2SV240        0600                                  -
     

# lsscsi --transport
[1:0:0:0]    disk    sata:                           /dev/sda
[6:0:0:0]    disk    sas:0x5001517e85c3efe5          /dev/sdb
[6:0:1:0]    disk    sas:0x5000c500215725bd          /dev/sdc
[6:0:2:0]    enclosu sas:0x5001517e85c3effd          -    


Notice that both the '--wwn' and '--transport' options replace the manufacturer, model and revision information. The disk at /dev/sda is an older SATA model that doesn't have a WWN and is connected via a SATA controller on the computer motherboard. The other two disks are connected via a SAS expander: /dev/sdb is a newer SATA disk with a WWN while /dev/sdc is a SAS disk which all have WWNs (a.k.a. "Logical unit name"). The 'lsscsi --transport' output is showing the transport type (as seen by Linux (hence "sas" for /dev/sdb)) and the target port identifier (which in SAS is a SAS address). Notice the WWN and target port identifier for /dev/sdc are close but not the same. The situation for a SATA disk behind a SAS expander is a little different for the target port identifier (look at the '--wwn' and '--transport' output for /dev/sdb), as the SAS expander "makes up" the target port identifier. The enclosure at 6:0:2:0 is closely associated with the SAS expander and the enclosure actually does have a WWN but udev (as used by lsscsi to data-mine the /dev directory) does not make it available, so it is not displayed. The sg_vpd utility (with the '-i' option) can be used to find the enclosure's WWN.

Version 0.27 added the '--lunhex' option (short form: '-x'). Below are some examples, the first shows the last element of the tuple when the '--lunhex' option is not given:

# lsscsi -g
[0:0:0:0]    disk    ATA      INTEL SSDSC2CW12 400i  /dev/sda   /dev/sg0
[7:0:0:1]    disk    Linux    scsi_debug       0004  /dev/sdb   /dev/sg1
[7:0:0:49409]wlun    Linux    scsi_debug       0004  -          /dev/sg2

# lsscsi -g --lunhex
[0:0:0:0x0000]              disk    ATA      INTEL SSDSC2CW12 400i  /dev/sda   /dev/sg0
[7:0:0:0x0001]              disk    Linux    scsi_debug       0004  /dev/sdb   /dev/sg1
[7:0:0:0xc101]              wlun    Linux    scsi_debug       0004  -          /dev/sg2

# lsscsi -xx
[0:0:0:0x0000000000000000]  disk    ATA      INTEL SSDSC2CW12 400i  /dev/sda
[7:0:0:0x0001000000000000]  disk    Linux    scsi_debug       0004  /dev/sdb
[7:0:0:0xc101000000000000]  wlun    Linux    scsi_debug       0004  -

Version 0.27 added the '--scsi_id' option (short form: '-i'):

# lsscsi -i
[0:0:0:0]    disk    ATA      INTEL SSDSC2CW12 400i  /dev/sda   SATA_INTEL_SSDSC2CW1CVCV
[6:0:0:1]    disk    Linux    scsi_debug       0004  /dev/sdb   353333330000036b1
[6:0:0:49409]wlun    Linux    scsi_debug       0004  -          -

Version 0.28 added the '--unit' option (short form: '-u'). It outputs the LU name as provided by the device identification VPD page, or the WWN for  SATA disks. That VPD page became available in lk 3.15 so this option will not work (i.e. outputs spaces) for older kernels. For a mixed SAS (with expanders) and SATA environment that has these manufacturer, product, revision strings:
# lsscsi
[3:0:0:0]    disk    ATA      ST3160812AS      D     /dev/sda
[6:0:0:0]    disk    SEAGATE  ST32000444SS     0008  /dev/sdf
[6:0:1:0]    enclosu Areca    ARC-802801.13.1D 0113  -       
[6:0:2:0]    disk    ATA      ST500LM000-1EJ16 DEM6  /dev/sdg
[6:0:3:0]    enclosu Intel    RES2SV240        0d00  -       
[6:0:4:0]    disk    ATA      ST3500418AS      CC34  /dev/sdh

The LU names can look like this:
# lsscsi -u
[3:0:0:0]    disk                                      /dev/sda
[6:0:0:0]    disk    5000c500215925bf                  /dev/sdf
[6:0:1:0]    enclosu 5001b4d516e9c03d                  -       
[6:0:2:0]    disk    5000c50072e9d0c4                  /dev/sdg
[6:0:3:0]    enclosu 5001517e85c9effd                  -       
[6:0:4:0]    disk    5000c5001209fe84                  /dev/sdh

The first disk is a relatively old SATA disk that does not have a WWN, hence the blanks. An example of using '-u' with an iSCSI device is given in the Overview section. When '--unit' is compared with '--wwn' it can be seen that the former is more general and is now preferred. For example '--unit' will show the LU name of non-disk devices such as enclosures and handle iSCSI devices (but the '--wwn' option will not).

Download and Build information

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

tarballbinary rpm + debsource rpmnotes
lsscsi-0.11.tgzlsscsi-0.11-1.i386.rpmlsscsi-0.11-1.src.rpmsuitable for lk 2.6.1
lsscsi-0.12.tgzlsscsi-0.12-1.i386.rpmlsscsi-0.12-1.src.rpmlk 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.tgzlsscsi-0.14-1.i386.rpmlsscsi-0.14-1.src.rpmport to use sysfsutils-1.2.0  or later
lsscsi-0.15.tgzlsscsi-0.15-1.i386.rpmlsscsi-0.15-1.src.rpmlk 2.6.12 with optional select arguments and /dev scanning. Does not use libsysfs.
lsscsi-0.16.tgzlsscsi-0.16-1.i386.rpmlsscsi-0.16-1.src.rpmlk 2.6.14, fixes for osst and ch devices, Debian build. Does not use libsysfs.
lsscsi-0.17.tgzlsscsi-0.17-1.i386.rpmlsscsi-0.17-1.src.rpmlk 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.tgzlsscsi-0.18-1.i386.rpmlsscsi-0.18-1.src.rpmallow 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.rpmadd 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.rpmfor 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.rpmmore changes for lk 2.6.26
lsscsi-0.22.tgz
20081226
lsscsi-0.22-1.i386.rpm
lsscsi_0.22-0.1_i386.deb
lsscsi-0.22-1.src.rpmshow protection information with '--protection' option, ATA, SATA and USB transport information
lsscsi-0.23.tgz
20091203
lsscsi-0.23-1.i386.rpm
lsscsi_0.23-0.1_i386.deb
lsscsi-0.23-1.src.rpmstop scanning /proc/mounts; assume /sys unless overridden by '--sysfsroot=PATH' option
lsscsi-0.24.tgz
20101224
lsscsi-0.24-1.i386.rpm
lsscsi_0.24-0.1_i386.deb
lsscsi-0.24-1.src.rpmadd "(null)" to the currently accepted "<NULL>" as the string representation of NULL; FC transport syntax changes (colon to slash). Needed around lk 2.6.32 and later
lsscsi-0.25.tgz
20110509
lsscsi-0.25-1.i386.rpm
lsscsi_0.25-0.1_i386.deb
lsscsi-0.25-1.src.rpm add --size and --protmode options
lsscsi-0.26.tgz
20120219
lsscsi-0.26-1.i386.rpm
lsscsi_0.26-0.1_i386.deb
lsscsi-0.26-1.src.rpmadd --wwn option and support for FCoE
lsscsi-0.27.tgz
20130508
lsscsi-0.27-1.i386.rpm
lsscsi-0.27-1.x86_64.rpm
lsscsi_0.27-0.1_i386.deb
lsscsi_0.27-0.1_amd64.deb
lsscsi-0.27-1.src.rpmadd --lunhex (-x)  option: accept Linux LUN numbers from sysfs as large as 64 bits. Add scsi_id (-i) option: udev derived information from /dev/disk/by-id/ . Improve handling of large number of disks.
lsscsi-0.28.tgz
20141127
lsscsi-0.28-1.i386.rpm
lsscsi-0.28-1.x86_64.rpm
lsscsi_0.28-0.1_i386.deb
lsscsi_0.28-0.1_amd64.deb
lsscsi-0.28-1.src.rpmadd --unit (-u) option: display LU name or WWN for ATA disks; requires lk >= 3.15 .

Here is the most recent ChangeLog .

To build from the tarball, extract its contents, move to the top level directory in the extracted sub-tree then do './configure ; make ; make install', Normal autotools conventions apply. If some configuration files are altered then the ./autogen.sh script may need to be called. The ./build_debian.sh script is provided to create a Debian package. A lsscsi.spec file is provided to facilitate building a "rpm" style package.

Return to main page.


 

Doug Gilbert (dgilbert@interlog.com)
Last updated: 27th November 2014

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值