mount and umount automaticaly iSCSI volume at boot

715 views
Skip to first unread message

DanRoche

unread,
Apr 3, 2006, 12:36:14 PM4/3/06
to open-iscsi
Hello,

i am using open-iscsi-1.0-485 with fedora 4.
it works well, but i have problem if i want to mount
automatically iscsi volume at boot time,
and similarly to umount automatically at shutdown.

the problem is that iscsi volume are seen as standard scsi
disk, and the system try to mount them before iscsid is started
and similarly to umount after iscsid is down.

i solve the problem by creating a startup script to mount and umount
iscsi volume at the right time, for this if have set the noauto flag
in
fstab.

I am sure man can find a better solution, but meanwhile
it is easy to setup and it works.

here is the iscsi-volume script :
------------------cut here -----------------------------
#!/bin/sh
#
# chkconfig: - 99 01
# description: Mount / Umount iSCSI volume
#

#
# iSCSI volume are seen like standard scsi disk
# the rc scripts try to mount them early
# BEFORE iscsi is up,
# and more problematic, when shutdowning it try
# to umount after network is down -> crash
#
# one solution is to set the noauto flag for
# iSCSI volumes on fstab and call this script
# last on boot and early on shutdown
#

# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi

start()
{
RETVAL=0
echo -n "Mouting iSCSI volumes: "
mount /mnt/xxxx
mount /mnt/yyyy
return $RETVAL
}

stop()
{
RETVAL=0
echo -n "Unmounting iSCSI volumes: "
umount /mnt/xxxx
umount /mnt/yyyy
return $RETVAL
}


restart()
{
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0
------------------cut here -----------------------------

just put this script in /etc/init.d/iscsi-volume
and do a chkconfig -add iscsi-volume; chkconfig iscsi-volume on

TODO: it would be better to have a way to flag iscsi volumes in
/etc/fstab
and to loop automaticaly on this list. Any idea ?

Best Regards.

Mike Christie

unread,
Apr 3, 2006, 1:13:03 PM4/3/06
to open-...@googlegroups.com
DanRoche wrote:
> Hello,
>
> i am using open-iscsi-1.0-485 with fedora 4.

...

> TODO: it would be better to have a way to flag iscsi volumes in
> /etc/fstab
> and to loop automaticaly on this list. Any idea ?
>
>

In FC5 you can add the _nettdev flag in the fstab:

/dev/sda /mnt/t0 ext2 _netdev 0 0

I think this also might work in FC4 due to us resuing the sane netfs
scripts. When my FC4 system is fixed I can check.

Mike Christie

unread,
Apr 3, 2006, 1:37:40 PM4/3/06
to open-...@googlegroups.com
Mike Christie wrote:
> DanRoche wrote:
>> Hello,
>>
>> i am using open-iscsi-1.0-485 with fedora 4.
>
> ...
>
>> TODO: it would be better to have a way to flag iscsi volumes in
>> /etc/fstab
>> and to loop automaticaly on this list. Any idea ?
>>
>>
>
> In FC5 you can add the _nettdev flag in the fstab:
>

That should be "_netdev" like in the example below

DanRoche

unread,
Apr 3, 2006, 2:13:50 PM4/3/06
to open-iscsi
thank you,
il will test _netdev ASAP.
i'll let you know.

DanRoche

unread,
Apr 4, 2006, 4:05:24 AM4/4/06
to open-iscsi
Hello,
i confirm that the _netdev flag works on Fedora 4
even if it is not in the man page.

so you can forget about my script, and use netdev instead.

thank you very much.

Mike Christie

unread,
Apr 4, 2006, 5:02:56 PM4/4/06
to open-...@googlegroups.com
DanRoche wrote:
> Hello,
> i confirm that the _netdev flag works on Fedora 4
> even if it is not in the man page.
>

Hey, good. We lucked out. I guess i will add that to the docs.

Does anyone know what you do for suse and debian and gentoo? Do you add
_netdev to the fstab?

> so you can forget about my script, and use netdev instead.
>
> thank you very much.
>

no problem

DanRoche

unread,
Apr 4, 2006, 6:49:58 AM4/4/06
to open-iscsi
> Does anyone know what you do for suse and debian and gentoo? Do you add
> _netdev to the fstab?

yes, my fstab look like :
/dev/sda1 /mnt/lun/test1 auto _netdev 0 0
/dev/sda2 /mnt/lun/test2 auto _netdev 0 0

you just have to call /etc/init.d/netfs to get your iscsi drive
mounted.

you just have to pay attention that the iscsi daemon is launched before
netfs.
for 1.0-485 and fedora 4 it is not the case, i had to change the Sxx
number.

Mike Christie

unread,
Apr 5, 2006, 2:45:10 AM4/5/06
to open-...@googlegroups.com

What did you change it too so we can fix that here?

the nappy rat

unread,
Apr 5, 2006, 9:41:53 AM4/5/06
to open-iscsi
SuSE 10.0 does not seem to come with netfs scripts. I've been doing a
bit of searching, is netfs just a fancy init script or does it require
some binaries to assist it. If it's just a script could someone post
it so I can look at integrating it into my SuSE setup?

Thanks

berthiau...@emc.com

unread,
Apr 5, 2006, 12:08:55 PM4/5/06
to open-...@googlegroups.com
The netfs script is part of the initscripts package contained on Red
Hat's RHEL distributions. In SLES 8 and 9, SuSE utilized an
/sbin/iscsi-mountall and unmountall binary called within the iscsi init
script and no special mount options. Whereas Red Hat utilized the _netdev
mount option and would use the netfs script to mount and unmount any
designated network mount filesystems.

I'm just starting to look at SLES 10 myself, but I would hope they
already have this issue covered here. Perhaps our friends at SuSE
engineering could add something to this thread?

Regards,
Wayne.

DanRoche

unread,
Apr 5, 2006, 12:36:09 PM4/5/06
to open-iscsi
basically i have changed the chkconfig number
to 13 at startup and 89 at shutdown.
i have also added the touch and rm of
/var/lock/subsys/open-iscsi file.

here is the script:
---------------------cut here ---------------------
#!/bin/sh
#
# chkconfig: - 13 89
# description: Starts and stops the iSCSI initiator
#
# pidfile: /var/run/iscsid.pid
# config: /etc/iscsid.conf

# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

ISCSID=`which iscsid`
ISCSIADM=`which iscsiadm`

if [ -z $ISCSID ] || [ -z $ISCSIADM ]
then
echo "open-iscsi not installed."
exit 1
fi

start_iscsid()
{
RETVAL=0
modprobe -q iscsi_tcp
daemon $ISCSID
RETVAL=$?
TARGETS=`$ISCSIADM -m node | sed 's@\[\(.*\)\] .*@\1@g'`
for rec in $TARGETS
do
STARTUP=`$ISCSIADM -m node -r $rec | grep "node.conn\[0\].startup" |
cut -d' ' -f3`
if [ $STARTUP = "automatic" ]
then
$ISCSIADM -m node -r $rec -l
fi
done
return $RETVAL
}

stop_iscsid()
{
RETVAL=0
sync
TARGETS=`$ISCSIADM | grep "\[*\]" | sed 's@\[\(.*\)\] .*@\1@g'`
for rec in $TARGETS
do
$ISCSIADM -m node -r $rec -u
done
pkill -KILL `basename $ISCSID`
modprobe -r iscsi_tcp
RETVAL=$?
return $RETVAL
}

start()
{
RETVAL=0
echo -n "Starting iSCSI initiator service: "
PID=`pidofproc $ISCSID`
if [ -z $PID ]
then
start_iscsid
fi
if [ $RETVAL == "0" ]
then
touch /var/lock/subsys/open-iscsi
echo_success
else
echo_failure
fi
echo
return $RETVAL
}

stop()
{
RETVAL=0
echo -n "Stopping iSCSI initiator service: "
PID=`pidofproc $ISCSID`
if [ $PID ]
then
stop_iscsid
fi
if [ $RETVAL == "0" ]
then
rm -f /var/lock/subsys/open-iscsi
echo_success
else
echo_failure
fi
echo
return $RETVAL
}


restart()
{
stop
start
}

status()
{
PID=`pidofproc $ISCSID`
if [ ! $PID ]
then
echo "iSCSI initiator is stopped."
exit 1
else
echo "iSCSI initiator is running."
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;

status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac

exit 0
-------------------cut here---------------------

the nappy rat

unread,
Apr 5, 2006, 2:12:36 PM4/5/06
to open-iscsi
I believe SLES used linux-iscsi which did do things a bit different
than open-iscsi. I'm just using SuSE Linux Professional 10.0 not the
enterprise server but it comes with a open-iscsi package. However, the
iscsi-mountall is missing as i suspect that was part of linux-iscsi.
Sadly most of the documentation in novell's knowledgebase is based on
SLES9 and linux-iscsi. I'm in the process of writing a small guide
based on my experiences getting SUSE Professional 10.0 to work with my
iscsi san and the only part i've yet to complete is mounting issues. I
had been considering writing a custom little job like the original
poster in this tthread did but in light of this conversation i'm now
seeking a cleaner and more reliable method. Maybe i'll head to the
novell forums and test my luck ;)

Mike Christie

unread,
Apr 7, 2006, 11:10:44 PM4/7/06
to open-...@googlegroups.com
DanRoche wrote:
> basically i have changed the chkconfig number
> to 13 at startup and 89 at shutdown.
> i have also added the touch and rm of
> /var/lock/subsys/open-iscsi file.
>
> here is the script:

thanks. I merged the fixes in svn r532.

Reply all
Reply to author
Forward
0 new messages