From Bob Brandt's Projects Site

SLES: Workaround for iSCSI issues on SLES11

I have been using iSCSI with SLES10 for a while without any problems. And even though I have been using SLES11 for months, I never ran across this problem until recently. Turns out that using iSCSI with SLES11 (or SuSE 11.1) has a bit of a problem.

The problem is that you are unable to mount the iSCSI LUNs from within the /etc/fstab file when using the open-scsi software initiator. Now I am fully willing to admit that this "problem" is just due to my own stupidity, but from the research I have done online, I am not the only one to notice this problem.

The issue I had was that the system would try to mount the LUNs before the network was up and therefore failed. I tried a number of possible remedies but nothing worked:

What other people have done is to create custom scripts. However my problem with these script is that they seemed sloppy. I needed a system that would handle both the iscsi initiator and the mounting of the filesystems in one go. And I also wanted a system that would work with the existing GNU utilities.

What I can up with was a wrapper script for the open-scsi deamon (see below). This handles both the software initiator and mounting of the filesystems - for both starting and stopping. This way I can be sure certain that the system will neither try to mount filesystems before the an iSCSI connection is established nor kill the iSCSI connection without first umounting the filesystems.

To make this script work it is necessary to slightly modify the iSCSI entries in the /etc/fstab file:

/etc/fstab (an example)
/dev/system/swap     swap                 swap       defaults              0 0
/dev/system/root     /                    ext3       acl,user_xattr        1 1
/dev/sda1            /boot                ext3       acl,user_xattr        1 2
/dev/system/home     /home                ext3       acl,user_xattr        1 2
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
UUID=81ff75b2-c311-46ea-b1b9-bade8b597624	/data	iscsi,ext3	acl,user_xattr,sync,dirsync,nofail,noatime        1 2
/etc/init.d/iscsi-mount
#!/bin/bash
#
# /etc/init.d/open-iscsi
#
### BEGIN INIT INFO
# Provides:          iscsi-mount
# Required-Start:    $network
# Should-Start:      iscsitarget
# Required-Stop:     $network
# Should-Stop:       iscsitarget
# Default-Start:     3 5
# Default-Stop:      
# Short-Description: iSCSI initiator daemon wrapper
# Description:       The iSCSI initator is used to create and
#                    manage iSCSI connections to a iSCSI Target.
#                    This wrapper also takes care of iSCSI 
#                    fstab entries.
#                    Created by Bob Brandt <projects@brandt.ie>
#                    
### END INIT INFO

ISCSISCRIPT=/etc/init.d/open-iscsi
MOUNTSCRIPT=/etc/init.d/iscsi-mount
RCSCRIPT=/sbin/rciscsi-mount
declare -i overallstatus=0

test -h $RCSCRIPT || ln -sf $MOUNTSCRIPT $RCSCRIPT

# Source LSB init functions
. /etc/rc.status

# Reset status of this service
rc_reset

iscsimount() {
	rc_reset
	echo -n "Mounting $1: "
	mount $1
	rc_status -v
	return $?
}

iscsiumount() {
	rc_reset
	echo -n "Umounting $1: "
	umount $1
	rc_status -v
	return $?
}

iscsicheck() {
	rc_reset
	echo -n "Verify if $1 is mounted: "
	mount | grep "on $1\b" > /dev/null
	rc_status -v
	return $?
}

iscsimountall() {
	#Added to take care of LVM groups on iSCSI
	vgscan > /dev/null
	sleep 1
	vgchange -a y > /dev/null 

	# Find all fstab lines with iscsi as the fstype
	for mountpoint in `grep "iscsi," /etc/fstab | sed -e 's|\s*iscsi,.*||' -e 's|.*[ \t]/|/|'`; do
		# Only try to mount filesystems that are NOT currently mounted.
		if ! mount | grep "on $mountpoint\b" > /dev/null 
		then
			iscsimount $mountpoint || overallstatus=$?
		fi
	done
	return $overallstatus
}

iscsiumountall() {
	# Find all fstab lines with iscsi as the fstype
	for mountpoint in `grep "iscsi," /etc/fstab | sed -e 's|\s*iscsi,.*||' -e 's|.*[ \t]/|/|'`; do
		# Only try to umount filesystems that are currently mounted.
		if mount | grep "on $mountpoint\b" > /dev/null
		then
			iscsiumount $mountpoint || overallstatus=$?
		fi
	done
	return $overallstatus
}

iscsicheckall() {
	# Find all fstab lines with iscsi as the fstype
	for mountpoint in `grep "iscsi," /etc/fstab | sed -e 's|\s*iscsi,.*||' -e 's|.*[ \t]/|/|'`; do
		iscsicheck $mountpoint || overallstatus=$?
	done
	return $overallstatus
}

case "$1" in
    start)  $ISCSISCRIPT $@ && sleep 1 && iscsimountall ;;
    stop)   iscsiumountall && $ISCSISCRIPT $@ ; overallstatus=$? ;;
    status) $ISCSISCRIPT $@ && iscsicheckall ;;
    restart|reload) $0 stop && sleep 1 && $0 start ; overallstatus=$? ;;
    initiator) shift ; $ISCSISCRIPT $@ ; overallstatus=$? ;;
    *) echo "Usage: $0 {start|stop|status|restart|reload|initiator}"; overallstatus=1 ;;
esac
rc_failed $overallstatus
rc_exit
Retrieved from /projects/pmwiki.php?n=SLES.ISCSIOnSLES11
Page last modified on November 13, 2009, at 04:07 PM