SG_LUNS(8) | SG3_UTILS | SG_LUNS(8) |
sg_luns - send SCSI REPORT LUNS command or decode given LUN
sg_luns [--decode] [--help] [--hex] [--linux] [--lu_cong] [--maxlen=LEN] [--quiet] [--raw] [--readonly] [--select=SR] [--verbose] [--version] DEVICE
sg_luns --test=ALUN [--decode] [--hex] [--lu_cong] [--verbose]
In the first form shown in the SYNOPSIS this utility sends the SCSI REPORT LUNS command to the DEVICE and outputs the response. The response should be a list of LUNs ("a LUN inventory") for the I_T nexus associated with the DEVICE. Roughly speaking that is all LUNs that share the target device that the REPORT LUNS command is sent through. This command is defined in the SPC-3 and SPC-4 SCSI standards and its support is mandatory. The most recent draft if SPC-6 revision 1.
When the --test=ALUN option is given (the second form in the SYNOPSIS), then the ALUN value is decoded as outlined in various SCSI Architecture Model (SAM) standards and recent drafts (e.g. SAM-6 revision 2, section 4.7) .
Where required below the first form shown in the SYNOPSIS is called "device mode" and the second form is called "test mode".
Arguments to long options are mandatory for short options as well.
For SR values 0x10 and 0x11, the DEVICE must be either LUN 0 or the REPORT LUNS well known logical unit. Values between 0xf8 and 0xff (inclusive) are vendor specific, other values are reserved. This utility will accept any value between 0 and 255 (0xff) for SR .
The SCSI REPORT LUNS command is important for Logical Unit (LU) discovery. After a target device is discovered (usually via some transport specific mechanism) and after sending an INQUIRY command (to determine the LU_CONG setting), a REPORT LUNS command should either be sent to LUN 0 (which is Peripheral device addressing method with bus_id=0 and target/lun=0) or to the REPORT LUNS well known LUN (i.e. 0xc101000000000000). SAM-5 requires that one of these responds with an inventory of LUNS that are contained in this target device.
In test mode, if the --hex option is given once then in the decoded output, some of the component fields are printed in hex with leading zeros. The leading zeros are to indicate the size of the component field. For example: in the Peripheral device addressing method (16 bits overall), the bus ID is 6 bits wide and the target/LUN field is 8 bits wide; so both are shown with two hex digits (e.g. bus_id=0x02, target=0x3a).
Typically by the time user space programs get to run, SCSI LUs have been discovered. In Linux the lsscsi utility lists the LUs that are currently present. The LUN of a device (LU) is the fourth element in the tuple at the beginning of each line. Below we see a target (or "I_T Nexus": "6:0:0") has two LUNS: 1 and 49409. If 49409 is converted into T10 LUN format it is 0xc101000000000000 which is the REPORT LUNS well known LUN.
# lsscsi -g
[6:0:0:1] disk Linux scsi_debug 0004 /dev/sdb /dev/sg1
[6:0:0:2] disk Linux scsi_debug 0004 /dev/sdc /dev/sg2
[6:0:0:49409]wlun Linux scsi_debug 0004 - /dev/sg3
We could send a REPORT LUNS command (with SR 0x0, 0x1 or 0x2) to any of those file device nodes and get the same result. Below we use /dev/sg1 :
# sg_luns /dev/sg1
Lun list length = 16 which imples 2 lun entry
Report luns [select_report=0x0]:
0001000000000000
0002000000000000
That is a bit noisy so cut down the clutter with --quiet:
# sg_luns -q /dev/sg1
0001000000000000
0002000000000000
Now decode that LUN into its component parts:
# sg_luns -d -q /dev/sg1
0001000000000000
Peripheral device addressing: lun=1
0002000000000000
Peripheral device addressing: lun=2
Now use --select=1 to find out if there are any well known LUNs:
# sg_luns -q -s 1 /dev/sg1
c101000000000000
So how many LUNs do we have all together (associated with the current I_T Nexus):
# sg_luns -q -s 2 /dev/sg1
0001000000000000
0002000000000000
c101000000000000
# sg_luns -q -s 2 -d /dev/sg1
0001000000000000
Peripheral device addressing: lun=1
0002000000000000
Peripheral device addressing: lun=1
c101000000000000
REPORT LUNS well known logical unit
The following example uses the --linux option and is not available in other operating systems. The extra number in square brackets is the Linux version of T10 LUN shown at the start of the line.
# sg_luns -q -s 2 -l /dev/sg1
0001000000000000 [1]
0002000000000000 [2]
c101000000000000 [49409]
Now we use the --test= option to decode LUNS input on the command line (rather than send a REPORT LUNS command and act on the response):
# sg_luns --test=0002000000000000
Decoded LUN:
Peripheral device addressing: lun=2
# sg_luns --test="c1 01"
Decoded LUN:
REPORT LUNS well known logical unit
# sg_luns -t 0x023a004b -H
Decoded LUN:
Peripheral device addressing: bus_id=0x02, target=0x3a
>>Second level addressing:
Peripheral device addressing: lun=0x4b
The next example is Linux specific as we try to find out what the Linux LUN 49409 translates to in the T10 world:
# sg_luns --test=L49409
64 bit LUN in T10 preferred (hex) format: c1 01 00 00 00 00 00 00
Decoded LUN:
REPORT LUNS well known logical unit
And the mapping between T10 and Linux LUN representations can be done the other way:
# sg_luns -t c101L
Linux 'word flipped' integer LUN representation: 49409
Decoded LUN:
REPORT LUNS well known logical unit
The exit status of sg_luns is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
Written by Douglas Gilbert.
Report bugs to <dgilbert at interlog dot com>.
Copyright © 2004-2020 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
January 2020 | sg3_utils-1.45 |