SG_SCAN(8)
β¨ SG_SCAN(8) β¨
Manual name: sg_scan, part of the SG3_UTILS crew π§
π NAME
sg_scan β scans sg devices (or SCSI/ATAPI/ATA devices) and prints results π
π SYNOPSIS
sg_scan [-a] [-i] [-n] [-w] [-x] [DEVICE]*
π DESCRIPTION
okay so if you don't give sg_scan any DEVICE names, it goes and scans all the sg devices for you π and spits out one line of info for each sg device that's currently bound to a SCSI device. ngl it's so helpful. but if you do name one or more DEVICEs, it only scans those ones π¦ Each device gets opened with the O_NONBLOCK flag, so the scan won't get stuck "hanging" on any device that another process is holding an O_EXCL lock on. no drama, no cap π«Ά
any DEVICE name you hand it is supposed to follow (to some extent) the Storage Architecture Model (SAM, see www.t10.org) π Device names tied to the Linux SCSI subsystem, like /dev/sda and /dev/st0m, are totally fine. ATAPI devices are also welcome (think most CD/DVD drives and ATAPI tape drives) β¨ And if your device doesn't fit into any of those categories? no worries bestie, sg_scan tries an ATA IDENTIFY command instead πΈ
β οΈ heads up: in the Linux 2.6 and 3 series kernels, the lsscsi utility might be a lifesaver π Besides giving you more info (it data-mines the sysfs pseudo file system), it doesn't need root permissions to run, which is the big difference, since this one usually does π
π OPTIONS
-aβ does an alphabetical scan (sga, sgb, sgc, you get it) π€ Heads up, sg device nodes with an alphabetical index have been deprecated since the Linux kernel 2.2 series, so β it's kinda old news.-iβ does a SCSI INQUIRY and outputs the results on a second, indented line π If the device is an ATA disk, it outputs info from an ATA IDENTIFY command instead.-nβ does a numeric scan (sg0, sg1, sg2...) π’ this is the [default], so you get it without asking.-wβ opens the sg device with a read/write flag π the default is read-only, so you have to ask for this one explicitly.-xβ shows extra info about queueing π§
π¦ NOTES
okay storytime π This utility was written back when hotplugging SCSI devices wasn't supported in Linux yet π It used a simple algorithm to scan sg device nodes in ascending numeric or alphabetical order, and it would stop after there were 4 consecutive errors. very vintage.
In the Linux kernel 2.6 series, this utility uses sysfs to figure out which sg device nodes are active, and it only checks those β¨ So you can end up with big "holes" in the numbering of sg device nodes (like after an adapter got removed), and all the active sg device nodes will still get listed π This utility assumes the sg device nodes use the normal naming conventions and searches from /dev/sg0 to /dev/sg4095 inclusive π
π EXIT STATUS
the exit status of sg_scan is 0 when it's successful π₯³ Otherwise, go check the sg3_utils(8) man page for the rest of the story π
π«Ά AUTHORS
Written by D. Gilbert and F. Jansen π
π COPYRIGHT
Copyright Β© 1999-2013 Douglas Gilbert π· This software is distributed under the GPL version 2. There is NO warranty π not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. π
π SEE ALSO
lsscsi(8)π§
sg3_utils-1.36 Β· May 2013 Β· SG_SCAN(8) ππ thanks for reading, bestie, you're literally the best π«Άβ¨
π¦ where this page comes from
- alpine 3.24: sg3_utils-doc 1.48-r0 Β· BSD-2-Clause AND GPL-2.0-or-later
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- centos-stream 10: sg3_utils 1.48-11.el10 Β· GPL-2.0-or-later AND BSD-2-Clause
- debian trixie: sg3-utils 1.48-3~deb13u1
- fedora 43: sg3_utils 1.48-10.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 43: sg3_utils 1.48-6.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-10.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-8.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixos 26.05: sg3_utils 1.48
- nixpkgs unstable: sg3_utils 1.49
- ubuntu questing: sg3-utils 1.48-2ubuntu1
- ubuntu resolute: sg3-utils 1.48-3ubuntu3
- ubuntu resolute: sg3-utils 1.48-3ubuntu3.2
- ubuntu stonking: sg3-utils 1.48-3ubuntu5
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms