mapscsi - Linux SCSI device mapping tool Problem: Currently SCSI devices names are allocated in the order of probing. If an additional device is added and has a lower host, channel or id than existing devices, these other devices will all be shuffled along on the next reboot ie. /dev/sdb becomes /dev/sdc, etc. Causing much mayhem with fstab et al. mapscsi is a small utility that creates a consistent mapping to Linux scsi devices. mapscsi achieves this by creating symbolic links to linux scsi disk devices after scanning all scsi disk devices, finding out their host, channel, id, lun, pci location (if available), Fibre Channel world wide node and port names, loop and port ids (with qla2x00 v4.46.5 driver) vendor, product and serial number details and using this information plus a mapping rules file containing device templates to dynamically create link names. mapscsi is a simple alternative to devfs and provides the added ability of including drive information such as vendor / product details and serial numbers in in device link names. It is intended to be run at boot time after device probing. There is still no guarantee these mappings are correct if devices have been hotplugged. It would be advisable to run this program from hotplug scripts or in background mode (polls /proc/scsi/scsi for changes). Matching rules are specified as a combination of attribute=value pairs. One line is one rule. Each device is checked against the rules and if they match, device nodes are created using the rules device template 'map' with values substituted into the devicename based on those listed below. Matching rules are read from /etc/mapscsi.rules or rules can be provided on the commandline, overiding the rules file, eg. ./mapscsi 'type=disk map=/dev/scsi/h%hc%ct%tl%l' 'map' specifies the device template and 'partmap' optionally specifies the template for devices with partitions (a default of the device template is used with p%p appended if this parameter is not provided). If no rules file is provided, these default rules are used (this is a wildcard rule that matches all devices): map=/dev/%D/c%hb%ct%tu%l example /etc/mapscsi.rules type=disk map=/dev/scsi/h%hc%ct%tl%l partmap=/dev/scsi/h%hc%ct%tl%lp%p type=disk vendor=CNSi map=/dev/san/h%hc%ct%tl%l type=disk fcwwpn=2000005013b3385a map=/dev/san/array1-lun%l type=cdrom vendor='HP' product='CD-Writer-8200' map=/dev/cdburner Substitution codes and match parameters: %h host Host / adapter no %c channel Channel no %t id Target / scsi id %l lun LUN %p part Partition number %w fcwwnn FC World Wide Node Name (with qla2x00 v4.46.5) %W fcwwpn FC World Wide Port Name (with qla2x00 v4.46.5) %I fcdid FC Port ID (with qla2x00 v4.46.5) %L fclid FC Loop ID (with qla2x00 v4.46.5) %B pci PCI dev:slot.function (eg 00:0f.0) %H hostname HBA Driver Name %V vendor Vendor Inquiry info %P product Product Inquiry info %R revision Revision Inquiry info %S serial Serial Number Inquiry info %D prefix device prefix (sd, scd) %T type device type (disk, cdrom) %g sg_device generic device (eg. /dev/sg0) %d device original device (eg. /dev/sda) mapscsi will read /proc/partitions to work out how many partition links to create. Run with no options, mapscsi will output mappings with BSDish style device names. To actually create the links you need to use the -x option. # ./mapscsi /dev/sd/c0b1t0u0 -> /dev/sda /dev/sd/c0b1t0u0p1 -> /dev/sda1 /dev/sd/c0b1t0u0p2 -> /dev/sda2 /dev/sd/c0b1t0u0p3 -> /dev/sda3 /dev/sd/c0b1t0u0p4 -> /dev/sda4 /dev/sd/c0b1t0u0p5 -> /dev/sda5 /dev/sd/c0b1t0u0p6 -> /dev/sda6 /dev/sd/c0b1t0u0p7 -> /dev/sda7 /dev/sd/c0b1t0u0p8 -> /dev/sda8 /dev/sd/c0b1t0u0p9 -> /dev/sda9 /dev/sd/c0b1t0u0p10 -> /dev/sda10 /dev/scd/c1b0t0u0 -> /dev/scd0 /dev/scd/c1b0t1u0 -> /dev/scd1 mapscsi now removes links created by previous runs. It does this by storing previously links in a file /var/state/mapscsi/devicemap. Command line options usage: mapscsi [-h] [-x] [-s] [-n] [-a] \ [-c ] [-d ] \ "[attrib=value [attrib=value]...]" ... -h show this help message -x execute - actually make the links -b background - poll for changes in the background -s silent - don't show mappings on stdout -n numeric sg device names eg. /dev/sg0 (default) -a alpha sg device names eg. /dev/sga -p print device scan information -R don't remove previous links -S don't save state in /var/state/mapscsi/devicemap -c mapscsi rules file (default /etc/mapscsi.rules) -d mapscsi state file (default /var/state/mapscsi/devicemap) Related software An alternative and more mature tool that has similar function is scsidev: http://www.garloff.de/kurt/linux/scsidev/ I didn't discover scsidev until after I'd written mapscsi. I think mapscsi is a little more flexible with device mapping than scsidev and it has the addition of mapping Fibre channel WWNs and a background daemon mode to dynamically pick up device changes. Although mapscsi support for removeable devices and tapes isn't quite there yet. Many thanks to Doug Gilbert (sg_utils) and the authors of the SCSI Programming HOWTO for providing the examples I needed to create this program. Copyright Metaparadigm Pte. Ltd. 2001. Michael Clark This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.