CentOS iSCSI

iSCSI udev fun with RHEL 5
Posted by Codafoo
on Wednesday, October 10

Configuring Redhat Enterprise Linux 5 with iSCSI is pretty straightforward. However, there is a critical problem with the configuration, non-conforming assignment of scsi drives across different systems.

You'll need to configure udev if you need consistent naming conventions for something like Xen live migrations.

  1. Add a new rule for iscsi in /etc/udev/rules.d/:
#iscsi.rules
      #below should all be on 1 line
      KERNEL=="sd*", BUS=="scsi", PROGRAM="/lib/udev/iscsidev.sh %b", SYMLINK+="iscsi/%c{1}/lun%c{2}/part%n"
  1. Add the iscsidev.sh shell script to /lib/udev/
#!/bin/sh
      #iscsidev.sh
      BUS=${1}
      HOST=${BUS%%:*}
      LUN=`echo ${BUS} | cut -d":" -f4`
      file="/sys/class/scsi_host/host${HOST}/device/session*/iscsi_session*/targetname"
      target_name=`echo $(cat ${file}) | cut -d":" -f2`

      if [ -z "${target_name}" ]; then
        exit 1
      fi

      echo "${target_name} ${LUN}"

3. Make sure /lib/udev/iscsidev.sh is executable:
chmod a+x /lib/udev/iscsidev.sh

4. Restart your iscsi device!
/etc/init.d/iscsi restart

#Now you should have consistent names found in /dev/iscsi/

# find /dev/iscsi
/dev/iscsi
/dev/iscsi/storevault1
/dev/iscsi/storevault1/lun2
/dev/iscsi/storevault1/lun2/part
/dev/iscsi/storevault1/lun1
/dev/iscsi/storevault1/lun1/part2
/dev/iscsi/storevault1/lun1/part1
/dev/iscsi/storevault1/lun1/part
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License