sg_rep_pip sends the SCSI REPORT PROVISIONING INITIALIZATION PATTERN command to a device and captures the response in a format you can actually use. It is a diagnostic read on a device that supports the command: it does not create a provisioning pattern or initialise storage. Allow about fifteen minutes, plus whatever time it takes to identify the correct SCSI generic device.
You need the sg3-utils package and access to the target device. Nothing here writes to the device.
Start with read-only inspection of the local installation. The examples here use sg3-utils package version 1.46-3ubuntu4 and sg_rep_pip version 1.01 20200605:
$ command -v sg_rep_pip
/usr/bin/sg_rep_pip
$ dpkg-query -W -f='${Package} ${Version}\n' sg3-utils
sg3-utils 1.46-3ubuntu4
$ sg_rep_pip --version
version: 1.01 20200605
Read the command's usage before you choose an option:
$ sg_rep_pip --help
Usage: sg_rep_pip [--help] [--hex] [--maxlen=LEN] [--raw] [--readonly]
[--verbose] [--version] DEVICE
The device argument is mandatory. A SCSI generic path such as /dev/sg3 is only an example here. Do not substitute a path from another host without checking what it actually represents on this one.
Use whatever device inventory tools already live on your system to map the physical target to its SCSI generic node. For example, inspect the available generic devices and their links:
$ ls -l /dev/sg* 2>/dev/null
$ lsscsi -g
lsscsi is a separate utility and may not be installed. What you need out of this is an exact path tied to the disk, enclosure or tape device you intend to query. If several paths exist, stop and resolve the mapping before running a pass-through command.
Checkpoint: Confirm that the chosen node exists and is a character device:
$ test -c /dev/sg3 && echo 'character device: /dev/sg3'
character device: /dev/sg3
Safety warning: The command opens the device read-write by default, even though this particular request is a report. Use --readonly unless you have a specific reason to allow a read-write open. This option changes how the device file is opened; it does not make an unsupported device implement the SCSI command.
$ sg_rep_pip --readonly --maxlen=8192 /dev/sg3
00000000 00 00 00 00 00 00 00 00 ........
The response bytes are device-specific, so the line above shows only the shape of addressed hexadecimal output, not a value you should expect from every drive. By default, the installed command prints the response in ASCII hexadecimal. Check success immediately:
$ printf 'exit status: %s\n' "$?"
exit status: 0
Keep that status check right next to the command. A later printf, pager or filter will happily overwrite the status you meant to inspect.
--maxlen=LEN places a maximum response length, in bytes, in the SCSI command's allocation-length field. Zero means the program picks its own default, and the documented maximum is 1048576. For a script, or an investigation where buffer size matters, give it an explicit non-zero value:
$ sg_rep_pip --readonly --maxlen=512 /dev/sg3
$ printf 'exit status: %s\n' "$?"
exit status: 0
There is a version-specific trap on this installation. The local sg_rep_pip(8) page says an omitted or zero length uses 8192 bytes, while the installed program's own --help text says its default is 512 bytes. Do not rely on the implicit default when the allocation length affects your test: pass the value you want and record it with the command.
A value above the limit is rejected before the device is even queried:
$ sg_rep_pip --maxlen=1048577 /dev/null
argument to '--maxlen' should be 1048576 or less
The default behaves like one --hex option: hexadecimal bytes with an address at the start of each line. Use --hex --hex when another tool needs hexadecimal without those leading addresses:
$ sg_rep_pip --readonly --hex --hex --maxlen=512 /dev/sg3
Use --raw when the next program in your pipeline expects the response as binary on standard output. Redirect it to a deliberately named file; never send binary data to a terminal:
$ sg_rep_pip --readonly --raw --maxlen=512 /dev/sg3 > report-pip.bin
$ test -s report-pip.bin && echo 'response file is non-empty'
response file is non-empty
The output file is local state. If you need to repeat the query, choose a new name, or remove the old file only after checking it. The command offers no undo for a saved capture, and deleting a useful one is irreversible.
Permission errors usually mean your account cannot open the device or issue the required ioctl. Inspect the node and your groups first:
$ ls -l /dev/sg3
$ id
$ sg_rep_pip --readonly --maxlen=512 /dev/sg3
$ printf 'exit status: %s\n' "$?"
Use elevated privileges only if your system's device policy requires them, and keep the target explicit:
$ sudo sg_rep_pip --readonly --maxlen=512 /dev/sg3
Do not jump straight to sudo for an unverified path. A wrong SCSI generic node can address a completely different device, and this program is a pass-through utility rather than a harmless file reader.
For a safe parser and error-path check, /dev/null is not a SCSI device. On this machine it produces an inappropriate-ioctl error and a non-zero status, which is the confirmation you want: a failed command must never be treated as a valid empty response:
$ sg_rep_pip --readonly /dev/null
Report provisioning initialization pattern: pass-through os error: Inappropriate ioctl for device
Report provisioning initialization pattern command: Inappropriate ioctl for device
sg_rep_pip failed: Inappropriate ioctl for device
$ printf 'exit status: %s\n' "$?"
exit status: 75
Other non-zero statuses can reflect device, transport or operating-system errors. Preserve the diagnostic text and investigate the device mapping, permissions, transport and device support before retrying. Turning up --verbose adds diagnostic detail; it does not repair a missing SCSI capability.
--readonly and an explicit --maxlen.