45

I have a CIFS share on my NAS that I want to have mounted at boot - it's used by my MythTV server as the main media store. I added an entry into fstab to have it mount but it doesn't. It appears that, after looking through my system logs, fstab is being read before my network interfaces are coming online. Is there any edit I can make to the fstab entry that would alter this?

The fstab entry for mounting the share is:

\\192.168.0.26\mythtv\media  /media/mybooklive  cifs  username=user,password=pass,umask=002,uid=136,gid=144,iocharset=utf8   0       0

It mounts fine after boot when I issue sudo mount -a and there are no other issues with it.

Thanks!

douggro
  • 2,587

7 Answers7

47

If _netdev doesn't work, try this option instead:

x-systemd.automount

It works by mounting the drive at first access.

To test the automount, unmount your share if it's currently mounted:

sudo umount /media/mybooklive

And then restart the remote-fs systemd unit:

sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target
t-dome
  • 471
40

Have you tried adding the option _netdev to your fstab entry? You would add it with the other options in your string like so

//192.168.0.26/mythtv/media  /media/mybooklive  cifs  username=user,password=pass,_netdev,umask=002,uid=136,gid=144,iocharset=utf8   0       0

_netdev is supposed to delay the mount until after the network connects.

17

I am using the Raspbian-Stretch build dated 2017-09-07 and experienced the same issue. However, I was able to overcome this by going into raspi-config and under the Boot Options menu, I enabled the "Wait for network at boot" option.

Chris
  • 171
10

It is a syntax error, I think you need a "/" rather then a "\", like this

//192.168.0.26/mythtv/media  /media/mybooklive  cifs  username=user,password=pass,_netdev,umask=002,uid=136,gid=144,iocharset=utf8  0 0

See : https://wiki.ubuntu.com/MountWindowsSharesPermanently for additional information.

Panther
  • 104,528
6
  • Using forward slashes (/) did NOT fix it for me.
  • Also, adding the option _netdev to my /etc/fstab entry did NOT fix it for me.

What I have done to fix this problem (on my Pi3) is modify /etc/rc.local to sleep 20 seconds (by calling sleep 20) and then call mount -a. This way, even though the network is NOT connected yet when the system first reads the fstab file, so the mount fails then, I force the system to wait 20 seconds here (giving the network time to connect) then I force it to call mount -a again to mount all drives in the fstab file.

Here is what my /etc/rc.local file now looks like:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

Print the IP address

GS notes: a minimum of sleep 10 is required for the mount below to

work on the Pi 3; it failed with sleep 5, but worked with sleep 10,

sleep 15, and sleep 30

sleep 20 _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" mount -a #GS: mount all drives in /etc/fstab fi

exit 0

Done! It now works perfectly for me!

References:

  1. [my answer] https://raspberrypi.stackexchange.com/a/63690/49091
  2. https://www.raspberrypi.org/documentation/linux/usage/rc-local.md
  3. http://elinux.org/RPi_Email_IP_On_Boot_Debian - they have a similar rc.local file with a comment in it that says:
    # Print the IP address if it doesn't work ad sleep 30 before all your code
    

English grammar follow-up question I had regarding an edit to my answer:

  1. https://english.stackexchange.com/questions/568348/need-help-identifying-if-this-is-1-grammatically-correct-and-2-an-infinitive
Gabriel Staples
  • 11,502
  • 14
  • 97
  • 142
4

The failsafe method, always remember these 3 altogether:

  • noauto
  • x-systemd.automount
  • _netdev

Always works.

Method from How to auto mount using sshfs?, which I'm quoting below:

I am adding an fstab method, since no one talks about it in this page. If you don't want hacks and use the builtin advanced mounting features, you need to use /etc/fstab and never look back.

user@host:/remote/folder /mount/point  fuse.sshfs noauto,x-systemd.automount,_netdev,IdentityFile=/home/name/.ssh/id_rsa, allow_other,reconnect 0 0
  • noauto will stop the no-brainer actions like forcibly mounting whatsoever at booting regardless if the network is up or not.
  • x-systemd.automount is the smart daemon that knows when to mount.
  • The _netdev tag will also identify that it uses network devices, thus it will wait until the network is up.
Seandex
  • 629
0

not enough rep yet to make a succinct comment (so you get a verbose solution)

_netdev is only forcing what /etc/fstab will find out (cifs type means it needs the internet), and didn't help my case

solution for me (but I'm headless; i.e. no gui, no network-manager): added "auto eno1" to my /etc/network/interfaces

(originally, I only had "allow-hotplug eno1", which apparently wasn't enough to have my network up in time for /etc/fastab, but I had network, and my scripts had their own mount commands, so this was low priority for a while)

now all is well (for me)