# SG_INQ(8) - man - phpMan

[SG_INQ(8)](https://www.chedong.com/phpMan.php/man/SGINQ/8/markdown)                                     SG3_UTILS                                    [SG_INQ(8)](https://www.chedong.com/phpMan.php/man/SGINQ/8/markdown)



## NAME
       sg_inq - issue SCSI INQUIRY command and/or decode its response

## SYNOPSIS
       **sg**___**inq**  [_--ata_]  [_--block=0|1_]  [_--cmddt_]  [_--descriptors_]  [_--export_] [_--extended_] [_--force_]
       [_--help_]  [_--hex_]  [_--id_]  [_--inhex=FN_]   [_--len=LEN_]    [_--long_]   [_--maxlen=LEN_]   [_--only_]
       [_--page=PG_] [_--raw_] [_--vendor_] [_--verbose_] [_--version_] [_--vpd_] _DEVICE_

       **sg**___**inq**  [_-36_]  [_-a_]  [_-A_]  [_-b_]  [_--B=0|1_]  [_-c_]  [_-cl_] [_-d_] [_-e_] [_-f_] [_-h_] [_-H_] [_-i_] [_-I=FN_]
       [_-l=LEN_] [_-L_] [_-m_] [_-M_] [_-o_] [_-p=VPD_PG_] [_-P_] [_-r_] [_-s_] [_-u_] [_-v_] [_-V_] [_-x_] [_-36_] [_-?_] _DEVICE_

## DESCRIPTION
       This utility, when _DEVICE_ is given, sends a SCSI INQUIRY command to it then outputs  the  re‐
       sponse. All SCSI devices are meant to respond to a "standard" INQUIRY command with at least a
       36 byte response (in SCSI 2 and higher). An INQUIRY is termed as  "standard"  when  both  the
       EVPD and CmdDt (now obsolete) bits are clear.

       Alternatively  the  _--inhex=FN_  option  can be given. In this case _FN_ is assumed to be a file
       name ('-' for stdin) containing ASCII hexadecimal representing an INQUIRY response.

       This utility supports two command line syntaxes. The preferred one is shown first in the syn‐
       opsis and is described in the main OPTIONS section. A later section titled OLDER COMMAND LINE
       OPTIONS describes the second group of options.

       An important "non-standard" INQUIRY page is the  Device  Identification  Vital  Product  Data
       (VPD)  page  [0x83]. Since SPC-3, support for this page is mandatory. The _--id_ option decodes
       this page. New VPD page information is no longer being added to this utility. To get informa‐
       tion on new VPD pages see the [sg_vpd(8)](https://www.chedong.com/phpMan.php/man/sgvpd/8/markdown) or [sdparm(8)](https://www.chedong.com/phpMan.php/man/sdparm/8/markdown) utilities.

       In  Linux,  if  the _DEVICE_ exists and the SCSI INQUIRY fails (e.g. because the SG_IO ioctl is
       not supported) then an ATA IDENTIFY (PACKET) DEVICE is tried.  If  it  succeeds  then  device
       identification  strings are output. The _--raw_ and _--hex_ options can be used to manipulate the
       output.  If the _--ata_ option is given then the SCSI INQUIRY is not performed and  the  _DEVICE_
       is assumed to be ATA (or ATAPI). For more information see the ATA DEVICES section below.

       In  some  operating systems a NVMe device (e.g. SSD) may be given as the _DEVICE_. For more in‐
       formation see the NVME DEVICES section below.

       The reference document used for interpreting an INQUIRY is T10/BSR  INCITS  502  Revision  19
       which  is draft SPC-5 revision 19, 14 February 2018). It can be found at <http://www.t10.org> .
       Obsolete and reserved items in the standard INQUIRY response output are displayed  in  square
       brackets.

## OPTIONS
       Arguments  to long options are mandatory for short options as well.  The options are arranged
       in alphabetical order based on the long option name.

### -a --ata
              Assume given _DEVICE_ is an ATA or ATAPI device which can receive ATA commands from  the
              host  operating  system. Skip the SCSI INQUIRY command and use either the ATA IDENTIFY
              DEVICE command (for non-packet devices) or the ATA IDENTIFY PACKET DEVICE command.  To
              show  the  response in hex, add a '--verbose' option. This option is only available in
              Linux.

### -B --block
              this option controls how the file handle to the _DEVICE_ is opened. If this argument  is
              0  then  the  open is non-blocking. If the argument is 1 then the open is blocking. In
              Unix a non-blocking open is indicated by a O_NONBLOCK flag while a  blocking  open  is
              indicated by the absence of that flag. The default value depends on the operating sys‐
              tem and the type of _DEVICE_ node. For Linux pass-throughs (i.e. the sg and bsg drivers)
              the default is 0.

### -c --cmddt
              set  the  Command Support Data (CmdDt) bit (defaults to [clear(0)](https://www.chedong.com/phpMan.php/man/clear/0/markdown)). Used in conjunction
              with the _--page=PG_ option where _PG_ specifies the SCSI command opcode  to  query.  When
              used  twice  (e.g. '-cc') this utility forms a list by looping over all 256 opcodes (0
              to 255 inclusive) only outputting a line for commands that are found. The CmdDt bit is
              now  obsolete;  it  has been replaced by the REPORT SUPPORTED OPERATION CODES command,
              see the [sg_opcodes(8)](https://www.chedong.com/phpMan.php/man/sgopcodes/8/markdown) utility.

### -d --descriptors
              decodes and prints the version descriptors found in a standard INQUIRY response. There
              are  up  to 8 of them. Version descriptors indicate which versions of standards and/or
              drafts the _DEVICE_ complies with. The normal components of a standard INQUIRY are  out‐
              put  (typically  from  the first 36 bytes of the response) followed by the version de‐
              scriptors if any.

### -e

### -f --force
              As a sanity check, the normal action when fetching VPD pages other than page 0x0  (the
              "Supported  VPD pages" VPD page), is to first fetch page 0x0 and only if the requested
              page is one of the supported pages, to go ahead and fetch the requested page.
              When this option is given, skip checking of VPD page  0x0  before  accessing  the  re‐
              quested  VPD  page.  The prior check of VPD page 0x0 is known to crash certain USB de‐
              vices, so use with care.

### -u --export
              prints out information obtained from the device. The output can be modified by select‐
              ing a VPD page with _PG_ (from _--page=PG_). If the device identification VPD page 0x83 is
              given it prints out information in the  form:  "SCSI_IDENT_<assoc>_<type>=<ident>"  to
              stdout.  If  the device serial number VPD page 0x80 is given it prints out information
              in the form: "SCSI_SERIAL=<ident>". Other VPD pages are not supported. If no VPD  page
              is   given   it   prints   out   information   in  the  form:  "SCSI_VENDOR=<vendor>",
              "SCSI_MODEL=<model>", and "SCSI_REVISION=<rev>", taken from the standard inquiry. This
              may be useful for tools like [udev(7)](https://www.chedong.com/phpMan.php/man/udev/7/markdown) in Linux.

### -E -x --extended
              prints the extended INQUIRY VPD page [0x86].

### -h --help
              print out the usage message then exit. When used twice, after the usage message, there
              is a list of available abbreviations than can be given to the _--page=PG_ option.

### -H --hex
              rather than decode a standard INQUIRY response, a VPD page or  command  support  data;
              print out the response in hex and send the output to stdout.  Error messages and warn‐
              ings are typically output to stderr. When used twice with the ATA Information VPD page
              [0x89] decodes the start of the response then outputs the ATA IDENTIFY (PACKET) DEVICE
              response in hexadecimal bytes (not 16 bit words). When used three times with  the  ATA
              Information VPD page [0x89] or the _--ata_ option, this utility outputs the ATA IDENTIFY
              (PACKET) DEVICE response in hexadecimal words suitable for input to 'hdparm --Istdin'.
              See note below.
              To  generate output suitable for placing in a file that can be used by a later invoca‐
              tion with the _--inhex=FN_ option, use the '-HHHH' option  (e.g.  'sg_inq  -p  di  -HHHH
              /dev/sg3 > dev_id.hex').

### -i --id
              prints the device identification VPD page [0x83].

### -I --inhex
              _FN_  is  expected to be a file name (or '-' for stdin) which contains ASCII hexadecimal
              or binary representing an INQUIRY (including VPD page)  response.  This  utility  will
              then  decode  that  response. It is preferable to also supply the _--page=PG_ option, if
              not this utility will attempt to guess which VPD page (or standard INQUIRY)  that  the
              response  is associated with. The hexadecimal should be arranged as 1 or 2 digits rep‐
              resenting a byte each of which is whitespace or comma separated. Anything from and in‐
              cluding a hash mark to the end of a line is ignored. If the _--raw_ option is also given
              then _FN_ is treated as binary.

### -l --len
              the number _LEN_ is the "allocation length" field in the INQUIRY cdb.  This is the (max‐
              imum)  length  of  the  response returned by the device. The default value of _LEN_ is 0
              which is interpreted as: first request is for 36 bytes and if  necessary  execute  an‐
              other  INQUIRY  if  the  "additional length" field in the response indicates that more
              than 36 bytes is available.
              If _LEN_ is greater than 0 then only one INQUIRY command is performed.  This means  that
              the Serial Number (obtained from the Serial Number VPD pgae (0x80)) is not fetched and
              therefore not printed.  See the NOTES section below about "36 byte INQUIRYs".

### -L --long
              this option causes more information to be decoded from the Identify command sent to  a
              NVMe _DEVICE_.

### -m --maxlen
              this  option  has the same action as the _--len=LEN_ option above. It has been added for
              compatibility with the sg_vpd, sg_modes and sg_logs utilities.

### -O --old
              Switch to older style options. Please use as first option on the command line.

### -o --only
              Do not attempt to additionally retrieve the serial number VPD page (0x80)  to  enhance
              the  output of a standard INQUIRY. So with this option given and no others, this util‐
              ity will send a standard INQUIRY SCSI command and decode its response. No  other  SCSI
              commands  will  be sent to the _DEVICE_.  Without this option an additional SCSI command
              is sent: a (non-standard) SCSI INQUIRY to fetch the Serial Number  VPD  page.  However
              the  Serial  Number VPD page is not mandatory (while the Device Identification page is
              mandatory but a billion USB keys ignore that) and may cause nuisance error reports.
              For NVMe devices only the Identify controller is performed, even  if  the  _DEVICE_  in‐
              cludes   a  namespace  identifier.  For  example  in  FreeBSD  given  a  _DEVICE_  named
              /dev/nvme0ns1 then an Identify controller is sent to /dev/nvme0 and nothing is sent to
              its "ns1" (first namespace).

### -p --page
              the _PG_ argument can be either a number of an abbreviation for a VPD page. To enumerate
              the available abbreviations for VPD pages  use  '-hh'  or  a  bad  abbreviation  (e.g,
              '--page=xxx').  When  the  _--cmddt_ option is given (once) then _PG_ is interpreted as an
              opcode number (so VPD page abbreviations make little sense).
              If _PG_ is a negative number, then a standard INQUIRY is performed. This can be used  to
              override some guessing logic associated with the _--inhex=FN_ option.
              If  _PG_ is not found in the 'Supported VPD pages' VPD page (0x0) then EDOM is returned.
              To bypass this check use the _--force_ option.

### -r --raw
              in the absence of _--inhex=FN_ then the output response is in binary.  The output should
              be  piped to a file or another utility when this option is used. The binary is sent to
              stdout, and errors are sent to stderr.
              If used with _--inhex=FN_ then the contents of _FN_ is treated as binary.

### -s --vendor
              output a standard INQUIRY response's vendor specific fields from offset 36  to  55  in
              ASCII.  When used twice (i.e. '-ss') also output the vendor specific field from offset
              96 in ASCII. This is only done if the data passes some simple sanity checks.

### -v --verbose
              increase level of verbosity. Can be used multiple times.

### -V --version
              print out version string then exit.

### -e --vpd
              set the Enable Vital Product Data (EVPD) bit (defaults to [clear(0)](https://www.chedong.com/phpMan.php/man/clear/0/markdown)). Used in  conjunc‐
              tion with the _--page=PG_ option where _PG_ specifies the VPD page number to query. If the
              _--page=PG_ is not given then _PG_ defaults to zero which is the "Supported VPD pages" VPD
              page. A more up to date decoding of VPD pages can be found in the [sg_vpd(8)](https://www.chedong.com/phpMan.php/man/sgvpd/8/markdown) utility.

## NOTES
       Some  devices  with  weak SCSI command set implementations lock up when they receive commands
       they don't understand (and some lock up if they receive response lengths that they don't  ex‐
       pect). Such devices need to be treated carefully, use the '--len=36' option. Without this op‐
       tion this utility will issue an initial standard INQUIRY  requesting  36  bytes  of  response
       data.  If  the device indicates it could have supplied more data then a second INQUIRY is is‐
       sued to fetch the longer response. That second command may lock up faulty devices.

       ATA or ATAPI devices that use a SCSI to ATA Translation layer (see SAT  at  www.t10.org)  may
       support the SCSI ATA INFORMATION VPD page. This returns the IDENTIFY (PACKET) DEVICE response
       amongst other things.  The ATA Information VPD page can be fetched with '--page=ai'.

       In the INQUIRY standard response there is a 'MultiP' flag which is set when the device has  2
       or  more  ports.  Some vendors use the preceding vendor specific ('VS') bit to indicate which
       port is being accessed by the INQUIRY command (0 -> relative port 1 (port "a"), 1 -> relative
       port 2 (port "b")). When the 'MultiP' flag is set, the preceding vendor specific bit is shown
       in parentheses. SPC-3 compliant devices should use the device identification VPD page  (0x83)
       to  show  which  port is being used for access and the SCSI ports VPD page (0x88) to show all
       available ports on the device.

       In the 2.4 series of Linux kernels the _DEVICE_ must be a SCSI generic (sg) device. In the  2.6
       series  and later block devices (e.g.  disks and ATAPI DVDs) can also be specified. For exam‐
       ple "sg_inq /dev/sda" will work in the 2.6 series kernels. From lk 2.6.6  other  SCSI  "char"
       device names may be used as well (e.g. "/dev/st0m").

       The  number  of  bytes output by _--hex_ and _--raw_ is 36 bytes or the number given to _--len=LEN_
       (or _--maxlen=LEN_). That number is reduced if the "resid" returned by the HBA  indicates  less
       bytes were sent back from _DEVICE_.

       The _DEVICE_ is opened with a read-only flag (e.g. in Unix with the O_RDONLY flag).

## ATA DEVICES
       There  are two major types of ATA devices: non-packet devices (e.g. ATA disks) and packet de‐
       vices (ATAPI). The majority of ATAPI devices are CD/DVD/BD drives in which the  ATAPI  trans‐
       port  carries  the MMC set (i.e.  a SCSI command set). Further, both types of ATA devices can
       be connected to a host computer via a "SCSI" (or some other) transport. When an ATA  disk  is
       controlled  via  a  SCSI  (or  non-ATA) transport then two approaches are commonly used: tun‐
       nelling (e.g. STP in Serial Attached SCSI (SAS)) or by emulating a SCSI device (e.g.  with  a
       SCSI  to ATA translation layer, see SAT at www.t10.org ). Even when the physical transport to
       the host computer is ATA (especially in the case of SATA) the operating system may choose  to
       put a SAT layer in the driver "stack" (e.g. libata in Linux).

       The main identifying command for any SCSI device is an INQUIRY. The corresponding command for
       an ATA non-packet device is IDENTIFY DEVICE while for an ATA packet  device  it  is  IDENTIFY
       PACKET DEVICE.

       When  this  utility  is  invoked  for  an  ATAPI  device (e.g. a CD/DVD/BD drive with "sg_inq
       /dev/hdc") then a SCSI INQUIRY is sent to the device and if it responds then the response  to
       decoded and output and this utility exits. To see the response for an ATA IDENTIFY PACKET DE‐
       VICE command add the _--ata_ option (e.g. "sg_inq --ata /dev/hdc).

       This utility doesn't decode the response to an ATA IDENTIFY (PACKET) DEVICE  command,  hdparm
       does  a good job at that. The '-HHH' option has been added for use with either the '--ata' or
       '--page=ai' option to produce a format acceptable to "hdparm --Istdin".  An example:  'sg_inq
       --ata -HHH /dev/hdc | hdparm --Istdin'. See hdparm.

## NVME DEVICES
       Currently  these  device  are typically SSDs (Solid State Disks) directly connected to a PCIe
       connector or via a specialized connector such as a M2 connector. Linux and FreeBSD treat NVMe
       storage  devices as separate from SCSI storage with device names like /dev/nvme0n1 (in Linux)
       and /dev/nvme0ns1 (in FreeBSD). The NVM Express group has a  document  titled  "NVM  Express:
       SCSI  Translation  Reference"  which defines a partial "SCSI to NVMe Translation Layer" often
       known by its acronym: SNTL.

       On operating systems where it is supported by this package, this  utility  will  detect  NVMe
       storage devices directly connected and send an Identify controller NVMe Admin command and de‐
       code its response. A NVMe controller is architecturally similar to a SCSI target  device.  If
       the  NVMe  _DEVICE_ indicates a namespace then an Identify namespace NVMe Admin command is sent
       to that namespace and its response is decoded. Namespaces are numbered sequentially  starting
       from  1.  Namespaces  are similar to SCSI Logical Units and their identifiers (nsid_s) can be
       thought of as SCSI LUNs. In the Linux and FreeBSD example device names above the "n1" and the
       "ns1"  parts  indicate  nsid  1  . If no namespace is given in the _DEVICE_ then all namespaces
       found in the controller are sent Identify namespace commands and the responses are decoded.

       To get more details in the response use the _--long_ option. To only get the controller's Iden‐
       tify decoded use the _--only_ option.

       It  is  possible that even though the _DEVICE_ presents as a NVMe device, it has a SNTL and ac‐
       cepts SCSI commands. In this case to send a SCSI INQUIRY command (and fetch  its  VPD  pages)
       use 'sg_vpd -p sinq <dev>' (or to get VPD pages: 'sg_vpd -p <vpd_page> <dev>').

## EXIT STATUS
       The  exit  status  of  sg_inq  is 0 when it is successful. Otherwise see the [sg3_utils(8)](https://www.chedong.com/phpMan.php/man/sg3utils/8/markdown) man
       page.

## OLDER COMMAND LINE OPTIONS
       The options in this section were the only ones available prior to sg3_utils  version  1.23  .
       Since then this utility defaults to the newer command line options which can be overridden by
       using _--old_ (or _-O_) as the first option. See the ENVIRONMENT VARIABLES  section  for  another
       way to force the use of these older command line options.

### -36
              indicates in its response it can supply more data, a second (longer)  INQUIRY  is  not
              performed.  This  is a paranoid setting.  Equivalent to '--len=36' in the OPTIONS sec‐
              tion.

### -a
              section. This page is defined in SAT (see at www.t10.org).

### -A
              section.

### -b
              section. This page is defined in SBC-2 (see www.t10.org) and later.

### -B

### -c
              with the _-p=VPD_PG_ option to specify the SCSI command opcode to query.  Equivalent  to
              _--cmddt_ in the OPTIONS section.

### -cl
              looping through all 256 opcodes. This option uses the CmdDt bit which is now obsolete.
              See  the  [sg_opcodes(8)](https://www.chedong.com/phpMan.php/man/sgopcodes/8/markdown)  utility.  Equivalent to '--cmddt --cmddt' in the OPTIONS sec‐
              tion.

### -d
              (e.g.  '-i'  or '-p=80'), then this utility attempts to decode the indicated VPD page.
              Otherwise the version descriptors (if any) are listed following a standard INQUIRY re‐
              sponse.  In  the version descriptors sense, equivalent to _--descriptors_ in the OPTIONS
              section.

### -e
              conjunction  with  the _-p=VPD_PG_ option to specify the VPD page to fetch. If _-p=VPD_PG_
              is not given then VPD page 0 (list supported VPD pages) is assumed.

### -f

### -h
              in the OPTIONS section.

### -H

### -i
              section. This page is made up of several "designation descriptors".  If  _-h_  is  given
              then  each descriptor header is decoded and the identifier itself is output in hex. To
              see the whole VPD 0x83 page response in hex use '-p=83 -h'.

### -I

### -l

### -L

### -m
              in the OPTIONS section.

### -M
              TIONS section.

### -N --new
              Switch to the newer style options.

### -o

### -p
              used in conjunction with the _-e_ or _-c_ option. If neither given then the _-e_ option  as‐
              sumed.  When the _-e_ option is also given (or assumed) then the argument to this option
              is the VPD page number.  The argument is interpreted as hexadecimal and is expected to
              be  in  the range 0 to ff inclusive. Only VPD page 0 is decoded and it lists supported
              VPD pages and their names (if known). To decode the  mandatory  device  identification
              page  (0x83) use the _-i_ option. A now obsolete usage is when the _-c_ option is given in
              which case the argument to this option is assumed to be a command opcode  number.  Re‐
              cent  SCSI  draft standards have moved this facility to a separate command (see sg_op‐
              [codes(8)](https://www.chedong.com/phpMan.php/man/codes/8/markdown)). Defaults to 0 so if _-e_ is given without this option then VPD page 0 is out‐
              put.

### -P
              '--page=upr' in the OPTIONS section.

### -r
              Can be used twice (i.e. '-rr' (and '-HHH' has same effect)) and if used with the _-A_ or
              _-a_ option yields output with the same format as "cat /proc/ide/hd<x>/identify" so that
              it can then be piped to "hdparm --Istdin".

### -s
              tion.

### -u

### -v

### -V

### -x
              OPTIONS section.

       **-?**     output usage message and exit. Ignore all other parameters.

## EXAMPLES
       The  examples  in  this  page use Linux device names. For suitable device names in other sup‐
       ported Operating Systems see the [sg3_utils(8)](https://www.chedong.com/phpMan.php/man/sg3utils/8/markdown) man page.

       To view the standard inquiry response use without options:

          sg_inq /dev/sda

       Some SCSI devices include version descriptors  indicating  the  various  SCSI  standards  and
       drafts they support. They can be viewed with:

          sg_inq -d /dev/sda

       Modern  SCSI  devices include Vital Product Data (VPD)pages which can be viewed with the SCSI
       INQUIRY command. To list the supported VPD pages (but not their contents) try:

          sg_inq -e /dev/sda

       Some VPD pages can be read with the sg_inq utility but a newer utility called sg_vpd special‐
       izes  in  showing their contents. The sdparm utility can also be used to show the contents of
       VPD pages.

       Further  examples  of  sg_inq  together  with  some  typical   output   can   be   found   on
       <http://sg.danny.cz/sg/sg3_utils.html> web page.

## ENVIRONMENT VARIABLES
       Since  sg3_utils  version 1.23 the environment variable SG3_UTILS_OLD_OPTS can be given. When
       it is present this utility will expect the older command line options.  So  the  presence  of
       this  environment variable is equivalent to using _--old_ (or _-O_) as the first command line op‐
       tion.

## AUTHOR
       Written by Douglas Gilbert

## REPORTING BUGS
       Report bugs to <dgilbert at interlog dot com>.

## COPYRIGHT
       Copyright © 2001-2021 Douglas Gilbert
       This software is distributed under the GPL version 2. There is NO warranty; not even for MER‐
       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

## SEE ALSO
       **sg**___**[opcodes(8)](https://www.chedong.com/phpMan.php/man/opcodes/8/markdown),** **sg**___**[vpd(8)](https://www.chedong.com/phpMan.php/man/vpd/8/markdown),** **sg**___**[logs(8)](https://www.chedong.com/phpMan.php/man/logs/8/markdown),** **sg**___**[modes(8)](https://www.chedong.com/phpMan.php/man/modes/8/markdown),** [**sdparm(8)](https://www.chedong.com/phpMan.php/man/sdparm/8/markdown),** [**hdparm(8)](https://www.chedong.com/phpMan.php/man/hdparm/8/markdown),** **sgdiag(scsirastools)**



sg3_utils-1.46                               March 2021                                    [SG_INQ(8)](https://www.chedong.com/phpMan.php/man/SGINQ/8/markdown)
