Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3257971
  • 博文数量: 710
  • 博客积分: 14546
  • 博客等级: 上将
  • 技术积分: 6738
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 10:20
文章分类

全部博文(710)

文章存档

2016年(1)

2014年(7)

2013年(22)

2012年(227)

2011年(322)

2009年(119)

2008年(12)

分类: LINUX

2011-07-24 23:18:35

Create the following rules file /etc/udev/rules.d/55-openiscsi.rules on the client node linux3:

  1. # /etc/udev/rules.d/55-openiscsi.rules
  2. KERNEL=="sd*", BUS=="scsi", PROGRAM="/etc/udev/scripts/iscsidev.sh %b",SYMLINK+="iscsi/%c/part%n"

Next, create the UNIX SHELL script that will be called when this event is received. Let's first create a separate directory on the linux3 node where udev scripts can be stored:

  1. [root@linux3 ~]# mkdir -p /etc/udev/scripts

Finally, create the UNIX shell script /etc/udev/scripts/iscsidev.sh:

  1. #!/bin/sh

  2. # FILE: /etc/udev/scripts/iscsidev.sh

  3. BUS=${1}
  4. HOST=${BUS%%:*}

  5. [ -e /sys/class/iscsi_host ] || exit 1

  6. file="/sys/class/iscsi_host/host${HOST}/device/session*/iscsi_session*/targetname"

  7. target_name=$(cat ${file})

  8. # This is not an open-scsi drive
  9. if [ -z "${target_name}" ]; then
  10.    exit 1
  11. fi

  12. # Check if QNAP drive
  13. check_qnap_target_name=${target_name%%:*}
  14. if [ $check_qnap_target_name = "iqn.2004-04.com.qnap" ]; then
  15.     target_name=`echo "${target_name%.*}"`
  16. fi

  17. echo "${target_name##*.}"

After creating the UNIX SHELL script, change it to executable:

  1. [root@linux3 ~]# chmod 755 /etc/udev/scripts/iscsidev.sh

Now that udev is configured, restart the iSCSI initiator service:

  1. [root@linux3 ~]# service iscsi stop
  2. Logging out of session [sid: 3, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]
  3. Logout of [sid: 3, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]: successful
  4. Stopping iSCSI daemon: /etc/init.d/iscsi: line 33: 5143 Killed /etc/init.d/iscsid stop


  5. [root@linux3 ~]# service iscsi start
  6. iscsid dead but pid file exists
  7. Turning off network shutdown. Starting iSCSI daemon: [ OK ]
  8. [ OK ]
  9. Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]
  10. Login to [iface: default, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]: successful
  11. [ OK ]

Let's see if our hard work paid off:

  1. [root@linux3 ~]# ls -l /dev/iscsi/
  2. total 0
  3. drwxr-xr-x 2 root root 60 Apr 7 01:57 linux3-data-1

  4. [root@linux3 ~]# ls -l /dev/iscsi/linux3-data-1/
  5. total 0
  6. lrwxrwxrwx 1 root root 9 Apr 7 01:57 part -> ../../sda

http://www.idevelopment.info/data/Unix/Linux/LINUX_ConnectingToAniSCSITargetWithOpen-iSCSIInitiatorUsingLinux.shtml

如果需要挂载为裸设备看如下文章:

rhel5挂载为裸设备


阅读(1791) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~