17

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!

  • 2
    If the server is running Ubuntu, it is likely you need a / rather then a \ - "//192.168.0.26/mythtv/media " See wiki.ubuntu.com/MountWindowsSharesPermanently – Panther Jan 3 '14 at 21:01
  • @bodhi.zazen It may have had the / when I entered it, but it now reads out with the \ – douggro Jan 3 '14 at 22:42
  • Check the syntax ( / vs \ ) in fstab – Panther Jan 3 '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 4 '14 at 1:00
  • 1
    @bodhi.zazen Please convert your comment to an answer - changing the \ to / solved it. – douggro Jan 4 '14 at 9:12
7

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.

23

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.

  • 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 3 '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 4 '14 at 9: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
  • 1
    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 5 '16 at 2: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 1 '16 at 18:01
12

if _netdev doesn't work, try the option:

x-systemd.automount

instead. 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
  • 1
    thank you, this worked for me in 18.04 LTS – Chief Jul 19 '18 at 23:44
  • 1
    _netdev wasn't working on 18.04, this worked perfectly :) – Brian Leishman May 30 at 12:58
6

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.

  • 1
    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 7 '18 at 19:29
3

-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:

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.