# Mounting iSCSI volumes on startup



## Morback (Mar 14, 2012)

Hello everyone,

I have a server running under FreeBSD 7.2. It's connected to an iSCSI NAS (Dell MD3000i) on which we have differents LUNs. On startup, the server mounts iSCSI devices, one in /var/spool/imap and another one in /var/ftp. I have deleted the entry about /var/ftp in the /etc/fstab file but this partition is still mounted on startup.

So my question is: where can I find the configuration file saying to the server to mount /var/ftp?

In fact I'm trying to mount another iSCSI LUN on startup but if I add an entry for this in /etc/fstab, the server doesn't boot (because it seems /etc/fstab is read before starting up the network services: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/boot-init.html).


----------



## gkontos (Mar 14, 2012)

You can't because ISCSI targets require networking. However, you can adjust the values in bold and use the below script to do that for you:


```
#!/bin/sh

# PROVIDE: iscsi
# REQUIRE: NETWORKING
# BEFORE: mountcritremote
# KEYWORD: shutdown

. /etc/rc.subr

name="iscsi"
start_cmd="iscsi_start"
stop_cmd="iscsi_stop"
rcvar="iscsi_enable"
required_modules="iscsi_initiator:iscsi"

iscsi_start()
{
        ${iscsi_command} -c ${iscsi_config} -n ${iscsi_nickname}
        if [ -f ${iscsi_fstab} ]; then
                devs=`sed -e '/^#/d' < ${iscsi_fstab} | cut -f 1`
                for xdev in $devs
                do
                        i=10
                        echo "Wait for $xdev"
                        while [ $i -ne 0 ]
                        do
                                [ -c $xdev ] && break
                                sleep 1
                                i=$(($i-1))
                        done
                done

                echo "mount -a -F ${iscsi_fstab}"
                mount -a -F ${iscsi_fstab}
        fi
}

iscsi_stop()
{
        if [ -f ${iscsi_fstab} ]; then
                echo "umount -a -F ${iscsi_fstab}"
                umount -a -F ${iscsi_fstab}
        fi
        killall -HUP ${iscsi_command}
}

load_rc_config $name

: ${iscsi_enable="NO"}
: ${iscsi_command="iscontrol"}
: ${iscsi_nickname="[B]idisk1[/B]"}
: ${iscsi_config="[B]/etc/iscsi.conf[/B]"}
: ${iscsi_fstab="[B]/etc/iscsi.fstab[/B]"}

run_rc_command "$1"
```

I found it somewhere in the Internet (can't recall where) so, I can't take any credit for it but it works!


----------



## Morback (Mar 14, 2012)

Thank you, I'll have a look on your script.

But currently two LUNs are mounted automatically on startup. Don't you have any idea where can this come from?


----------



## gkontos (Mar 14, 2012)

Morback said:
			
		

> Thank you, I'll have a look on your script.
> 
> But currently two LUNs are mounted automatically on startup. Don't you have any idea where can this come from?



No, but I would assume that a similar script takes care of that. Just look at the mountpoints and search in your /etc or /usr/local/etc with something like:

[CMD=""]#find . -type f -exec grep "mountpoint" /dev/null {} \;[/CMD]


----------



## Morback (Mar 15, 2012)

Oh, I found a script like the one you posted in /usr/local/etc/rc.d/. It seems my iSCSI drives are mounted with this script.

Thank you.


----------

