41

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,537
  • 2
    If the server is running Ubuntu, it is likely you need a / rather then a \ - "//192.168.0.26/mythtv/media " See https://wiki.ubuntu.com/MountWindowsSharesPermanently – Panther Jan 03 '14 at 21:01
  • @bodhi.zazen It may have had the / when I entered it, but it now reads out with the \ – douggro Jan 03 '14 at 22:42
  • Check the syntax ( / vs \ ) in fstab – Panther Jan 03 '14 at 22:43
  • @bodhi.zazen I'm pretty sure that the wiki article is what I followed when setting it up. I'll check syntax later when I get time to sit with my server. – douggro Jan 04 '14 at 01:00
  • After reading your question again, I think you need to follow djmadscribbler's advice. – Panther Jan 04 '14 at 01:14
  • 1
    @bodhi.zazen Please convert your comment to an answer - changing the \ to / solved it. – douggro Jan 04 '14 at 09:12

6 Answers6

46

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
  • 461
39

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.

djmadscribbler
  • 556
  • 4
  • 10
  • Can you add context to where that would be placed in the fstab line? With that, and a period where I can reboot the server when it's not being used, I will give it a try. Thanks for answering. – douggro Jan 03 '14 at 20:33
  • Turns out bodhi.zazen had the right track with his comment. I did give you an upvote for your help. Thanks! – douggro Jan 04 '14 at 09:13
  • 1
    This worked for me in Ubuntu 12.04 but not in Ubuntu 16.04. Has this changed in the latest version? – Katu Apr 25 '16 at 14:46
  • same here, not working in 16.04 – jcollum May 23 '16 at 00:24
  • 2
    Note: I think _netdev actually works in 16.04, however credentials=/home/user/.smbcreds does no longer works. At least for me when I use user=, pass=, _netdev it works, when I use credentials=,_netdev it does not. Both work via sudo mount-a from the command line after booting. – jb510 Jun 05 '16 at 02:59
  • 1
    I actually think this might have more to do with the permission changes that were made to the media folder. At some point, Ubuntu started mounting things to /media/username/folder name rather than /media/folder name. If don't mount to the "username" location then you have to have sudo level permissions for access. If you change your path to use the /media/username path I think it should still work. – djmadscribbler Aug 01 '16 at 18:01
  • 3
    _netdev - Only valid with fstype nfs – Mikhail Chuprynski Aug 28 '17 at 20:20
  • This worked, but only after I figured out that my network path also wasn't resolving properly on my local network. I had to add a domain suffix. Probably a peculiarity of my PFSense box. I was trying to mount //freenas/x/y, but my dns resolver wanted to see //freenas.pflan/x/y. – gregb212 Nov 03 '22 at 04:12
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
  • 3
    This is actually VERY helpful, i had problems that even if boot said everything OK it did just not mounted it or display folders – Alfred Espinosa May 07 '18 at 19:29
  • Thanks! That was it. This must be #1 reason for fstab entries not loading or raspberries as such option is turned off by default. Cheers. – drakorg Nov 01 '20 at 19:54
  • 1
    This does a great job of filling in for the "_netdev" argument, which ONLY works for NFS shares. – Frankie0p Oct 17 '22 at 10:35
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
  • 102,067
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
  • Are you connecting via wifi? – cbcoutinho Nov 17 '17 at 22:27
  • Yes, I'm using WiFi instead of ethernet. – Gabriel Staples Nov 21 '17 at 13:41
  • That's indeed very strange, but probably not related to my issue. I have three network drives I'm trying to connect through an ethernet cable - no wifi. One of the drives' names has a special character in it, and that causes it to not be connected after a fresh boot. Executing sudo mount -a solves the issue, but I'm curious why it doesn't work while booting up. I'll try your solution and see if that helps. – cbcoutinho Nov 21 '17 at 13:58
  • 1
    You wrote "What I have done to fix this problem (on my Pi3) is modify /etc/rc.local to sleep". The use of 'modify' here is good correct English. To use 'modifying' would be wrong. Pseudo-cleft sentences (also called wh-clefts) are similar in function to cleft sentences, but they are formed with the pronoun what (= the thing(s) that/which). The emphasis in a pseudo-cleft sentence is on the phrase after the what-clause + be: In the past simple and present perfect, we can use the following pattern What I have done is (to) write a letter to the editor. – Michael Harvey Jun 02 '21 at 19:41
3

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
  • 579