Persistent SCSI device naming

With udev, you can define naming schemes that provide persistent SCSI device naming.

About this task

In persistent naming each device is always assigned the same unique name, independent of the sequence in which the devices are discovered. If a distribution has no predefined naming scheme for specific devices, or if a customized naming scheme is required, you can extend the set of rules for udev. Examples are given in the following paragraphs.

Procedure

  1. To display all information about a disk that is available to udev, use the udevinfo command:
    udevinfo -a -p /sys/class/scsi_generic/sg0

    The udevinfo command starts with the device the node belongs to and then walks up the device chain. For every device found, it prints all possibly useful attributes in the udev key format. Only attributes within one device section can be used together in one rule to match the device for which the node is created.

    device ’/sys/class/scsi_generic/sg0’ has major:minor 21:0
    looking at class device ’/sys/class/scsi_generic/sg0’:
    SUBSYSTEM=="scsi_generic"
    SYSFS{dev}=="21:0"
    follow the "device"-link to the physical device:
    looking at the device chain at 
    ’/sys/devices/css0/0.0.000e/0.0.54ae/host0/rport-0:0-0/target0:0:0/0:0:0:0’:
    
    BUS=="scsi"
    ID=="0:0:0:0"
    DRIVER=="sd"
    SYSFS{device_blocked}=="0"
    SYSFS{fcp_lun}=="0x512e000000000000"
    SYSFS{hba_id}=="0.0.54ae"
    SYSFS{iocounterbits}=="32"
    SYSFS{iodone_cnt}=="0x3a0"
    SYSFS{ioerr_cnt}=="0x1"
    SYSFS{iorequest_cnt}=="0x3a0"
    SYSFS{model}=="2105F20 "
    SYSFS{queue_depth}=="32"
    SYSFS{queue_type}=="simple"
    SYSFS{rev}==".693"
    SYSFS{scsi_level}=="4"
    SYSFS{state}=="running"
    SYSFS{timeout}=="30"
    SYSFS{type}=="0"
    SYSFS{vendor}=="IBM "
    SYSFS{wwpn}=="0x5005076300cb93cb"
    ...
  2. The combination of wwpn and fcp_lun provide a unique identifier for the device. Based on this information an additional rule can be written.
    Note: To avoid rules being overwritten in case of a udev update, keep additional rules in an extra file (for example, /etc/udev/rules.d/10-local.rules).

    For example, an additional rule to create a link for the LUN 0x401040c300000000 behind the WWPN 0x500507630310c562 with the persistent name /dev/my_zfcp_disk is:

    KERNEL=="sd*", SYSFS{wwpn}=="0x500507630310c562", \
     SYSFS{fcp_lun}=="0x401040c300000000", NAME="%k", SYMLINK+="my_zfcp_disk%n"
    Where:
    %k
    refers to the kernel name for the device
    %n
    is substituted by the number that is given by the kernel
    A detailed description of the udev rules can be found on the udev man page.

Results

The new rule leaves the original device names provided by the kernel intact and add symbolic links with the new device names:
# ll /dev/my_zfcp_disk*
lrwxrwxrwx 1 root root 3 Mar 14 16:14 /dev/my_zfcp_disk -> sda
lrwxrwxrwx 1 root root 4 Mar 14 16:14 /dev/my_zfcp_disk1 -> sda1

A more general rule that applies to all FCP disks and provides a generic persistent name based on fcp_lun and WWPN can be written as:

KERNEL=="sd*[a-z]", SYMLINK+="scsi/%s{hba_id}-%s{wwpn}-%s{fcp_lun}/disk"
KERNEL=="sd*[0-9]", SYMLINK+="scsi/%s{hba_id}-%s{wwpn}-%s{fcp_lun}/part%n"
Where:
%s
points to the information as it was given by the udevinfo command
With these rules, udev creates links similar to the following examples:
# ll /dev/scsi/*/*
lrwxrwxrwx  1 root root  9 May 22 15:19
          /dev/scsi/0.0.54ae-0x5005076300cb93cb-0x512e000000000000/disk -> ../../sda
lrwxrwxrwx  1 root root 10 May 22 15:19
          /dev/scsi/0.0.54ae-0x5005076300cb93cb-0x512e000000000000/part1 -> ../../sda1
lrwxrwxrwx  1 root root  9 May 22 15:19
          /dev/scsi/0.0.54ae-0x5005076300cb93cb-0x512f000000000000/disk -> ../../sdb
lrwxrwxrwx  1 root root 10 May 22 15:19
          /dev/scsi/0.0.54ae-0x5005076300cb93cb-0x512f000000000000/part1 -> ../../sdb1