OpenWrt Forum Archive

Topic: Mounting Network Drive to OpenWRT Filesystem

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

I have a small business website, nothing more than a storefront, that I host directly on my Linksys WRT400N using uhttpd.  The website is currently little more than a skeleton but as I've added features to my OpenWRT installation, memory is now at a premium and I would like to offload the website to external storage.  As the WRT400N does not have USB ports, I cannot host the website from a local stick.  What I do have is a WDTV Live Streaming which has USB ports and is always awake on the network.  The WDTV shares attached storage over the network using what I believe is SMB.

Googling dredges up endless discussions of attached USB drives but nothing about a remote drive.  How should I go about this?

You need smbclient. If the NAS offers NFS that would work even better.

What is this smbclient you speak of?  I have Luci's Samba plugin, which includes Samba 3.  Luci's UI for it looks like it only handles sharing mounts that the filesystem has already attached.

I should mention that I'm a noob with Linux.  I have a good grasp of what I'm wanting to do conceptually but I don't know the syntax for mounting a drive using SMB.

Thanks, towolf!  The remote USB stick mounted successfully using the document you linked.

For future googlers, I did have to specifically install kmod-nls-utf8 to support the UTF8 character set for anonymous login to my share.

I celebrated too soon.

I now want to automount the remote USB stick at boot.  My first attempt was to add

mount.cifs //IP.address.of.WDTV/Folder /mnt/Folder -o guest,iocharset=utf8,file_mode=0777,dir_mode=0777,nounix,noserverino

to rc.local (Luci>System>Startup).  I figured that if the command worked manually, it ought to work in rc.local.  Wrong!

I googled around a bit and found mention of using fstab so I tried making an entry there.  It shows up in Luci>System>Mount Points, it's marked Enabled, but it doesn't mount unless I do it manually.  That's probably what https://dev.openwrt.org/ticket/10366 is referring to.

Next, I read that I should be using a hotplug script instead of fstab: https://forum.openwrt.org/viewtopic.php?id=32812.  What I understood was that I needed to create a file in /etc/hotplug.d/iface.  I called it 41-cifsmount:

#!/bin/sh

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

. /etc/functions.sh
case "$ACTION" in
  ifup)
    if [ "$DEVICE" == "br-lan" ]; then
      mount -t cifs //IP.address.of.WDTV/Folder /mnt/Folder -o guest,iocharset=utf8,file_mode=0777,dir_mode=0777,nounix,noserverino
    fi
    ;;
  ifdown)
    if [ "$DEVICE" == "br-lan" ]; then 
      umount  /mnt/pub
    fi
    ;;
esac

That didn't work, either.  I'm well out of my depth at this point and would welcome any and all assistance.

Good news!  I added

sleep 30

before the mount.cifs command in rc.local and eventually the mount is added.  Now I'll play with the delay to see how long is necessary.

20 seconds works for me.  10 was too short.  15 worked a few times but failed once, and I need a margin for error so the website that I'm putting on this mount doesn't drop because the router booted a little slow.  If I knew what it needs to wait for, I could kludge together a if statement.

I had added block-mount, block-hotplug, and block-extroot during my blind experimenting.  I removed all of those and deleted the /etc/config/fstab entry for the mount and the rc.local command still works.  To mount a CIFS partition, apparently all that is needed is cifsmount and kmod-fs-cifs (probably kmod-nls-utf8, too).  I also removed all of the options except guest and I can still access the share fine.

I tried to push the start of the /etc/init.d/done script back from 95 to 100, because that's what calls /etc/rc.local.  I then removed the delay in rc.local.  However, the mount stopped loading at boot; I thought it was worth a try.  There's too much there that I don't understand so I'll hope someone comes along with a more elegant solution.

The discussion might have continued from here.