How shoud you auto-mount an NFS share in LEDE

I am trying to auto-mount an NFS share in LEDE but not having much success.

I have installed the relevant NFS client packages

kmod-fs-nfs 4.9.40-1
kmod-fs-nfs-common 4.9.40-1
nfs-utils 2.1.1-1

I have created the directory structure
/srv/remote/[serverdirectory]
on the router

I can manually mount this with the command
mount -t nfs -o nolock [serverIP]:/srv/nfs/[serverdirectory] /srv/remote/[serverdirectory]/

I can see the share in the LUCI gi-bin/luci/admin/system/fstab page
listed as [serverIP]:/srv/nfs/[serverdirectory] /srv/remote/[serverdirectory]

ls /srv/remote/[serverdirectory]
shows the file structure on the server

umount /srv/remote/[serverdirectory]/
unmounts the nfs share

When adding the following to /etc/fstab
[serverIP]:/srv/nfs/[serverdirectory] /srv/remote/[serverdirectory]/ nfs nolock 0 0
and running the command
mount -a
the nfs share is re-mounted.

However, the share does not mount automatically on reboot of the router.
I have run /etc/init.d/fstab enable.
but still the share does not auto-mount on reboot.
What am I missing?

Have you followed this: https://lede-project.org/docs/user-guide/fstab_configuration ?

Where possible I would avoid writing to configuration files directly and use UCI. I'm not even sure when/where /etc/fstab gets used in LEDE/OpenWrt. Reading your post made me check and mine is in fact empty, even though I'm auto-mounting a USB drive on boot.

For reference, here's the output of uci show fstab on my router.

fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].delay_root='5'
fstab.@global[0].check_fs='0'
fstab.@mount[0]=mount
fstab.@mount[0].target='/mnt/external'
fstab.@mount[0].device='/dev/mapper/external'
fstab.@mount[0].enabled='1'
fstab.@mount[0].fstype='ext4'

Thanks, chr0mag,

I had seen that link before and thought that it just had to do with USB and 'block' devices though and not nfs shares.

block detect > /etc/config/fstab does nothing for an NFS share.

I have tried to edit /etc/config/fstab as I can't find a command to populate it with the required configuration for an NFS share
I entered the following into /etc/config/fstab manually:-
config 'mount'
option target '/srv/remote/[serverdirectory]'
option device '[IPaddress]/srv/nfs[serverdirectory]'
option fstype 'nfs'
option options 'nolock'
option enabled '1'
and
running 'uci show fstab' displays :-
fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].delay_root='5'
fstab.@global[0].check_fs='0'
fstab.@mount[0]=mount
fstab.@mount[0].target='/srv/remote/[serverdirectory]'
fstab.@mount[0].device='[serverIP]:/srv/nfs/[serverdirectory]/'
fstab.@mount[0].fstype='nfs'
fstab.@mount[0].options='nolock'
fstab.@mount[0].enabled='1'

ran "block umount && block mount"
and done a reboot but this did not work. Even after removing the entry from /etc/fstab

I still can use the entry in /etc/fstab OK manually with 'mount -a' with the same configuration as above "[serverIP]:/srv/nfs/[serverdirectory] /srv/remote/[serverdirectory]/ nfs nolock 0 0" so I know that the parameters are OK.

I just found this:
https://forum.openwrt.org/viewtopic.php?pid=349731#p349731

It seems like a bit of a kludge.
But it is recent, so it "might just work".

Surely there is a better way than that...

You might be right. I notice the section titled Client installation (on LEDE) in the NFS configuration doc (https://lede-project.org/docs/user-guide/nfs_configuration) says its a work in progress but it should work in the usual linux way - which implies the use of /etc/fstab as you're doing.

If you just want to auto-mount on boot, I suppose you could add your working mount command to /etc/rc.local .

If you follow the hotplug method in the OpenWrt link you posted, you'll have more control over mounting/umounting based on the network availability.

Do you see any errors in dmesg or logread when you try running block mount?

Yes, I have looked at the NFS client installation page but I think that it assumes that you are using your LEDE router as the server and another machine as the client.

I have now tried the hotplug method and it's working well.

However, I then had an issue that nlbwmon (that's what I am using the nfs share for) seemed to be starting up before the nfs share is available and can't record its stats to the nfs share. If I restart nlbwmon it starts recording stats again.
I have changed the hortplug file to a lower number, 30-netmount, but that seems not to have fixed it.

in /etc/rc.d
S60nlbwmon
is higher than
S20network
so nlbwmon should be starting after the network is available but I am unsure how this relates to the files in /etc/hotplug.d/iface/ for ordering the nfs share to be mounted before nlbwmon starts.

Edit:
Ok, it seemed to work, in syslog I get this message:
NetMount: ifup: Mounting //<ip of nas>/backups in /mnt/backups
However the samba share isn't mounted :frowning: I suspect the samba share on the nas isn't avaiable by the time this hotplug script is executed...
Is there an easy way to tell it to wait or retry mounting until it's successfull?


Hi, just found this thread and have a simple question. I haven't used such hotplug script before. Could you help me set it up?
So I just paste the config 'netmount' stuff in /etc/config/fstab right?
Then create this file /etc/hotplug.d/iface/98-netmount and make it executeable.
Is there anything else to set up?

I just followed this: https://lede-project.org/docs/user-guide/hotplug_lede

I did too. The message output tells me the script is executed correctly. But I think too early. My nas with the samba share is connected to the router and upon reboot I think the share isn't reachable this early. Any idea how to delay the netmount?

In your
/etc/config/fstab

did you change
option fstype 'nfs' # or cifs
to
option fstype 'cifs'

I am not sure what packages you might need in LEDE for samba/cifs, but are they installed too?
samba36-client maybe ?
see https://lede-project.org/docs/user-guide/samba_configuration
But I think that page is geared to setting up a samba server on LEDE.

Yes I did that.
Also changed option src to '//nas/backups'.
I saw that cifs need the syntax with the slashes.

Yes, manual mount in console already works with this command:
mount -t cifs //nas/backups /mnt/backups -o rw,_netdev,user=<user>, password=<pw>

If it helps here is my config, keeping in mind I'm not using Samba and am mounting a LUKS encrypted USB drive.

Hotplug scripts are posted here: Automount LUKS encrypted USB drive on boot .

My NFS /etc/exports looks like this:

#/mnt	*(ro,all_squash,insecure,sync) #default config
#post-install config
/mnt		192.168.14.0/24(rw,sync,fsid=root,no_subtree_check,insecure)
/mnt/external	192.168.14.0/24(rw,all_squash,anonuid=65534,anongid=65534,sync,no_subtree_check,insecure,mountpoint)

...and uci show fstab

fstab.@global[0]=global
fstab.@global[0].anon_swap='0'
fstab.@global[0].anon_mount='0'
fstab.@global[0].auto_swap='1'
fstab.@global[0].auto_mount='1'
fstab.@global[0].delay_root='5'
fstab.@global[0].check_fs='0'
fstab.@mount[0]=mount
fstab.@mount[0].target='/mnt/external'
fstab.@mount[0].device='/dev/mapper/external'
fstab.@mount[0].enabled='1'
fstab.@mount[0].fstype='ext4'

I have nothing in /etc/fstab .

trohn_javolta, Also, I expect you should have entries something like the following in your /etc/config/fstab?

option options 'rw'
option options 'user=[user]'
option options 'password=[pw]'
option network 'lan'
option fstype 'cifs'

The /etc/hotplug.d/iface/ scripts get started in the right order dependent on their own numbering and other processes, which the script tests for, getting started. In my case I could have tested to see if the nlbwmon process was running as well as the lan interface being up I suppose.
In your case you would have to amend the script to wait until the the samba share on the nas is available somehow, I am not sure how, pinging it maybe?

or I guess that you could experiment with a sleep command in the hotplug script
e.g.

    if [ "$ACTION" = "ifup" ]
    then
        sleep 5s # Waits 5 seconds.
        logger "NetMount: $ACTION: Mounting $src in $target"
        mount -t $fstype -o $options $src $target
    elif [ "$ACTION" = "ifdown" ]

Yess! Sleep 5 helped, now it works! Thx

I just put mount -a before exit 0 in System - Startup - Local Startup script. The share is for saving backups, so for me it's enough.