elacson
Posts: 7
Joined: Wed Dec 30, 2015 7:27 am
Location: Manila, Philippines

Network drive on fstab does not mount on start-up

Thu Dec 31, 2015 1:45 am

I have been all over the web looking for an answer for this. Essentially, I have a network drive mounted via /etc/fstab and works pretty well via 'mount -a'. However, I won't mount after restart.

This seems to be a common issue that has to do with fstab doing the mount before the network is available. Tried this putting this script on init.d as suggested in one of the post in stackexchange:

------------------------------
#! /bin/sh
# /etc/init.d/mountscript

### BEGIN INIT INFO
# Provides: Mounting of all drives
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to mount drives at boot
# Description: Added 30jan 2014
### END INIT INFO

#Now mount all drives
sudo mount -a
echo "All drives mounted"
----------------------------------------------------------------

Tested it with the following which works fine:

sudo /etc/init.d/mountscript start

...and finalled registered the script to be run at start-up:

sudo update-rc.d mountscript defaults

Everything seems to check well until I did a restart and the drive is not yet mounted. Starting the script manually mounted back the drive. This one seems to work fro most people but does not seem to work for me. I am running on Raspbian Jessie 4,1 with the latest updates,

Would appreciate some wisdom,

Thanks!

Erik

User avatar
DougieLawson
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Network drive on fstab does not mount on start-up

Thu Dec 31, 2015 9:35 am

Have you added

Code: Select all

,x-systemd.automount
to the lines in /etc/fstab? Try that and you won't need your script running at boot time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

elacson
Posts: 7
Joined: Wed Dec 30, 2015 7:27 am
Location: Manila, Philippines

Re: Network drive on fstab does not mount on start-up

Fri Jan 01, 2016 4:05 am

Thanks for the reply. I disabled the script and modified /etc/fstab as follows. but still does not mount in startup:

----------------------------------

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
//thisisoffline/seagate\040backup\040plus\040drive /media/networkshare/seagatedrive cifs guest 0 0 ,x-systemd.automount
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
---------------------------------------------------------

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Network drive on fstab does not mount on start-up

Fri Jan 01, 2016 5:07 am

It just needs a little re-arranging to get everything in the right column.

Code: Select all

//thisisoffline/seagate\040backup\040plus\040drive /media/networkshare/seagatedrive cifs guest,x-systemd.automount 0 0 

LesGirauds
Posts: 20
Joined: Tue Aug 13, 2013 2:52 pm

Re: Network drive on fstab does not mount on start-up

Fri Jan 01, 2016 7:01 pm

I had the same problem with a recent project; network drives would not mount from fstab. Even in a script started at startup (init.d) they wouldn't. Running the script manually (after boot up) worked. As did, as you say, mount -a (when I had the mount in the fstab) Searching the web suggested what was called a 'race condition' - basically the Pi boots more quickly than the network is recognised.

The way I got around it was to code a simple 'sleep 10' into my script. Not ideal but it worked.

I noted that in the recent Raspbian Jessie image, the rasp-config utility has the option to have the Pi boot process wait for network. Maybe it's always been there, I don't know, but it's worth a look.

User avatar
rubikwizard
Posts: 95
Joined: Tue Jan 10, 2012 10:37 pm
Location: West Yorkshire

Re: Network drive on fstab does not mount on start-up

Fri Jan 01, 2016 7:13 pm

I noted that in the recent Raspbian Jessie image, the rasp-config utility has the option to have the Pi boot process wait for network.
This works really well, and worth a try.

elacson
Posts: 7
Joined: Wed Dec 30, 2015 7:27 am
Location: Manila, Philippines

Re: Network drive on fstab does not mount on start-up

Sat Jan 02, 2016 9:01 am

Code: Select all

//thisisoffline/seagate\040backup\040plus\040drive /media/networkshare/seagatedrive cifs guest,x-systemd.automount 0 0
This returned an invalid argument error. Will try via raspi-config worse case.

Thanks to all!

Cheers!

Erik

User avatar
Gedarius
Posts: 2
Joined: Sun Jul 10, 2016 8:57 pm
Location: são paulo
Contact: Website

Re: Network drive on fstab does not mount on start-up

Sun Jul 10, 2016 9:17 pm

Hello,

sorry to late reply, but i had the same problem and this is how i solve it:

first give permission to your mount point:

Code: Select all

sudo chown -R pi:pi /mnt/HD1
sudo chmod -R 775 /mnt/HD1
sudo setfacl -Rdm g:pi:rwx /mnt/HD1
sudo setfacl -Rm g:pi:rwx /mnt/HD1
then, write the line below in the fstab:

Code: Select all

//192.168.0.111/myNetworkFolder     /mnt/HD1   cifs username=MyUsr,password=MyPass,sec=ntlm,uid=pi,gid=pi,_netdev,xsystemd.automount 0 0
username and password parameters are credentials of you network drive, in my case, its a FTP from my router (a USB pendrive)

pay attention on the sec=ntlm parameter, this make all the difference for me

this is it, reboot your raspberry and see it works =]

Return to “Raspberry Pi OS”