Other iSCSI Mount Points at Boot

I am fairly new to FreeBSD having made the switch based on a really good experience breathing new life into an Xserve G4 with FreeBSD 10.2. So, I decided to switch out from CentOS Linux to FreeBSD on my dev server.

I was able to get everything up and running with no problem. I followed the instructions in the Handbook to the letter. My problem comes into play during a reboot - my iSCSI mount points fail but it seems to be a timing error. Apparently, iSCSI hasn't created the devices for which I can mount to.

In my /etc/fstab, I have the following:

Code:
# iSCSI Mounts
/dev/da0p1              /mnt/web        ufs           rw,late           3        3

If I issue the command: #mount -a -l

The device mounts and I can access the share with no problem.

When I reboot, the boot sequence stops and I get the error:

Code:
Cant stat /dev/da0p1:  No such file or directory

THE FOLLOWING FILE SYSTEM HAD AN UNEXPECTED INCONSISTENCY:
         ufs: /dev/da0p1 (/mnt/web)
Unknown error; help!
ERROR:  ABORTING BOOT (sending SIGTERM to parent)
Feb 21 09:49:00 init: /bin/sh on /etc/rc terminated abnormally, going to single user mode
Enter full pathname of shell or RETURN for /bin/sh:

All I do is press RETURN to enter the shell, type exit press RETURN again and this it continues to boot. I can see that my iscsi device then gets created (it's da0), some services get loaded and I am at the login prompt. When I login and check, all mounts are where they are supposed to be.

Ok...so I have determined that the iSCSI initiator is not creating the device before fstab gets parsed even though I have the "late" option specified.

What I did....
  • I commented out the line in question in /etc/fstab
  • I created a /etc/fstab-iscsi file with that same line
  • I then modified my /etc/rc.d/mountlate to wait 5 seconds then mount the file
Relevant mountlate code:
Code:
mountlate_start()

{

local err latefs
# Mount "late" filesystems.
#
err=0
        echo -n 'Sleeping for iSCSI to load'
        sleep 5                                        <------Wait 5 seconds
echo -n 'Mounting late file systems:'
mount -a -L -F /etc/fstab-iscsi               <------Mount fstab-iscsi
err=$?
echo '.'

While this works, I am positive this is not the right way to do this. Is there a proper way to get iSCSI devices mounted so that they are persistent across reboots?
 
Last edited by a moderator:
iSCSI or Internet SCSI is a way of mounting shares over the network at the block level as opposed to the file level (like NFS). Basically, the same way that a physical drive would appear on your system as /dev/ada0 or /dev/ada1, iSCSI drives show up as drives that you can mount, format, read/write, etc. If I wanted to, I could make an iSCSI drive part of a ZFS pool and do all the wonderfully ZFS stuff to it....

I will make the change you mentioned and see how it works out.
 
Last edited by a moderator:
So there are assorted daemons working hard on two or more machines, before the disk appears. noauto and devd-invoked mount /mnt/web springs to mind.

Juha
 
Untested, but try setting a higher value for kern.cam.scsi_delay="2000" in /boot/loader.conf. The value is in milliseconds, so try 5000 or 10000.
 
Same problem here.

I've tried to increase kern.cam.scsi_delay to 15000 (default is 5000), didn't work.

Thanks.
 
Basically, the problem here is that the iSCSI sessions are not setup quickly enough, and when the mountlate rc script runs, the iSCSI device is still not there yet. You have several options. The first one is the sleep, as above. Yeah, it's suboptimal, but rc scripts are easy to modify for a reason :)

Second way, 11-CURRENT only, is to use the -w flag for iscsictl. It makes the iscsictl(8) utility - which is what's used at boot - wait until the iSCSI sessions are established. So basically, you'd add
Code:
iscsictl_flags="-Aa -w 10"
to rc.conf.

Third way is to use autofs to defer mounting. Basically, you'd set up autofs (https://www.freebsd.org/doc/handbook/network-nfs.html) and either access the filesystem through /media (eg cd /media/da0p1 && ls), or change the entry in fstab from late to noauto and use the -noauto autofs map (https://www.freebsd.org/cgi/man.cgi?auto_master), or just use any other kind of autofs map; there are several possibilities to choose from.
 
Also, you can hook up the script below to devd, like this:

Code:
notify 100 {
        match "system" "GEOM";
        match "subsystem" "DEV";
        action "/usr/local/bin/mount_media";
};

And the script starts here:

Code:
#!/bin/sh

# Print a single map entry.
mount_media() {
        local _fstype _fstype_and_label _label _p

        for _p in ${providers}; do
                _fstype_and_label="$(fstyp -l "/dev/${_p}" 2> /dev/null)"
                if [ $? -ne 0 ]; then
                        # Ignore devices for which we were unable
                        # to determine filesystem type.
                        continue
                fi

                if [ ! -e ${_p} ]; then
                        mkdir "${_p}"
                fi

                _fstype="${_fstype_and_label%% *}"
                if [ ${_fstype} = "ntfs" ]; then
                        mount -t "${_fstype}" -o nosuid,mountprog=/usr/local/bin/ntfs-3g        "/dev/${_p}" "${_p}"
                else
                        mount -t "${_fstype}" -o nosuid "/dev/${_p}" "${_p}"
                fi
        done
}

# Obtain a list of (geom-provider-name, access-count) pairs, turning this:
#
# z0xfffff80005085d00 [shape=hexagon,label="ada0\nr2w2e3\nerr#0\nsector=512\nstripe=0"];
#
# Into this:
#
# ada0 r2w2e3
#
# XXX: It would be easier to use kern.geom.conftxt instead, but it lacks
#      access counts.
pairs=$(sysctl kern.geom.confdot | sed -n 's/^.*hexagon,label="\([^\]*\)\\n\([^\]*\).*/\1 \2/p')

# Obtain a list of GEOM providers that are not already open - not mounted,
# and without other GEOM class, such as gpart, attached.  In other words,
# grep for "r0w0e0".  Skip providers with names containing slashes; we're
# not interested in geom_label(4) creations.
providers=$(echo "$pairs" | awk '$2 == "r0w0e0" && $1 !~ /\// { print $1 }')

cd /mnt
mount_media
exit 0
 
Hilariously,
Code:
notify 200 {
  match  "system"  "DEVFS";
  match  "subsystem" "CDEV";
  match  "type"  "CREATE";
  match  "cdev"  "ufs/johnny";
  action "sleep 1; mount /dev/$cdev /mnt 2>&1 | logger";
};
still requires a sleep. It's Permission denied without it.

Juha
 
I tried the noauto solutions...but no joy. Here's what I did and the results:

When I issue a mount command, I see all my mounts plus the one I created in /etc/auto_master (/mnt/web). If I try to traverse the directory, my console starts throwing errors:


Code:
# mount

zroot/ROOT/default on / (zfs, local, noatime, nfsv4acls)
devfs on /dev (devfs, local, multilabel)
fdescfs on /dev/fd (fdescfs)
zroot/tmp on /tmp (zfs, local, noatime, nosuid, nfsv4acls)
zroot/usr/home on /usr/home (zfs, local, noatime, nfsv4acls)
zroot/usr/ports on /usr/ports (zfs, local, noatime, nosuid, nfsv4acls)
zroot/usr/src on /usr/src (zfs, local, noatime, nfsv4acls)
zroot/var/audit on /var/audit (zfs, local, noatime, noexec, nosuid, nfsv4acls)
zroot/var/crash on /var/crash (zfs, local, noatime, noexec, nosuid, nfsv4acls)
zroot/var/log on /var/log (zfs, local, noatime, noexec, nosuid, nfsv4acls)
zroot/var/mail on /var/mail (zfs, local, nfsv4acls)
zroot/var/tmp on /var/tmp (zfs, local, noatime, nosuid, nfsv4acls)
zroot on /zroot (zfs, local, noatime, nfsv4acls)
map -hosts on /net (autofs)
map -noauto on /mnt/web (autofs)


Code:
WARNING:  autofs_trigger_one: request for /mnt/web completed with error5
WARNING:  autofs_trigger_one: request for /mnt/web completed with error5
Feb 22 22L34:28 fred automountd[948]: mount failed

This goes on for a while until it times out.


I was about to try this new solution with devd, but I am not sure where to insert that script. I would love to try, but I am going to need a gentle (aka a swift kick) in the right direction.
 
Hm, it should work. Ok, autofs debugging 101: first, as root, kill automountd ( pkill -KILL automountd). Then run it from shell, like this:
Code:
while :; do automountd -d; done
Leave it running and access the directory in another shell window. You should see some debugging information from automountd; please paste it here.
 
Back
Top