Page 1 of 1

Cannot mount network share on boot

Posted: Thu Jun 14, 2018 1:24 pm
by dizzo
I have tried multiple walkthroughs on adding lines to fstab and on editing rc.local but so far nothing I have tried works. Even tried it as a chrontab task at one point.

I am trying to make it so that my raspberry pi mounts a folder from an external hard drive attached to my router's USB port (so not a NAS) on boot.

When I run the following command (password edited out obviously) after boot everything mounts up fine:

sudo mount -t cifs -o username=Plex,password=XXXXXXXX,vers=1.0 //192.168.1.1/Plex /home/pi/Plex/Library

But no matter what I do in terms of adding that command to fstab or rc.local it will not mount on boot. I always have to open a terminal and run it manually.

Any specific advice? I feel like there's probably just some "Duh!" thing I'm missing.

Re: Cannot mount network share on boot

Posted: Thu Jun 14, 2018 1:36 pm
by n67
This is probably in the category of "The network isn't up yet at the time you try to do the mount".

There are various solutions, some that use "systemd", some that do not.

Before suggesting a solution, it would be good to know what specific method(s) you've employed

Re: Cannot mount network share on boot

Posted: Thu Jun 14, 2018 1:49 pm
by dizzo
As an initial matter, the pi is connected via ethernet, if that makes a difference with the network not being up:

I've tried editing the fstab file from:
proc /proc proc defaults 0 0
/dev/mmcblk0p6 /boot vfat defaults 0 2
/dev/mmcblk0p7 / ext4 defaults,noatime 0 1

To

proc /proc proc defaults 0 0
/dev/mmcblk0p6 /boot vfat defaults 0 2
/dev/mmcblk0p7 / ext4 defaults,noatime 0 1
sudo mount -t cifs -o username=Plex,password=XXXXXXXX,vers=1.0 //192.168.1.1/Plex /home/pi/Plex/Library

I've also tried adding the same command to the rc.local file adding
sudo mount -t cifs -o username=Plex,password=XXXXXXXX,vers=1.0 //192.168.1.1/Plex /home/pi/Plex/Library

just above the exit 0 line.

If it really is a network not up issue, I don't have a problem with having it run the command itself say 30 seconds after booting up etc. That would be fine too.

Re: Cannot mount network share on boot

Posted: Thu Jun 14, 2018 2:37 pm
by n67
I would do this via rc.local and leave fstab alone. (Yes, I know a lot of the hardcores will go apoplectic over this and tell you to do it with some weird systemd thing or something, but ignore them)

Note, BTW, that you don't need "sudo" in rc.local, since rc.local runs as root anyway.

Next, if you're going to do it via rc.local, the first thing you need to do is get some logging going on, so you can tell what is happening and what is not working. The best way to do that is to put the following line into rc.local:

Code: Select all

exec > /tmp/rc-local.out 2>&1;set -x
just after:

# By default this script does nothing.

Now, after you boot, you'll be able to see what happens by looking at the file (/tmp/rc-local.out).
Presumably, you'll see some kind of error message from the mount command.

Next, you need to put some kind of delay in rc.local to wait for the network - note that even though you have ethernet, there's still some time involved in getting it up and running. One way is to do a ping loop, but the easiest way would be just loop your mount command. Something like:

Code: Select all

until mount -t cifs -o username=Plex,password=XXXXXXXX,vers=1.0 //192.168.1.1/Plex /home/pi/Plex/Library
do sleep 5;done
That will just keep trying it until it works.

Finally, note that pre-systemd, there was a problem with doing stuff like this in rc.local, since if you did anything wrong and rc.local didn't finish (say, if the above loop never succeeds), then your system would not finish booting (essentially becoming locked). Now that we have systemd, this doesn't happen anymore (rc.local is run asynchronously, like everything else).

Re: Cannot mount network share on boot

Posted: Thu Jun 14, 2018 3:51 pm
by dizzo
Worked like a charm. Thanks so much.