cprins1908
Posts: 10
Joined: Mon Jun 22, 2015 6:57 pm

mount network share on boot

Thu Aug 27, 2015 6:38 pm

Hi there,

I figured out how to mount a windows network share to my PI.
After that I added a line to my fstab so the mount is executed at each boot
Unfortunately my network file is not mounted during boot
When I type sudo mount -a at the command prompt my windows share is mounted so that means that the line in my fstab is correct.
Now I learned that this behavior might be caused by the fact the network is not active when fstab is being executed.
To overcome this adding a small script to /etc/init.d calling sudo mount -a (and a echo to so if its been executed) should be added to update-rc.d
(I wrote a similar script for starting VNC and that works)
When I boot my PI still the share is not mounted, I checked the boot log but no sign there from my echo I put in my script (I do see the echo from the VNC script).

What other options are there to mount my network share at boot time

Thanks in advance
Christian

User avatar
rpdom
Posts: 15385
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: mount network share on boot

Thu Aug 27, 2015 7:05 pm

Put a mount command in /etc/rc.local.

There does seem to be a problem with mounting certain types of share at boot time, quite a few people have reported it. I think it might just be Windows type shares (CIFS/SAMBA), as I don't have any problems with my NFS file systems mounting at boot time.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: mount network share on boot

Thu Aug 27, 2015 7:07 pm

It also happens with USB drives (if for whatever reason, the USB subsystem isn't fully functional at the moment that fstab is processed).
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

beta-tester
Posts: 1242
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: mount network share on boot

Thu Aug 27, 2015 7:30 pm

Joe Schmoe wrote:It also happens with USB drives (if for whatever reason, the USB subsystem isn't fully functional at the moment that fstab is processed).
i think there was a bootdelay in cmdline.txt or config.txt needed for RPi2 to get some USB drives to be mounted properly at boot time via fstab.

BTW: i have a NAS that populates Windows shares only (no NFS)...
they will be mounted automatically at boot time via fstab (in case the share is available at boot time)
so, lucky me, in my case it works

Code: Select all

//192.168.100.123/share /media/nas123 cifs defaults,uid=pi,gid=pi,user=guest,password=guest,rw 0 0
Last edited by beta-tester on Thu Aug 27, 2015 7:46 pm, edited 1 time in total.
{ I only give negative feedback }
RPi B (rev1, 256MB), B (rev2, 512MB), B+, 2B, 3B, 3B+, ZeroW, ...

cprins1908
Posts: 10
Joined: Mon Jun 22, 2015 6:57 pm

Re: mount network share on boot

Thu Aug 27, 2015 7:45 pm

Adding sudo mount -a to the /etc/rc.local did the trick

Thanks

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Tue Mar 22, 2016 8:05 pm

Hello,

same problem here, but /etc/rc.local did not the trick or I made a mistake. I removed the first "#" and added the mount command that worked in the command line after boot.

Code: Select all

!/bin/sh -e

sudo mount -t cifs -o user=ftpuser,password=123 //192.123.123.1/share /media/smbFNAS
#
# 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.
...
Any suggestions?
thx
WOLF

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

Re: mount network share on boot

Tue Mar 22, 2016 10:17 pm

Use systemd to mount it rather than rc.local, it works much better, those posts are a bit outdated.

Use the following in fstab (edit as needed of course)

Code: Select all

//192.123.123.1/share /media/smbFNAS cifs username=ftpuser,password=123,uid=pi,gid=pi,x-systemd.automount 0 0
That's all one long line, no line breaks. I added the "uid" and "gid" so the mounted share would belong to "pi" rather than root. If you're using a different username on the RPi then use that instead of "pi".

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Tue Mar 29, 2016 3:40 pm

JimmyN wrote:Use systemd to mount it rather than rc.local, it works much better, those posts are a bit outdated.

Use the following in fstab (edit as needed of course)

Code: Select all

//192.123.123.1/share /media/smbFNAS cifs username=ftpuser,password=123,uid=pi,gid=pi,x-systemd.automount 0 0
I added that line to the fstab and made a reboot. If I try to change into that directory smbFNAS I got an error message like the following:

Code: Select all

pi@Raspi2HBB:/media $ cd smbFNAS
di-bash: cd: smbFNAS: no "fitting" device "found/present"
Do I have to edit something else?
thx
WOLF

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

Re: mount network share on boot

Tue Mar 29, 2016 4:01 pm

What do you get with a "df -h" command, or a "mount" command? Is the share mounted?

User avatar
RaTTuS
Posts: 10487
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: mount network share on boot

Tue Mar 29, 2016 4:13 pm

typxxi wrote:Hello,

same problem here, but /etc/rc.local did not the trick or I made a mistake. I removed the first "#" and added the mount command that worked in the command line after boot.

Code: Select all

!/bin/sh -e

sudo mount -t cifs -o user=ftpuser,password=123 //192.123.123.1/share /media/smbFNAS
#
# 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.
...
Any suggestions?
thx
put the # back in the first line of that file
then do it via systemd
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Tue Mar 29, 2016 5:56 pm

JimmyN wrote:What do you get with a "df -h" command, or a "mount" command? Is the share mounted?
As I mentioned before I got an error if I try to go into the "target dir" smbFNAS
If I do a mount manually I will be able to enter that dir and see all the subdirs of that NAStorage

Regarding your last questions df - h brings this

/dev/root 7,2G 4,8G 2,1G 70% /
devtmpfs 412M 0 412M 0% /dev
tmpfs 416M 0 416M 0% /dev/shm
tmpfs 416M 6,0M 410M 2% /run
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
tmpfs 416M 0 416M 0% /sys/fs/cgroup
/dev/mmcblk0p1 60M 20M 41M 34% /boot
tmpfs 84M 0 84M 0% /run/user/1000

There is no mounted NAS.
WOLF

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Tue Mar 29, 2016 8:45 pm

RaTTuS wrote:put the # back in the first line of that file
then do it via systemd
OK, I have put the # back and after reboot nothing has changed - no access

But what do you mean with that "via systemd"?

Even if I add that "systemd" to fstab I still get (after reboot) the same error if I try to change the directory.
If I try to go to "/media/smbFNAS" I still get the same error as mentioned above. And /media/smbFNAS does exist.

thx
Last edited by typxxi on Tue Mar 29, 2016 8:51 pm, edited 1 time in total.
WOLF

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

Re: mount network share on boot

Tue Mar 29, 2016 8:51 pm

That's a bit unusual. First the error message itself when changing to the directory.

Code: Select all

cd smbFNAS
di-bash: cd: smbFNAS: no "fitting" device "found/present"
Normally it would look like this:

Code: Select all

cd smbFNAS
-bash: cd: smbFNAS: No such file or directory
And even if the mount had failed the /media/smbFNAS/ mount directory would be there, so you'd be able to "cd" to it, even though it's empty.

Do you have a mount directory at "/media/smbFNAS"?
What do you get with a "ls -l /media"

What is the exact mount command you're using that works (edit any passwords). After it's mounted manually what do you get with a "mount" command, and a "ls -l /media" command.

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Wed Mar 30, 2016 7:58 am

JimmyN wrote:That's a bit unusual. First the error message itself when changing to the directory.

Code: Select all

cd smbFNAS
di-bash: cd: smbFNAS: no "fitting" device "found/present"
Normally it would look like this:

Code: Select all

cd smbFNAS
-bash: cd: smbFNAS: No such file or directory
maybe the raspbian translation into german is the source of that question because I have to translate it back. No such file or directory would mean in german "keine solche Datei oder Verzeichnis", but it was completly different
JimmyN wrote:And even if the mount had failed the /media/smbFNAS/ mount directory would be there, so you'd be able to "cd" to it, even though it's empty.
Yeah, that was the normal behaviour before I did these fstab and rc.local things.
JimmyN wrote:Do you have a mount directory at "/media/smbFNAS"?
That is what I want to and therefore I had created that smbFNAS directory.
JimmyN wrote:What do you get with a "ls -l /media"
pi@Raspi2HBB:~ $ ls -l /media
insgesamt 8
drwxr-xr-x 2 pi pi 4096 Mär 26 20:13 HDD1
drwxr-x---+ 2 root root 4096 Mär 20 17:51 pi
drwxr-xr-x 2 root root 0 Jan 1 1970 smbFNAS
JimmyN wrote:What is the exact mount command you're using that works (edit any passwords).

That one mentioned above and its parameters are identical to that of the mount command.
sudo mount -t cifs -o user=xxx,password=yyy //192.168.178.1/fritz.nas/ST310005-28AS-01 /media/smbFNAS
JimmyN wrote:After it's mounted manually what do you get with a "mount" command, and a "ls -l /media" command.
The same as mentioned above. But if I go into that smbFNAS directory I can see all the NAS files & directories. So it can mount, but only manually.

But this mount command only works if I do NOT have that "systemd.automount" line in my fstab (//192.123.123.1/share /media/smbFNAS cifs username=ftpuser,password=123,uid=pi,gid=pi,x-systemd.automount 0 0)

With that line in the fstab I even can not manually mount with the mount command because I would get an english error message (maybe not yet translated because normally I get german errors).

My raspbian installation was done around mid of march with only a few things added like ntfs support, samba, hp cups, MidnightCommander, a backup script and all the updates & upgrades and extended partition (from 4 to the whole 8 GB of that SANDISK SD Card)

thx
WOLF

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

Re: mount network share on boot

Wed Mar 30, 2016 11:18 am

You're right, the different error message is probably a translation thing.

If you can mount it manually, then you can mount it with fstab. The only difference is timing, fstab runs during boot, where mounting it manually would be done after it's finished booting. The x-systemd.automount hands the mount to systemd which will wait to mount the drive until it's first accessed, so you're assured everything is up and running at that point.

If you're mounting it manually using "sudo mount -t cifs -o user=xxx,password=yyy //192.168.178.1/fritz.nas/ST310005-28AS-01 /media/smbFNAS" then don't use the systemd.automount.

Let's check some things.
Use this in fstab

Code: Select all

//192.168.178.1/fritz.nas/ST310005-28AS-01 /media/smbFNAS cifs user=xxx,password=yyy,uid=pi,gid=pi,x-systemd.automount 0 0
Reboot and check dmesg to see what systemd has to say.

Code: Select all

dmesg | grep mount
This pi is mounting three network shares, yours may read a little different due to translation, but you can see that systemd has set up all the automounts.

Code: Select all

 dmesg | grep mount
[    3.866626] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (nul                                                                   l)
[    3.932557] devtmpfs: mounted
[    5.564148] systemd[1]: Starting home-jimmy-Win7\x2dFolder.automount.
[    5.622608] systemd[1]: Set up automount home-jimmy-Win7\x2dFolder.automount.
[    5.644737] systemd[1]: Starting home-jimmy-NAS.automount.
[    5.670071] systemd[1]: Set up automount home-jimmy-NAS.automount.
[    5.689924] systemd[1]: Starting home-jimmy-Network\x2dfolder.automount.
[    5.718175] systemd[1]: Set up automount home-jimmy-Network\x2dfolder.automount.
[    5.741117] systemd[1]: Starting Arbitrary Executable File Formats File System Automou                                                                   nt Point.
[    5.773394] systemd[1]: Set up automount Arbitrary Executable File Formats File System                                                                    Automount Point.
Now try a "df -h" command to see it the mount is listed. If it's not then try using a "sudo mount -a" command, and then another "df -h" to see if that mounted it.

typxxi
Posts: 44
Joined: Sat Mar 05, 2016 6:11 pm
Location: GERMANY

Re: mount network share on boot

Wed Mar 30, 2016 6:16 pm

Hey Jimmy,
now everything works and I found the source of this misery.

But step by step: Here are my results after I appended the line in fstab you recommended.

Code: Select all

pi@Raspi2HBB:~ $ dmesg | grep mount
[    2.115018] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    2.138444] devtmpfs: mounted
[    3.671675] systemd[1]: Starting media-smbFNAS.automount.
[    3.702997] systemd[1]: Set up automount media-smbFNAS.automount.
[    3.739522] systemd[1]: Starting Arbitrary Executable File Formats File System Automount Point.
[    3.759152] systemd[1]: Set up automount Arbitrary Executable File Formats File System Automount Point.
[    6.076840] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   10.747545] CIFS VFS: cifs_mount failed w/return code = -101
[   10.839224] CIFS VFS: cifs_mount failed w/return code = -101
2nd step

Code: Select all

pi@Raspi2HBB:~ $ df -h
Dateisystem                                Größe Benutzt Verf. Verw% Eingehängt auf
/dev/root                                   7,2G    4,8G  2,1G   70% /
devtmpfs                                    412M       0  412M    0% /dev
tmpfs                                       416M       0  416M    0% /dev/shm
tmpfs                                       416M    6,0M  410M    2% /run
tmpfs                                       5,0M    4,0K  5,0M    1% /run/lock
tmpfs                                       416M       0  416M    0% /sys/fs/cgroup
//192.168.178.1/fritz.nas/ST310005-28AS-01  2,0T     84G  1,9T    5% /media/smbFNAS
/dev/mmcblk0p1                               60M     20M   41M   34% /boot
tmpfs                                        84M       0   84M    0% /run/user/1000
3rd step

Code: Select all

pi@Raspi2HBB:~ $ sudo mount -a
mount error(16): Device or resource busy
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

Code: Select all

pi@Raspi2HBB:~ $ df -h
Dateisystem                                Größe Benutzt Verf. Verw% Eingehängt auf
/dev/root                                   7,2G    4,8G  2,1G   70% /
devtmpfs                                    412M       0  412M    0% /dev
tmpfs                                       416M       0  416M    0% /dev/shm
tmpfs                                       416M    6,0M  410M    2% /run
tmpfs                                       5,0M    4,0K  5,0M    1% /run/lock
tmpfs                                       416M       0  416M    0% /sys/fs/cgroup
//192.168.178.1/fritz.nas/ST310005-28AS-01  2,0T     84G  1,9T    5% /media/smbFNAS
/dev/mmcblk0p1                               60M     20M   41M   34% /boot
tmpfs                                        84M       0   84M    0% /run/user/1000
I must admit that I first did all what you asked for and copied it - without thinking.

Later I looked into the results and recogniced that the NAS HDD must have been connected because the data regarding that NAS HDD were right!

Then I did a reboot and everything was there where it should be.

But to be honest: I really do not know, what the trick was to make it happen.
Therefore I will remove all the other things which might have been changed and are no longer needed like that rc.local stuff.

Meanwhile I removed the rc.local stuff and it still works.

I asked myself what went wrong and it could be that all my problems were the result of a tiny difference: a result of a copy and paste action from another web page I assume

And you also used the fstab commandline in 2 different syntax
username=123
user=123

Username does not work - at least in fstab, but user does work.

That I found out when I checked my "Ras Pi Master Setup Recipe" from where the hell I got all these problems because at the beginning of easter saturday everything worked fine until I came across this site while I was trying to establish a guest / user share mode. It was late a night when my pi suddenly did not reboot and the next morning I had forgotten what I had exactly changed at last, the changes of my previously working "mount line" in fstab were gone because I forget to use # and deleted that line that had been working before:

https://rasspberrypi.wordpress.com/2012 ... pberry-pi/

There you will find these lines:

2.1 Guest Share
sudo mount -t cifs -o guest //WindowsPC/share1 /mnt/mountfoldername
Tip: If your share has space then run the following command, notice the quotes
sudo mount -t cifs -o guest "//WindowsPC/Share 1" /mnt/mountfoldername

2.2 Password Protected Share
sudo mount -t cifs -o username=yourusername,password=yourpassword //WindowsPC/share1 /mnt/mountfoldername
And I can tell you that you can kill your Ras Pi Installation if fstab content is wrong. At least 3 or 4 times I had to reinstall the whole thing ... and reboot .

Many, many thanks for your constant support the last few days. :D
WOLF

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

Re: mount network share on boot

Wed Mar 30, 2016 7:47 pm

You're welcome, glad you got it working. Copy/Paste will mess you up sometimes. You grab an extra quote mark or space, or leave a bit behind when you copy, and it's usually those kind of little things that hang you up and are hard to find.

I think I got the "user" from the line you posted, since I didn't know if your HDD setup needed "username" or "user" to log in. I did add "uid" and "gid" to the line so the mounted files would belong to "pi".

The errors you see in dmesg (they also show up on the boot screen and syslog)

Code: Select all

[   10.747545] CIFS VFS: cifs_mount failed w/return code = -101
[   10.839224] CIFS VFS: cifs_mount failed w/return code = -101
are from fstab trying to mount the share during boot, even though systemd will be mounting it later. You can suppress those errors by adding ",noauto" in front of the ",x-systemd.automount". With "noauto" fstab won't try to mount it when booting, so you won't get the error messages, but it also prevents you from mounting it from the commandline using "sudo mount -a" since you've disabled the auto mount function.

voyager529
Posts: 1
Joined: Thu Mar 08, 2018 7:07 pm

Re: mount network share on boot

Thu Mar 08, 2018 7:17 pm

Hey everyone!

Sorry-not-sorry for resurrecting an old thread. I'm trying to do this same thing, and I'm almost there.

I have a folder share on my DD-WRT router I want my RasPi to be able to utilize. Here is the relevant code in my /etc/fstab:

Code: Select all

//192.168.2.1/media  /media/media       cifs username=[snip],password=[snip],nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=1  0
When I use my Windows laptop on the share, everything looks and works exactly the way it's supposed to. When I use the Pi, I can see it, and I can read from it. However, when I do things like "ls >/media/media/testfile.txt", it will create a zero-byte file, but can't write actual data to it. Furthermore, I can delete files from those shares, which I would assume requires write access.

Now, my gut feeling is that this is a permissions issue. Well, DD-WRT has the share set to read/write, and I set the chmod on the folders to 777, and again, Windows works fine. I know this is more of a general Linux question, but I appreciate whatever assistance can be provided.

Thank you!

User avatar
DougieLawson
Posts: 36312
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: mount network share on boot

Fri Mar 09, 2018 12:57 pm

Change

Code: Select all

username=[snip],password=[snip],
to

Code: Select all

credentials=/root/.cifsuser,
Create a /root/.cifsuser file with

Code: Select all

username=[[snip]]
password=[[snip]]
With the password enclosed in brackets. That's more secure, you can use sudo chmod 600 /root/.cifsuser to protect your secrets.

Also add

Code: Select all

uid=pi,group=pi
to your mount options string as that means the share will be owned by the pi user and not by root. That gives pi complete control over the share (based on what your .cifsuser credentials allow).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

kent.lucas.11
Posts: 1
Joined: Fri Jul 13, 2018 3:21 am

Re: mount network share on boot

Fri Jul 13, 2018 3:32 am

I'm still having issues with this and I followed the instructions above adequately, I believe. I may be missing something.

This is my line in my fstab:

Code: Select all

//10.1.2.1/USB_Storage /mnt/lucas cifs username=xxx,password=yyy,uid=pi,gid=pi,x-systemd.automount 0 0
And below is the result of a dmesg | grep mount.

Code: Select all

pi@raspberrypi:/mnt/lucas $ dmesg | grep mount
[    1.010774] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    1.020683] devtmpfs: mounted
[    2.177955] systemd[1]: Set up automount mnt-lucas.automount.
[    2.898760] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[  214.027164] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) speci                                                fy vers=1.0 on mount.
[  215.085099] No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1). To use the less secure SMB1 dialect to access old servers which do not support SMB3 (or SMB2.1) speci                                                 fy vers=1.0 on mount.
When I manually mount the share, it works fine. When I run sudo mount -a after rebooting, it also mounts fine, but does give me the error message below.

Code: Select all

pi@raspberrypi:~ $ sudo mount -a
mount error(16): Device or resource busy
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Anything I'm missing? Like I said, it will mount fine when I do a sudo mount -a, so the line in fstab must be right. Thank you for your time.

stefano.ferroni
Posts: 1
Joined: Wed Dec 26, 2018 9:50 pm

Re: mount network share on boot

Wed Dec 26, 2018 10:21 pm

Well Lucas, I hope you have solved your problem by now.
Anyway:
1. the "dialect" line can be avoided by specifying a newer version (I put vers=3.0 in the options)
2. the "device or resource busy" are probably due to the gid=pid, uid=pi options. You don't need to get rid of them.
3. everything has started to work fine when I have set the Raspberry to wait for network on boot.

Return to “Troubleshooting”