SG_MAP(8)

πŸ’… sg_map(8) β€” the SG3_UTILS era, okurrr

okay so bestie, quick vibe check: this is sg_map from the sg3_utils fam, and it's here to tell you which Linux sg device (like /dev/sg0) matches up with which actual SCSI device. raw. unfiltered. ancient. iconic.


✨ SYNOPSIS ✨

sg_map [-a] [-h] [-i] [-n] [-scd] [-sd] [-sr] [-st] [-V] [-x]

πŸ¦‹ DESCRIPTION πŸ¦‹

ngl, sometimes it's genuinely a whole struggle to figure out which SCSI device a sg device name refers to β€” like, /dev/sg0... who is she?? πŸ’€ So this command literally loops through the sg devices and hunts down the matching SCSI disk, cdrom or tape device name, if there even is one. Scanners are the prime example of SCSI devices that have no alternate SCSI device name besides their sg device name β€” they're the main character with no understudy, fr fr.

⚠️ Okay, important: this utility is deprecated and has not been updated for years. Only very obvious bugs get fixed. Unless you're running a truly ancient Linux (like, 2.4 series or earlier πŸ’€), please use something like lsscsi(8) or the facilities that udev(8) offers instead. Periodt.

πŸŽ€ OPTIONS πŸŽ€

  • -a β€” assume the sg devices have alphabetical device names and loop through /dev/sga, /dev/sgb, etc. Default is numeric scan. Heads up though: sg device nodes with an alphabetical index have been deprecated since the Linux kernel 2.2 series. so like... vintage.
  • -h β€” print usage message then exit. the classic "help me help you" πŸ’…
  • -i β€” in addition, do a standard INQUIRY and output the vendor, product and revision strings for devices that are found. cute lil device biography ✨
  • -n β€” assume the sg devices have numeric device names and loop through /dev/sg0, /dev/sg1, etc. Default is numeric scan.
  • -scd β€” display mappings to SCSI cdrom device names of the form /dev/scd0, /dev/scd1 etc.
  • -sd β€” display mappings to SCSI disk device names.
  • -sr β€” display mappings to SCSI cdrom device names of the form /dev/sr0, /dev/sr1 etc.
  • -st β€” display mappings to SCSI tape device names.
  • -V β€” print out the version string then exit, without further ado. no small talk, love that for us 🫢
  • -x β€” after each active sg device name is displayed, there are five digits: <host_number> <bus> <scsi_id> <lun> <scsi_type>. the raw tea β˜•

🌸 NOTES 🌸

If no options starting with -s are given, then the mapping to all SCSI disk, cdrom and tape device names gets shown. all of them. no crumbs left behind.

If the device file system (devfs) is present, a line noting this is output. The "native" devfs scsi hierarchy makes the relationship between a sg device name and any corresponding disk, cdrom or tape device name easy to establish β€” which honestly replaces the need for this command entirely. However, many applications will continue to look for Linux SCSI device names in their traditional places. [Devfs supplies a compatibility daemon called devfsd whose default configuration adds back the Linux device names in their traditional positions.] πŸ‘‘

Quite often the mapping information can be derived just by observing the output of the command sg_map. However, if devices have been added since boot, this can be deceptive β€” messy, lowkey unreliable πŸ™ˆ

In the Linux kernel 2.6 series, something close to the mapping shown by this utility can be found by analysing sysfs. The main difference is that sysfs analysis will show the mapping between sg nodes and other SCSI device nodes in terms of major and minor numbers. While major 8, minor 16 will usually be /dev/sdb, that is not necessarily so. Facilities associated with udev may assign major 8, minor 16 some other device node name. This version of sg_map has been extended to cope with sparse disk device node names of the form /dev/sd<str> where <str> can be one of [a-z,aa-zz,aaa-zzz]. See the sg_map26 utility for a more precise way (i.e. less directory scanning) of mapping between sg device names and higher level names β€” including finding user defined names. so thorough, we love an overachiever πŸ’–

This utility was written at a time when hotplugging of SCSI devices was not supported in Linux. It used a simple algorithm to scan sg device nodes in ascending numeric or alphabetical order, stopping after there were 5 consecutive errors. five strikes and you're out, bestie.

In the Linux kernel 2.6 series, this utility uses sysfs to find which sg device nodes are active and only checks those. Hence there can be large "holes" in the numbering of sg device nodes (e.g. after an adapter has been removed) and still all active sg device nodes will be listed. This utility assumes that sg device nodes are named using the normal conventions and searches from /dev/sg0 to /dev/sg4095 inclusive. that's a LOT of searching. she's dedicated πŸ”₯


⭐ EXAMPLES ⭐

My system has a SCSI disk, a cd writer and a dvd player:

$ sg_map
# Note: the devfs pseudo file system is present
/dev/sg0  /dev/sda
/dev/sg1  /dev/sr0
/dev/sg2  /dev/sr1

In order to find which sg device name corresponds to the disk:

$ sg_map -sd
# Note: the devfs pseudo file system is present
/dev/sg0  /dev/sda
/dev/sg1
/dev/sg2

The -x option gives the following output:

sg_map -x
# Note: the devfs pseudo file system is present
/dev/sg0  1 0 1 0  0  /dev/sda
/dev/sg1  2 0 4 0  5  /dev/sr0
/dev/sg2  2 0 6 0  5  /dev/sr1

When a SCSI scanner is added, the output becomes:

$ sg_map
# Note: the devfs pseudo file system is present
/dev/sg0  /dev/sda
/dev/sg1  /dev/sr0
/dev/sg2  /dev/sr1
/dev/sg3

By process of elimination, /dev/sg3 must be the scanner. detective work. ate. πŸ”βœ¨


πŸ’€ EXIT STATUS πŸ’€

The exit status of sg_map is 0 when it is successful. Otherwise, see the sg3_utils(8) man page.


🧚 AUTHOR 🧚

Written by Douglas Gilbert.


🌈 REPORTING BUGS 🌈

Report bugs to <dgilbert at interlog dot com>.


Copyright Β© 2000-2026 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. (yes, that's the all-caps shouty part, respect the tradition πŸ’…)


πŸ“ SEE ALSO πŸ“

sg_map26(8) , scsi_info(8) , scsidev(8) , devfsd(8) , lsscsi(8) , udev(7)


and that's the whole page, bestie 🫢 this was sg3_utils-1.49, dated 2026-06-25, signing off β€” go use lsscsi(8) instead, i'm begging πŸ˜­πŸ’œ

πŸ“¦ where this page comes from