Left Arrow Back to Linux page of KG

scsidev utility for Linux

Are you puzzled by the way Linux assigns device nodes to SCSI devices?
Do you have a lot of SCSI devices, but don't have them switched on all of the time?
Do you want to use a SCSI ID larger than 7 for one of your wide SCSI disks, but have an ZIP drive on 5, which is not always connected?

You need an alternative way of specifying disks, then. For this you may use the scsidev utility, or devfs .


On initialization of the SCSI drivers, Linux scans the SCSI bus for devices. The scanning goes from ID 0 up to ID 7 (or 15 on wide SCSI buses). The first disk being found is assigned sda (b 8 0), the second one sdb (b 8 16) and so on. This is handled the same way for the other SCSI devices (sr, st, sg).

Normally, this is a good thing, as you know that the first SCSI disk always is sda, no matter what SCSI ID you gave it. However, there are some situations, where this leads to problems:


When you want to use a device in those cases, you would rather like to tell the kernel to use a harddisk to be specified by the SCSI ID (which does not change) or even by the vendor name and serial number of the device, rather than by the dynamic device numbering the kernel uses.

Several software packages exist to help you out:

Add a completely new filesystem to the kernel, which is mounted to /dev/. Instead of having a huge collection of possible devices in /dev/, the devices there are created by the kernel. As the kernel knows which devices are present, it will only create device nodes for those. The SCSI device numering taken there (besides old compatibility entries) uses a naming cHbCtIuL with (H = Host (controller) no. , C = Channel (bus) number, I = SCSI ID (target), L = SCSI LUN (unit)).
This program scans the SCSI bus and creates device nodes in /dev/scsi/, which have a naming corresponding to their SCSI IDs and LUNs, just like with devfs. (The devfs has no notion of hostadapter IDs, scsidev is better here.) Furthermore, the devices are inquired to tell their names and serial numbers. Those can be compared with the entries in a database /etc/scsi.alias and device nodes corresponding to these entries are being built. So, this will even work if you change the SCSI IDs of a device, where the devfs approach would fail.
Probably there is more software available, which helps you to work with dynamic device numbering. You never know all of it!
Let me mention two things:


This nice program was written by
Eric Youngdale and creates a list of SCSI devices and assigns names like sdh4-334c0i0l0p1 to it, meaning Scsi Disk Host 4 - hostid 0x334 (IOPORT) Channel 0 scsi Id 0 Lun 0 Partition 0.
Furthermore it inquires the devices for manufacturer, model names and serial numbers and creates the aliases as specified in the alias database, thus allowing the usage of the same device, even in presence of SCSI ID changes.

The scsidev-1.5 released in Mar 1997, did unfortunately not compile and work any more on recent glibc and kernel versions. So I created a fix and talked to Eric Youngdale about it. We agreed on releasing the code under GNU GPL license and I created a bugfix release scsidev-1.6a.

Development goes on: After digging through the code, I had a lot of ideas to change things. Also, I stumbled across the problem, that removable devices were not handled gracefully. So I did make a lot of changes: The result is scsidev-2.0b.
I don't currently know about bugs, but there always are! Please report them to me.

Update: I found one by thinking about it: The program assumes the ordering of the generic SCSI devices is the same as the one of the disks, CDRoms, ... After booting, this is always true, but I can imagine one scenario, where it's not, any more: If you dynamically remove a tape and insert a disk instead (in presence of disk with higher IDs), then the freed sg slot might be reused, while the disk is appended to the list. This breaks assumptions, which scsidev is based on. (This does not apply to scsidev-1.6.)
An update to scsidev-2.1 is being worked on. It will add sanity checks to detect and handle such situations. (Handling them, is only possible in case everything is still uniquely detectable, which might not be the case in presence of more than one removable device.)

I'd like to thank Eric Youngdale to design and program the scsidev program in the first place. Thanks also go to SuSE GmbH for paying me for doing software development for Linux.
Using it
For using it, I have patched my boot script to call scsidev -q right after loading the scsi_hostadapter. Unfortunately, this is not as easy, because the / filesystem is readonly at this stage, and a ramdisk is used therefore. It is later cleaned up and the real /dev/scsi is populated by scsidev, again.
The patch is included in the tarball. If you are using SuSE 6.4 it should apply cleanly. Otherwise, it should give you an idea.
If your harddisk with the / fs is affected by SCSI changes, you might even need to work with an INITRD.
Oops! An embarassing bug has been found in both scsidev-1.6 and scsidev-2.0: If you call scsidev without installing a /etc/scsi.alias, it just segfaults. (The old routine just assumed nothing would go wrong reading a NULL file descriptor.)
Therefore, I now released 1.6a and 2.0a. The diffs can be found here for 1.6a and here for 2.0a.
Another bug has been spotted in scsidev-2.0: The hostname feature did not work reliably, due to the fact that the PROBE_HOST ioctl expects the buffer len to be found in the buffer. Fixed in scsidev-2.0b. Here are diffs: scsidev-20-20b.diff, scsidev-20a-20b.diff.
A prerelease for scsidev-2.1 is available. It does some additional sanity checks. Not inserted removable devices are only supported, if -r is specified.
The version scsidev-2.10 is released almost unchanged from 2.09. You may want to have a look at the diffs.
Added support for osst. Use O_NONBLOCK for scanning devices. Released version scsidev-2.20. Diffs against 2.10 are available as well.
Patch from Doug Gilbert: Prevent overflow of hostname (occurs with Advansys). Please update to version scsidev-2.21. Diffs against 2.20 are available as well.
Fixed parser for /etc/scsi.alias to handle the last line correctly in absence of a trailing LF. (Problem reported by Jürgen Vollmer). Please update to version scsidev-2.22. Diffs against 2.20 and against 2.21 are also available.
- Support for WWIDs (EVPD=1,INQ.page 0x83), wwid= in scsi.alias.
- Support LUNs up to 255
- Fix parser for hex numbers
Please update to version scsidev-2.23. Diffs against 2.22 are also available.
- Store permissions in .shadow normal files rather the dev nodes with the same name and minor 255.
- More independent on major numbers.
- Support for SDs up to 256.
- Handle SCSI changers (untested).
Please update to version scsidev-2.24. Diffs against 2.23 are also available.
- More work on cleaning up permission storage.
- Match short hostnames (/proc/scsi/*) alternatively.
- Adjust perms of underlaying rela dev nodes in symlink mode.
- Strip leading & trailing whitespace on SCSI INQUIRY responses.
- Support /proc/scsi/scsi extensions.
- Support for many disks (>256).
- Support collecting information from the /proc filesystem (ioports, host adapter names, partitions).
Please update to version scsidev-2.25. Diffs against 2.24 are also available.
- Program could segfault in case of failed inquiries. Fixed.
- Device type (chr. vs. blk) could be false. Fixed.
Please update to version scsidev-2.26. Diffs against 2.25 are also available.
- Fix usage message
Please update to version scsidev-2.27. Diffs against 2.26 are also available.
- Fix use of sscanf() (could break on some platforms, thanks to Olaf Hering)
- Fix parsing of device types in /proc/scsi/scsi: Spaces were breaking detection. (Thanks to Gerrit Hannaert for reporting and testing).
- Multipath support: With option -M, scsidev now accepts if more than one device matches an alias description and creates the alias for the first one found (and being operational).
Please update to version scsidev-2.28. Diffs against 2.27 are also available.
- Handle EOF from sscanf()
- Handle empty names gracefully (happens on zfcp, thanks to Bernd Kaindl!)
- Fix partition handling in symlink mode (thanks to Suresh Grandhi)
- Fix file descriptor leak (/proc/partitions) which limited the no of disks we could support
Please update to version scsidev-2.29. Diffs against 2.28 are also available.
- Document automatically created aliases (n version for tapes, -pX partitions for disks. (Thanks to Russel Shaw.)
- Detect HP HSV controllers, grab OS Unit ID, add alias support (HSVOSID=) for it. Fixes to searching for matching disks, so we skip ghost SCSI disks (common on failover configs). Contributed by Evan Felix (PNL).
- Optionally create old names with scd name instead of the more systematic sr name. (Some distros seem to prefer scd and so does devices.txt.) Option -o.
- Avoid crashes on empty model names. (Thanks to James Budworth for reporting.)
- Compatibility with 2.6 kernel. Reverse order of triggering SCSI HL driver module loads: Real devs should attach prior to sg.
- Compatibility with 2.6: Use sysfs to gather some information. Unfortunately, only block devs provide what we need, so far.
Please download scsidev-2.30. Diffs against 2.29 are available as well.
- The fix to partition handling from 2.29 got lost for some reason and was reintroduced. Thanks to Brian Keefer for noticing!
Please download scsidev-2.31 or apply the tiny diffs against 2.30 to a 2.30 tarball.
- sysfs has changed a bit since 2.6.0-test1. Adapt.
Please download scsidev-2.32 or apply the tiny diffs against 2.31 to a 2.31 tarball.
- Support longer host adapter names (thx to Wolfgang Celeda)
- Bug fix for dump page lengths and block vs. char device creation (Hannes Reineke)
- Support displaying ASCII T10 date from EVPD INQ page 0x83 (Hannes Reineke)
- Fix quiet option (Ulli Horlacher + /me)
- Allow alternate location of scsi.alias file (Ulli Horlacher)
- Allow large (>8bit) minors and majors (/me)
Please download scsidev-2.33 or apply the tiny diffs against 2.32 to a 2.32 tarball.
- Allow to switch off sysfs for debugging (-y).
- Make sure /dev/scsi/testdev is removed always..
- Don't overwrite scsi device type when getting serial no. etc. in fill_in_proc().
- Fix bug with channel specified in scsi.alias (contributed by Chris Townsend).
- Handle longer partition names.
Please download scsidev-2.35, or apply the diffs from 2.33 to 2.34 and the diffs from 2.34 to 2.35.
- Support for parsing sysfs info for tapes (2.6 kernel).
- Better parsing of 0x83 VPD INQUIRY pages.
- Use SG_IO instead of old sg interface if available.
Please download scsidev-2.36, or apply the diffs from 2.35 to 2.36.
- Support for changed sysfs filenames in linux kernel 2.6.17+
Please download scsidev-2.37, or apply the diffs from 2.36 to 2.37.


More useful scsi stuff can be found on Doug Gilbert's sg pages and his SCSI pages for kernel 2.4.
(w) by KG, last changed 2007-07-19