Create the following rules file /etc/udev/rules.d/55-openiscsi.rules on the client node linux3:
- # /etc/udev/rules.d/55-openiscsi.rules
-
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:
- [root@linux3 ~]# mkdir -p /etc/udev/scripts
Finally, create the UNIX shell script /etc/udev/scripts/iscsidev.sh:
- #!/bin/sh
-
-
# FILE: /etc/udev/scripts/iscsidev.sh
-
-
BUS=${1}
-
HOST=${BUS%%:*}
-
-
[ -e /sys/class/iscsi_host ] || exit 1
-
-
file="/sys/class/iscsi_host/host${HOST}/device/session*/iscsi_session*/targetname"
-
-
target_name=$(cat ${file})
-
-
# This is not an open-scsi drive
-
if [ -z "${target_name}" ]; then
-
exit 1
-
fi
-
-
# Check if QNAP drive
-
check_qnap_target_name=${target_name%%:*}
-
if [ $check_qnap_target_name = "iqn.2004-04.com.qnap" ]; then
-
target_name=`echo "${target_name%.*}"`
-
fi
-
-
echo "${target_name##*.}"
After creating the UNIX SHELL script, change it to executable:
- [root@linux3 ~]# chmod 755 /etc/udev/scripts/iscsidev.sh
Now that udev is configured, restart the iSCSI initiator service:
- [root@linux3 ~]# service iscsi stop
-
Logging out of session [sid: 3, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]
-
Logout of [sid: 3, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]: successful
-
Stopping iSCSI daemon: /etc/init.d/iscsi: line 33: 5143 Killed /etc/init.d/iscsid stop
-
-
-
[root@linux3 ~]# service iscsi start
-
iscsid dead but pid file exists
-
Turning off network shutdown. Starting iSCSI daemon: [ OK ]
-
[ OK ]
-
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]
-
Login to [iface: default, target: iqn.2006-01.com.openfiler:scsi.linux3-data-1, portal: 192.168.2.195,3260]: successful
-
[ OK ]
Let's see if our hard work paid off:
- [root@linux3 ~]# ls -l /dev/iscsi/
-
total 0
-
drwxr-xr-x 2 root root 60 Apr 7 01:57 linux3-data-1
-
-
[root@linux3 ~]# ls -l /dev/iscsi/linux3-data-1/
-
total 0
-
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) |