OpenWrt Forum Archive

Topic: Fstab not mounting cifs at boot or through CLI

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi, this is my first post here so I want to say thanks to everyone for all the info that is up. I have been able to solve most of my problems myself so far by just searching and reading others posts.

I am having an issue I cannot find any information about. I have a network share that I can access just fine and mount using either mount.cifs or mount -t cifs. When I try to mount it using fstab I am having some issues though.

When I mount using mount.cifs or mount -t it works just fine, this is the output of running the mount command with no arguments:

root@OpenWrt:~# mount -t cifs //192.168.1.9/share ~/mount/nas/share -o guest
root@OpenWrt:~# mount
rootfs on / type rootfs (rw)
(snip)
//192.168.1.9/share on /root/mount/nas/share type cifs (rw,mand,nodiratime,unc=\\192.168.1.9\share,username=root,domain=,rsize=16384,wsize=16384)

But I have tried to include this in my fstab config file using the following config:

config global automount
        option from_fstab 1
        option anon_mount 1

config global autoswap
        option from_fstab 1
        option anon_swap 0

config mount
        option target   /root/mount/nas/share
        option device   //192.168.1.9/share
        option fstype   cifs
        option options  rw,mand,nodiratime,unc=\\192.168.1.9\share,username=root,domain=,rsize=16384,wsize=16384
        option enabled  1
        option enabled_fsck 0

config swap
        option device   /dev/sda2
        option enabled  0

Now, the drive doesn't mount on reboot (which is why I am here) but it also doesn't mount when I run /etc/init.d/fstab start or restart. In my logread output there are no error messages other than a warning about not being able to find fsck (which shouldn't be an issue because it isn't enabled in fstab) and I also get that message running fstab start or restart.

I have tried the fix mentioned here http://wiki.openwrt.org/doc/uci/fstab#notes regarding the commenting out of that line in fstab and creating a symbolic link, but it hasn't improved. In fact, now when I run restart or stop I get:

swapoff: /etc/fstab: No such file or directory

which I assume is ecause fstab hasn't been able to successfully mount the drive in the first place?


Anyway I am running out of avenues of investigation here. I can't get any error messages or details in the log as to why it isn't mounting, I can't get it to mount at all using fstab yet I have no issues mounting and accessing it using the mount command.

Can someone tell me if there are any other ways of investigating why this isn't mounting, or possibly correct my config file for me? I have tried it with a lot of different options too in the options line but I have had no luck at all. Oh sorry I should add that I am using 10.03.

Thanks in advance if anyone is able to help.

edit: just wanted to add that I have also checked the dmesg output and there is nothing output there either

(Last edited by Goblox on 6 Nov 2011, 10:57)

Goblox wrote:

I am having an issue I cannot find any information about. I have a network share that I can access just fine and mount using either mount.cifs or mount -t cifs. When I try to mount it using fstab I am having some issues though.

1. check the order of scripts executed at startup with 'ls /etc/rc.d'
2. write a hotplug script that mounts when your network interface goes up and umounts when it goes down
3. ????
4. profit

Thank you so much! Solved my problem instantly, who needs fstab anyway eh hehe


I love this community, thanks again.

Goblox wrote:

Thank you so much! Solved my problem instantly, who needs fstab anyway eh hehe


I love this community, thanks again.

Hi, I've just faced with the same problem - can't mount cifs share during the initial bootup process. fstab doesn't work at all. hotplug script works, but doesn't mount the share. After the boot process is accomplished I can mount the share without any problems.

The device is WR941ND v2.2 running Backfire 10.03.1

The contents of /etc/hotplug.d/iface/21-cifs-mount is as follows

#!/bin/sh
# This script is executed as part of the hotplug event with
# HOTPLUG_TYPE=iface, triggered by various scripts when an interface
# is configured (ACTION=ifup) or deconfigured (ACTION=ifdown).  The
# interface is available as INTERFACE, the real device as DEVICE.

[ "$DEVICE" == "lo" ] && exit 0

. /etc/functions.sh
case "$ACTION" in
    ifup)
        if [ "$DEVICE" == "br-lan" ]
        then  /bin/mount -t cifs //10.20.251.23/router /cifs -o user=router,password=password09,nounix,noserverino
        fi         
    ;;
    ifdown)
        if [ "$DEVICE" == "br-lan" ] 
        then /bin/umount  /cifs
        fi
    ;;
esac

the contents of /etc/hotplug.d/iface directory is as follows:

root@router-2:~# ls -l /etc/hotplug.d/iface/
-rw-r--r--    1 root     root          242 Nov 14 13:34 00-netstate
-rw-r--r--    1 root     root         3622 Nov 14 13:34 10-routes
-rw-r--r--    1 root     root          537 Dec 20 21:53 20-firewall
-rw-r--r--    1 root     root          608 Jan 24 17:26 21-cifs-mount

My part of /etc/config/fstab is as follows:

config mount                                                                                                                          
        option target   /cifs                                                                                                          
        option device   //10.20.251.23/router                                                                                         
        option fstype   cifs                                                                                                          
        option options  user=router,password=password09,nounix,noserverino,rw
        option enabled  1                                                                                                             
        option enabled_fsck 0                                                                                                         
        option is_rootfs 0

The question is what's wrong in my config?

Any help would be very much appreciated.
Thank you, Dmitry

(Last edited by rdmitry on 24 Jan 2012, 15:54)

A little update. When I substituted /bin/mount -t cifs to /sbin/mount.cifs in hotplug script, Igot an error

mount error: cifs filesystem not supported by the system
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

which means, that cifs mount functions are unavailable at the network initialization point.
Now the question is when they become available during initial bootup process?

Regards, Dmitry

rdmitry wrote:

A little update. When I substituted /bin/mount -t cifs to /sbin/mount.cifs in hotplug script, Igot an error

mount error: cifs filesystem not supported by the system
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

which means, that cifs mount functions are unavailable at the network initialization point.
Now the question is when they become available during initial bootup process?

Regards, Dmitry

this script is proven to work

root@Alix:~# cat /etc/hotplug.d/iface/21-pub
#!/bin/sh

[ "$DEVICE" == "lo" ] && exit 0

. /etc/functions.sh
case "$ACTION" in
  ifup)
    if [ "$DEVICE" == "br-lan" ]; then
      mount -t cifs //192.168.0.100/pub /mnt/pub -o user=flux,nounix,noserverino
    fi
    ;;
  ifdown)
    if [ "$DEVICE" == "br-lan" ]; then 
      umount  /mnt/pub
    fi
    ;;
esac

It makes more sense to check for "$INTERFACE" == "lan" instead of "$DEVICE" == "br-lan", then it will also work if lan isn't a bridge for whatever reason.

Hi, I've just made it possible to use fstab for network mounts like cifs, smb and nfs. You have to add one more check in libmount_find_device_by_id() function  in /lib/functions/block.sh
Now it looks like

libmount_find_device_by_id() {                                                                                                                                  
        local uuid="$1"
        local label="$2"
        local device="$3"
        local cfg_device="$4"
        local found_device                                                                                                                                      

        if [ -n "$uuid" ]; then
                found_device="$(libmount_find_token "UUID" "$uuid")"
        elif [ -n "$label" ]; then
                found_device="$(libmount_find_token "LABEL" "$label")"
        elif [ "$device" = "$cfg_device" ]; then
                found_device="$device"
        elif [ -z "$device" ] && [ -e "$cfg_device" ]; then
                found_device="$cfg_device" 

## makes it possible to mount network shares

        elif [ "${cfg_device:0:2}" = "//" ] || [ -n $(/bin/echo $cfg_device | /bin/grep -iq ":") ]; then
                found_device="$cfg_device" 
        fi
        [ -n "$device" ] && [ "$device" != "$found_device" ] && {
                found_device=""
        }
        echo "$found_device"
}

However, hotplug script still doesn't work on boot. I think I have to to build custom backfire image with cifs/nfs modules included.

Regards, Dmitry

question;
what is the difference between putting a script in /etc/hotplug.d/net/ and in /etc/hotplug.d/iface/ ?

Here is another idea similar to /etc/hotplug.d script, but uses /etc/init.d/mountcifs:

#!/bin/sh /etc/rc.common

START=90

start() {
    mkdir -p /mnt/ext /mnt/sat
    mount -o user=,password=,noatime,nodiratime -t cifs //192.168.1.2/external /mnt/ext
    mount -o user=,password=,noatime,nodiratime -t cifs //192.168.1.4/harddisk /mnt/sat
}

stop() {
    umount /mnt/ext /mnt/sat
} 

Then use:

/etc/init.d/mountcifs enable
/etc/init.d/mountcifs start

This script works well for me. Also, similar scripts can start/stop many other things.

(Last edited by plasticassius on 19 Jan 2013, 12:31)

rdmitry wrote:

Hi, I've just made it possible to use fstab for network mounts like cifs, smb and nfs. You have to add one more check in libmount_find_device_by_id() function  in /lib/functions/block.sh
Now it looks like

libmount_find_device_by_id() {                                                                                                                                  
        local uuid="$1"
        local label="$2"
        local device="$3"
        local cfg_device="$4"
        local found_device                                                                                                                                      

        if [ -n "$uuid" ]; then
                found_device="$(libmount_find_token "UUID" "$uuid")"
        elif [ -n "$label" ]; then
                found_device="$(libmount_find_token "LABEL" "$label")"
        elif [ "$device" = "$cfg_device" ]; then
                found_device="$device"
        elif [ -z "$device" ] && [ -e "$cfg_device" ]; then
                found_device="$cfg_device" 

## makes it possible to mount network shares

        elif [ "${cfg_device:0:2}" = "//" ] || [ -n $(/bin/echo $cfg_device | /bin/grep -iq ":") ]; then
                found_device="$cfg_device" 
        fi
        [ -n "$device" ] && [ "$device" != "$found_device" ] && {
                found_device=""
        }
        echo "$found_device"
}

However, hotplug script still doesn't work on boot. I think I have to to build custom backfire image with cifs/nfs modules included.

Regards, Dmitry

I have same issue
Any solution on this?

flux wrote:
rdmitry wrote:

A little update. When I substituted /bin/mount -t cifs to /sbin/mount.cifs in hotplug script, Igot an error

mount error: cifs filesystem not supported by the system
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

which means, that cifs mount functions are unavailable at the network initialization point.
Now the question is when they become available during initial bootup process?

Regards, Dmitry

this script is proven to work

root@Alix:~# cat /etc/hotplug.d/iface/21-pub
#!/bin/sh

[ "$DEVICE" == "lo" ] && exit 0

. /etc/functions.sh
case "$ACTION" in
  ifup)
    if [ "$DEVICE" == "br-lan" ]; then
      mount -t cifs //192.168.0.100/pub /mnt/pub -o user=flux,nounix,noserverino
    fi
    ;;
  ifdown)
    if [ "$DEVICE" == "br-lan" ]; then 
      umount  /mnt/pub
    fi
    ;;
esac

Hi Flux, I already follow this step but still not work ( sorry I'm new). is there any additional commands at "hotplug2.rules" ,"hotplug2-common.rules" or "hotplug2.init.rules" must be added to make this work?
as jow advise, I changed  "$DEVICE" == "br-lan to "$INTERFACE" == "lan" but still not work on me.

(Last edited by exgenui on 18 Dec 2013, 21:47)

exgenui wrote:

Hi Flux, I already follow this step but still not work ( sorry I'm new). is there any additional commands at "hotplug2.rules" ,"hotplug2-common.rules" or "hotplug2.init.rules" must be added to make this work?
as jow advise, I changed  "$DEVICE" == "br-lan to "$INTERFACE" == "lan" but still not work on me.

Hotplug is very sensitive to script errors. If there's a single invalid command, the script stops short.
In my case (and probably yours) "/etc/functions.sh" does not exist. Therefore, the script must be modified in order to first check for it's existence.
And DEVICE really must be compared with "br-lan", since our /etc/hotplug.d/iface/21-foo script gets the following arguments when interface goes up :

ACTION=ifup INTERFACE=lan DEVICE=br-lan

Just to clarify, here's my working version :

!/bin/sh

[ "$DEVICE" == "lo" ] && exit 0

[ -f /etc/functions.sh ] && . /etc/functions.sh

#/usr/bin/logger hotplug.d iface : ACTION=$ACTION INTERFACE=$INTERFACE DEVICE=$DEVICE

case "$ACTION" in
  ifup)
    if [ "$DEVICE" == "br-lan" ]; then
      mount /path/to/mount
    fi
    ;;
  ifdown)
    if [ "$DEVICE" == "br-lan" ]; then
      umount  /path/to/mount
    fi
    ;;
esac

Thank you for helping us all.

(Last edited by hugo.leote on 30 Jan 2016, 03:59)

Hi,

I rewrote this script using UCI to get the configurations from a fstab-like file. I called the config section "netmount", so I can define network mounts in standard UCI fstab, and it should not introduce any issue with normal block-mount activity (at least based on the source code that I looked into). I use it for NFS exports, but it should work with CIFS/SMB shares as well.

The relevant section of my /etc/config/fstab:

config 'netmount'
    option enabled '1'
    option target '/mount/point'
    option src 'server.name.or.ip:/exported/dir'
    option options 'ro,nolock'
    option network 'lan'    # the INTERFACE as defined in /etc/config/network
    option fstype 'nfs'     # or cifs
    option delay 5

And the hotplug script (/etc/hotplug.d/iface/98-netmount):

#!/bin/sh

. /lib/functions.sh

network_mount() {
    local config="$1"
    local enabled
    local target
    local src
    local options
    local network
    local fstype
    local delay
  
    config_get_bool enabled "$config" enabled 0

    for opt in target src options network fstype delay
    do
        config_get "$opt" "$config" "$opt"
    done

    if [ "$enabled" = 1 -a "$INTERFACE" = "$network" ]
    then
        if [ "$ACTION" = "ifup" ]
        then
            if [ "$delay" -a $delay -gt 0 ]; then
                logger "NetMount: $ACTION: Sleep $delay seconds before mount"
                sleep $delay
            fi
            logger "NetMount: $ACTION: Mounting $src in $target"
            mount -t $fstype -o $options $src $target
        elif [ "$ACTION" = "ifdown" ]
        then
            logger "NetMount: $ACTION: Umounting $src from $target"
            umount $target
        elif [ "$ACTION" = "ifupdate" ]
        then
            logger "NetMount: $ACTION: DHCP renew. Leaving $src mounted in $target"
        else
            logger "NetMount: Unknown action $ACTION: Leaving $src mounted in $target"
        fi
    fi
}

config_load fstab
config_foreach network_mount netmount

UPDATE: if the IP is managed by DHCP, procd invokes the script with ACTION=ifupdate at every renew, umounting the volume. I've updated the script to handle this case (doing umount only for ifdown) and to log unknown actions

UPDATE: Thanks to trohn_javolta for sharing his experience, I think it may be useful to be able to configure a different delay on each mount, and I implemented it

(Last edited by SysRq on 17 Feb 2018, 15:43)

Edit: Ok, adding sleep 5s before mounting command fixed it!

Hi, sry to dig this up again.
Since I get this message in syslog, I assume I set everything up correctly:

NetMount: ifup: Mounting //<ip of nas>/backups in /mnt/backups

However the cifs share isn't mounted. It's on my nas and I suspect after a reboot of the router, my nas needs more time to reconnect to lan and serve the share.
I don't know if I'm right but can I somehow delay the mount command being executed?

(Last edited by trohn_javolta on 27 Jan 2018, 22:19)

The discussion might have continued from here.