Site icon UnixArena

LINUX – SCSI Device Management – Identifying Devices

Linux SCSI Devices Management

Linux SCSI Devices Management

This article is going to share very least used SCSI commands on Linux operating systems. These commands will be very useful to identifying SCSI devices and tuneable parameters. There are few utilities which can be used to get the detailed information about the scsi devices. lsscsi is most command tool which scans sysfs pseudo file system to provide the required information. The lsscsi command should show the relationship between a device’s primary node name (SCSI generic (sg) node name) and kernel name. “sdparm”  command is used to view and set values contained in various mode pages supported by SCSI. Commands are supported by scsi devices which carries across many transports like ATAPI , PATA ,SATA , SPI , SAS, FCP , USB, ISCSI.

 

1. Reading /proc filesystems devices are the easiest way of to identify the scsi devices.

[root@UARHEL1 ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: VBOX     Model: HARDDISK         Rev: 1.0
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: VBOX     Model: CD-ROM           Rev: 1.0
  Type:   CD-ROM                           ANSI  SCSI revision: 05
[root@UARHEL1 ~]# 

 

2. lsscsi is the most of the command utility to list the SCSI devices. If lsscsi is not found , You must install lsscsi.x86_64 package.

[root@UARHEL1 ~]# lsscsi
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0
[2:0:0:0]    disk    VBOX     HARDDISK         1.0   /dev/sda
[root@UARHEL1 ~]#

 

3.To know the SCSI device queue depth ,use “-l” option.

[root@UARHEL1 ~]# lsscsi -l
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0
  state=running queue_depth=1 scsi_level=6 type=5 device_blocked=0 timeout=30
[2:0:0:0]    disk    VBOX     HARDDISK         1.0   /dev/sda
  state=running queue_depth=32 scsi_level=6 type=0 device_blocked=0 timeout=30
[root@UARHEL1 ~]#

 

4.To know the device mapping between SG driver and Linux device.

[root@UARHEL1 ~]# lsscsi -g
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0   /dev/sg1
[2:0:0:0]    disk    VBOX     HARDDISK         1.0   /dev/sda   /dev/sg0
[root@UARHEL1 ~]#

 

To list the scsi devices with size,

[root@UARHEL1 ~]# lsscsi -s
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0        -
[2:0:0:0]    disk    VBOX     HARDDISK         1.0   /dev/sda   17.1GB
[root@UARHEL1 ~]#

 

To list the device in verbose mode which provides the device physical path ,

[root@UARHEL1 ~]# lsscsi -v
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0
  dir: /sys/bus/scsi/devices/1:0:0:0  [/sys/devices/pci0000:00/0000:00:01.1/ata2/host1/target1:0:0/1:0:0:0]
[2:0:0:0]    disk    VBOX     HARDDISK         1.0   /dev/sda
  dir: /sys/bus/scsi/devices/2:0:0:0  [/sys/devices/pci0000:00/0000:00:14.0/host2/target2:0:0/2:0:0:0]
[root@UARHEL1 ~]#

 

HELP: lsscsi

[root@UARHEL1 ~]# lsscsi -help
Usage: lsscsi   [--classic] [--device] [--generic] [--help] [--hosts]
                [--kname] [--list] [--lunhex] [--long] [--protection]
                [--scsi_id] [--size] [--sysfsroot=PATH] [--transport]
                [--verbose] [--version] [--wwn] []
  where:
    --classic|-c      alternate output similar to 'cat /proc/scsi/scsi'
    --device|-d       show device node's major + minor numbers
    --generic|-g      show scsi generic device name
    --help|-h         this usage information
    --hosts|-H        lists scsi hosts rather than scsi devices
    --kname|-k        show kernel name instead of device node name
    --list|-L         additional information output one
                      attribute=value per line
    --long|-l         additional information output
    --lunhex|-x       show LUN part of tuple as hex number in T10 format;
                      use twice to get full 16 digit hexadecimal LUN
    --protection|-p   show target and initiator protection information
    --protmode|-P     show negotiated protection information mode
    --scsi_id|-i      show udev derived /dev/disk/by-id/scsi* entry
    --size|-s         show disk size
    --sysfsroot=PATH|-y PATH    set sysfs mount point to PATH (def: /sys)
    --transport|-t    transport information for target or, if '--hosts'
                      given, for initiator
    --verbose|-v      output path names where data is found
    --version|-V      output version string and exit
    --wwn|-w          output WWN for disks (from /dev/disk/by-id/wwn*)
             filter output list (def: '*:*:*:*' (all))

List SCSI devices or hosts, optionally with additional information
[root@UARHEL1 ~]#

 

5. “sdparm” command  is another useful command to view and set the values contained in various mode pages supported by SCSI.If you get error like “sdparm command not found” ,then you are missing that utility on that server. You can install sdparm using yum command.

Packages:

 

6. Here is the list of supported page modes for scsi devices.

[root@UARHEL1 ~]# sdparm --enumerate
Mode pages:
  addp 0x0e,0x02  DT device primary port (ADC)
  adlu 0x0e,0x03  logical unit (ADC)
  adtd 0x0e,0x01  Targer device (ADC)
  adts 0x0e,0x04  Targer device serial number (ADC)
  apo  0x1a,0xf1  SAT ATA Power condition
  atag 0x0a,0x02  Application tag (SBC)
  bc   0x1c,0x01  Background control (SBC)
  ca   0x08       Caching (SBC)
  cms  0x2a       CD/DVD (MM) capabilities and mechanical status (MMC)
  co   0x0a       Control
  coe  0x0a,0x01  Control extension
  cdp  0x0a,0xf0  Control data protection (SSC)
  dac  0x0f       Data compression (SSC)
  dc   0x10       Device configuration (SSC)
  dca  0x1f       Device capabilities (SMC)
  dce  0x10,0x01  Device configuration extension (SSC)
  dr   0x02       Disconnect-reconnect (SPC + transports)
  eaa  0x1d       Element address assignment (SMC)
  edc  0x1f,0x41  Extended device capabilities (SMC)
  esm  0x14       Enclosure services management (SES)
  fo   0x03       Format (SBC)
  ie   0x1c       Informational exceptions control
  lbp  0x1c,0x02  Logical block provisioning (SBC)
  mco  0x1d       Medium configuration (SSC)
  mpa  0x11       Medium partition (SSC)
  mrw  0x03       Mount rainier reWritable (MMC)
  pat  0x0a,0xf1  SAT pATA control
  pl   0x18       Protocol specific logical unit
  po   0x1a       Power condition
  ps   0x1a,0x01  Power consumption
  poo  0x0d       Power condition - old version
  pp   0x19       Protocol specific port
  rbc  0x06       RBC device parameters (RBC)
  rd   0x04       Rigid disk (SBC)
  rw   0x01       Read write error recovery
  tgp  0x1e       Transport geometry parameters (SMC)
  tp   0x1d       Timeout and protect (MMC)
  ve   0x07       Verify error recovery (SBC)
  wp   0x05       Write parameters (MMC)
  xo   0x10       XOR control (SBC)
[root@UARHEL1 ~]#

 

7. sdparm can be used to inquiry about specific scsi devices to know the supported VPD pages.

[root@UARHEL1 ~]# sdparm --inquiry /dev/sda
    /dev/sda: VBOX      HARDDISK          1.0
Device identification VPD page:
VPD page error: short designator around offset -1
VPD page error: short designator around offset -1
VPD page error: short designator around offset -1
[root@UARHEL1 ~]#

Since I am demonstrating using virtual box Linux instance, you can’t see the page modes for the specific devices.

HELP: sdparm

[root@UARHEL1 ~]# sdparm -help
Usage: sdparm [--all] [--clear=STR] [--command=CMD] [--dbd] [--defaults]
              [--dummy] [--flexible] [--get=STR] [--help] [--hex] [--inquiry]
              [--long] [--num-desc] [--page=PG[,SPG]] [--quiet] [--readonly]
              [--save] [--set=STR] [--six] [--transport=TN] [--vendor=VN]
              [--verbose] [--version] DEVICE [DEVICE...]

       sdparm --enumerate [--all] [--inquiry] [--long] [--page=PG[,SPG]]
              [--transport=TN] [--vendor=VN]
  where:
    --all | -a            list all known fields for given device
    --clear=STR | -c STR    clear (zero) field value(s)
    --command=CMD | -C CMD    perform CMD (e.g. 'eject')
    --dbd | -B            set DBD bit in mode sense cdb
    --defaults | -D       set a mode page to its default values
    --dummy | -d          don't write back modified mode page
    --enumerate | -e      list known pages and fields (ignore device)
    --flexible | -f       compensate for common errors, relax some checks
    --get=STR | -g STR    get (fetch) field value(s)
    --help | -h           print out usage message
    --hex | -H            output in hex rather than name/value pairs
    --inquiry | -i        output INQUIRY VPD page(s) (def: mode page(s))
                          use --page=PG for VPD number (-1 for std inq)
    --long | -l           add description to field output
    --num-desc | -n       report number of mode page descriptors
    --page=PG[,SPG] | -p PG[,SPG]    page (and optionally subpage) number
                          [or abbrev] to output, change or enumerate
    --quiet | -q          suppress device vendor/product/revision string line
    --readonly | -r       force read-only open of DEVICE (def: depends
                          on operation). Mainly for ATA disks
    --save | -S           place mode changes in saved page as well
    --set=STR | -s STR    set field value(s)
    --six | -6            use 6 byte SCSI mode cdbs (def: 10 byte)
    --transport=TN | -t TN    transport protocol number [or abbrev]
    --vendor=VN | -M VN    vendor (manufacturer) number [or abbrev]
    --verbose | -v        increase verbosity
    --version | -V        print version string and exit

View or change SCSI mode page fields (e.g. of a disk or CD/DVD drive).
STR can be [=val] or ::[=val].
[root@UARHEL1 ~]#

 

8. Install sg3 utilities which provides command called sg_map.

[root@UARHEL1 ~]# sg_map -i -x
/dev/sg0  2 0 0 0  0  /dev/sda  VBOX      HARDDISK          1.0
/dev/sg1  1 0 0 0  5  /dev/sr0  VBOX      CD-ROM            1.0
[root@UARHEL1 ~]#

Packge name

 

Help:  sg_map

[root@UARHEL1 ~]# sg_map --help
Unknown switch: --help
Usage: sg_map [-a] [-h] [-i] [-n] [-sd] [-scd or -sr] [-st] [-V] [-x]
  where:
    -a      do alphabetic scan (ie sga, sgb, sgc)
    -h or -?    show this usage message then exit
    -i      also show device INQUIRY strings
    -n      do numeric scan (i.e. sg0, sg1, sg2) (default)
    -sd     show mapping to disks
    -scd    show mapping to cdroms (look for /dev/scd
    -sr     show mapping to cdroms (look for /dev/sr
    -st     show mapping to tapes (st and osst devices)
    -V      print version string then exit
    -x      also show bus,chan,id,lun and type

If no '-s*' arguments given then show all mappings. This utility
is DEPRECATED, do not use in Linux 2.6 series or later.
[root@UARHEL1 ~]#

In upcoming articles ,we will see more about other hardware management on Linux operating system. Hope this article is informative to you. Share it ! Comment it !! Be sociable !!!

Exit mobile version