Linux mounting cifs share (NAS drive) upon startup

Thread Starter

zazas321

Joined Nov 29, 2015
668
Hello. I am trying to mount a NAS drive that is connected to the local network. I can mount it manually using sudo mount -t command but that is not good since I need the drive to automatically mount when raspberry PI is powered.

I have read this article:

https://help.ubuntu.com/community/MountWindowsSharesPermanently

and I have modified my /etc/fstab
Code:
proc            /proc           proc    defaults          0       0
PARTUUID=645ce3d5-01  /boot           vfat    defaults          0       2
PARTUUID=645ce3d5-02  /               ext4    defaults,noatime  0       1
//192.168.50.230/share_name /nfs/temp-share cifs username=name,password=pass,iocharset=utf8 0 0
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
I have tried to reboot the raspberry PI a few times but it does not sucessfully mount the share after the startup.

However, when I type sudo mount -a, it mounts and I can see all my files in /nfs/temp-share folder.Shouldnt the mount -a be called after the startup??

Could the problem be that in order to connect to network drive I need to be connected to wifi (I use wifi instead of ethernet cable). and since the WIFI takes some time to connect, the fstab mount happens before the wifi manages to connect to the local network therefore failing to mount the network drive? Is that a possibility? If so, what are the options to solve this
 

nsaspook

Joined Aug 27, 2009
7,587
No I havent yet but that could not be an issue since I can mount the network drive using sudo mount -a which manually remounts the drives on etc/fstab.
Maybe it's a network sequence issue.
Try adding _netdev to your fstab entry so it will delay until networking is up. username=user,password=pass,_netdev,...

or a automount with systemd
https://wiki.archlinux.org/index.php/Fstab
Remote filesystem
The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.mount-timeout= option to specify how long systemd should wait for the mount command to finish. Also, the _netdev option ensures systemd understands that the mount is network dependent and order it after the network is online.
$ sudo systemctl daemon-reload
$ sudo systemctl restart remote-fs.target
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Okay things I have tried so far but with no luck. It is clearly a timing issue since mounting happens during boot, network is not ready yet.

1. Added _netdev option to my fstab as suggested above

Result: Still not mounted

2. Added a command to /etc/rc.local :
Code:
sudo mount -t cifs //192.168.50.230/Share_name -o username=user,password=pass,vers=3.0 /nfs/temp-share

Result: Still not mounted

Checked using dmesg | grep mount and I can see that the system is attempting to mount cifs drive and fails returning error code = -2

3. Added "sleep 10" option to /etc/rc.local before sudo mount as following to add delay as following
[code]
sleep 10
sudo mount -t cifs //192.168.50.230/Share_name -o username=user,password=pass,vers=3.0 /nfs/temp-share
Result: I can see that the has been delayed, still returns the same error code = -2
Why calling this function manually in terminal mounts the drive but not working in rc.local??


Another really strange thing is that even sometimes when I succesfully mount the drive using
Code:
sudo mount -a
or
sudo mount -t cifs //192.168.50.230/Share_name -o username=user,password=pass,vers=3.0 /nfs/temp-share
I can see that the drive has been mounted ( 4GB of space allocated on /nfs/temp-share folder but the folder contents is empty??? When i right click -> Properties, I can see that there are 4 files inside but I cannot see them. Can someone explain what is going on?

2020-09-09-091117_1920x1080_scrot.png



And when I close, reopen the folder /nfs/temp-share multiple times(10-20 times), eventually the folders show up just out of nowhere???2020-09-09-092101_1920x1080_scrot.png
 
Last edited:

nsaspook

Joined Aug 27, 2009
7,587
Strange. I'm mounting a NAS remote drive here using the fstab file. My init system is old school sysvinit instead of systemd because I hate systemd.

Zyxel Personal Cloud Storage Server [4-Bay] with Remote Access and Media Streaming [NAS540]

FSTAB line:
//208.51.108.251/admin /impnas2 cifs rw,user=xxxx,pass=xxxx 0 0


df:
//208.51.108.251/admin 476656472 289436 476367036 1% /impnas2
 

djsfantasi

Joined Apr 11, 2010
6,795
Does the CIFS have permissions for a user named “user” and whose password is “pass”? Or did you redact the username and password for your post?

At this point, when you can see the drive but not it’s contents, it looks like a permissions or security error.
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Okay I have managed to get it to mount upon startup. I have done :

Preferences -> Raspberry PI configuration and tick Wait for Network
2020-09-10-093311_1920x1080_scrot.png
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Actually, there is one more small problem. I am not able to put any files to the drive that I have mounted because I am getting "permission denied" problem. I can copy/delete and view all the files if I connect to the NAS drive manually by typing in the IP address to the browser.

I am unsure whether that is supposed to be that way, but the only way I can copy or delete anything from that drive is by using sudo commands on terminal as following:

2020-09-11-073446_1920x1080_scrot.png
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Your /nfs/temp-share directory on the RPI is owned by root 'rwx' and is r-x for group and others as 755. As a test you can: chmod 777 /nfs/temp-share
to open full permissions to all to see if that works. If it does then you can change the group from root to something in common with regular users while restricting others.

https://www.tutorialspoint.com/unix/unix-file-permission.htm
Thanks for your reply again. I have tried creating a new user and giving it onwership for the /nfs/temp-share folder. Unfortunately, the onwership of the /nfs/temp-share did not change ( still remains root root ) despite me using :
Code:
sudo chown lukas /ntc/temp-share
I have found a similar article:
https://askubuntu.com/questions/350580/root-owns-home-directory-chown-does-not-work

Perhaps only way to do that is to modify fstab
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Also, I do not really understand why would user root not be able to write anything to that folder since it has rwx permissions?
rwx should mean that i am able to read/write/execute
UPDATE:
Does "root" owner means superuser? I mean if I use sudo commands that will execute commands as a root right? If so, I am starting to understand how it works.

Anyway, since I mainly use user "pi" would it make most sense to change the ownership of /nfs/temp-share to pi user and give permissions to write?
 
Last edited:

nsaspook

Joined Aug 27, 2009
7,587
'root' is GOD unless you have SELINUX enabled and in enforcing mode.

https://en.wikipedia.org/wiki/Security-Enhanced_Linux
A Linux kernel integrating SELinux enforces mandatory access control policies that confine user programs and system services, as well as access to files and network resources. Limiting privilege to the minimum required to work reduces or eliminates the ability of these programs and daemons to cause harm if faulty or compromised (for example via buffer overflows or misconfigurations). This confinement mechanism operates independently of the traditional Linux (discretionary) access control mechanisms. It has no concept of a "root" superuser, and does not share the well-known shortcomings of the traditional Linux security mechanisms, such as a dependence on setuid/setgid binaries.
 

Thread Starter

zazas321

Joined Nov 29, 2015
668
Understood. So would changing ownership to user "Pi" and giving that user write privilleges is an okay solution for that task? Or that is generaly considered not safe ?
 
Top