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
.
Background
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:
- You have a device, that's not always connected or always switched on.
All subsequent devices (devices with higher IDs) will then be assigned a
different device node, depending on the status of this device.
- You often change your SCSI setup, because you are testing things.
- Maybe you even reconfigure your SCSI bus online and rescan the bus via
the rescan-scsi-bus.sh script.
- You built in another SCSI hostadapter which is probed before the old one
by Linux.
Solution
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:
-
devfs
- 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)).
- scsidev
- 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.
- Miscelleaneous
- 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:
- 2.2 kernels (and later) produce a /proc/partitions file which
contains a list of partitions available.
- Recent mount versions can use this info and compare
UUIDs of your filesystems.
scsidev
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.
Status
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.
scsidev-2
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:
- Scanning is now done by scanning for all generic devices (sg) first. All
are inquired. The periph. dev type of the inquiry information informs the
program what type of device we deal with, so the required device nodes (sd,
st, sr) can be automatically created. For disks, an additional partition scan
is done, for tapes, a no-rewind alternate device is added.
- Added rev and hostname fields to the device database
and compare them with settings in /etc/scsi.alias.
- Handle more than 16 SCSI disks.
- More options, allowing e.g. continuation of the scan process, if
a SCSI generic is unavailable (could have been removed by
"remove-single-device" command).
The result is scsidev-2.0b.
Problems
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.)
Acknowledgements
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.
NEWS
- 00/01/23
- 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.
- 00/01/27
- 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.
- 00/01/28
- 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.
- 00/02/14
- The version scsidev-2.10 is released
almost unchanged from 2.09. You may want to have a look at the
diffs.
- 2000-07-15
- Added support for osst.
Use O_NONBLOCK for scanning devices.
Released version scsidev-2.20.
Diffs against 2.10 are available as well.
- 2000-08-28
- 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.
- 2000-09-05
- 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.
- 2002-07-26
- - 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.
- 2002-07-29
- - 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.
- 2002-07-30
- - 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.
- 2002-08-07
- - 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.
- 2002-08-07
- - Fix usage message
- Please update to version scsidev-2.27.
Diffs against 2.26 are also available.
- 2002-10-04
- - 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.
- 2003-06-30
- - 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.
- 2003-08-09
- - 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.
Links
More useful scsi stuff can be found on
Doug Gilbert's sg pages and
his SCSI pages for kernel 2.4.
More:
(w) by KG, last changed 2003-06-30