SG_SCAN(8)

πŸ“¦
version 1.49 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 Β© 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


sg3_utils-1.36 Β· May 2013 Β· SG_SCAN(8) πŸŒˆπŸ’– thanks for reading, bestie, you're literally the best 🫢✨

πŸ“¦ where this page comes from