Mounting samba shares on boot fails half the time

I recently switched to Manjaro after using Mint for the last couple of years. My fstab contains the same lines for mounting samba shares which worked just fine on Mint, but now fails about half the time on Manjaro. When it fails, I can run “sudo mount -a” after logging in, and it works just fine.
Looking at dmesg, it looks like the problem is that the network is not available when the mounts occur.
My computers are connected via ethernet, so there shouldn’t be any connectivity issues.

Success:

[    7.095407] r8169 0000:04:00.0 enp4s0: Link is Up - 1Gbps/Full - flow control rx/tx
[    7.095425] IPv6: ADDRCONF(NETDEV_CHANGE): enp4s0: link becomes ready
...
[    7.183167] CIFS: Attempting to mount //192.168.1.175/media
[    7.183190] CIFS: Attempting to mount //192.168.1.170/homes
[    7.183210] CIFS: Attempting to mount //192.168.1.170/media
[    7.183245] CIFS: Attempting to mount //192.168.1.175/homes
[    7.183515] CIFS: Attempting to mount //192.168.1.170/files

Failure:

[    3.377637] CIFS: Attempting to mount //192.168.1.170/media
[    3.377666] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.377669] CIFS: VFS: cifs_mount failed w/return code = -101
[    3.377775] CIFS: Attempting to mount //192.168.1.175/media
[    3.377804] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.377805] CIFS: VFS: cifs_mount failed w/return code = -101
[    3.377837] CIFS: Attempting to mount //192.168.1.170/files
[    3.377859] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.377861] CIFS: VFS: cifs_mount failed w/return code = -101
[    3.378032] CIFS: Attempting to mount //192.168.1.170/homes
[    3.378048] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.378050] CIFS: VFS: cifs_mount failed w/return code = -101
[    3.378157] CIFS: Attempting to mount //192.168.1.175/homes
[    3.378173] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.378174] CIFS: VFS: cifs_mount failed w/return code = -101
...
[    6.894855] r8169 0000:04:00.0 enp4s0: Link is Up - 1Gbps/Full - flow control rx/tx
[    6.894861] IPv6: ADDRCONF(NETDEV_CHANGE): enp4s0: link becomes ready

From my fstab:

//192.168.1.170/homes /mnt/samba/server1_homes cifs credentials=/home/myuser/myuser.cred,_netdev,vers=2.0,uid=myuser 0 0
//192.168.1.170/media /mnt/samba/server1_media cifs credentials=/home/myuser/myuser.cred,_netdev,vers=2.0,uid=myuser 0 0
//192.168.1.170/files /mnt/samba/server1_files cifs credentials=/home/myuser/myuser.cred,_netdev,vers=2.0,uid=myuser 0 0
//192.168.1.175/media /mnt/samba/server2_media cifs credentials=/home/myuser/myuser.cred,_netdev,vers=2.0,uid=myuser 0 0
//192.168.1.175/homes /mnt/samba/server2_homes cifs credentials=/home/myuser/myuser.cred,_netdev,vers=2.0,uid=myuser 0 0

How can I prevent this from happening? Any help is greatly appreciated.

Try adding the nofail mount option.
I needed to add this for an internal drive a bit too slow to mount at startup, yet it is correctly mounted every time the session is open. :man_shrugging:

1 Like

Also take a look here, there might be something that helps: [root tip] Use systemd to mount ANY device

1 Like

Your issue is due to the fact that no network connection is available when your fstab is parsed.

systemd parses you fstab and convert the entries to native mount units.

Therefore it makes sense - at least to me - to define my mounts using mount units instead of fstab.

mount and automount units carries - when mounting network shares - conditions to be present - e.g. network is up and running.

2 Likes

You can try this

sudo systemctl enable NetworkManager-wait-online.service

If that doesn’t do the trick try adding this to the end of your fstab option list for every share:
x-systemd.after=network-online.target

After saving execute this terminal command:

sudo systemctl enable systemd-networkd-wait-online

Although it might be the best option to use @linux-aarhus method, i use this at home and works great. i use nfs though.

1 Like

This works fine with my Manjaro in a Microsoft network. Manjaro load Windows shares on boot. Maybe it helps you.

noauto,x-systemd.automount,cache=none,rsize=130048,wsize=57344,_netdev,user,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,credentials=/home/User/logins/login-pc.cred 0 0

Thanks for all the tips. I created mount units as suggested by @linux-aarhus and @Mirdarthos, and it worked the first two times I restarted the system, but failed on the third. Looking at the boot log, the same thing happened as before.

[    3.458132] CIFS: Attempting to mount //192.168.1.170/files
[    3.458161] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.458163] CIFS: VFS: cifs_mount failed w/return code = -101
[    3.458229] CIFS: Attempting to mount //192.168.1.170/homes
[    3.458253] CIFS: VFS: Error connecting to socket. Aborting operation.
[    3.458254] CIFS: VFS: cifs_mount failed w/return code = -101
...
[    7.374430] r8169 0000:04:00.0 enp4s0: Link is Up - 1Gbps/Full - flow control rx/tx
[    7.374437] IPv6: ADDRCONF(NETDEV_CHANGE): enp4s0: link becomes ready

My unit files look like this:

[Unit]
Description=Server1 Homes
After=network-online.target
Wants=network-online.target

[Mount]
What=//192.168.1.170/homes
Where=/mnt/samba/server1_homes
Type=cifs
Options=credentials=/home/myuser/myuser.cred,rw,_netdev,vers=2.0
TimeoutSec=30

[Install]
WantedBy=remote-fs.target
WantedBy=multi-user.target

I also have a permissions problem since I only get read access when the mounts work, but I can probably solve that later.

When your mount includes removable devices such as network shares you need to use both a mount unit and an automount unit.

When you create units from scratch without an existing path - starting the .mount unit once and stopping it will create the folder structure.

Only the automount unit can be enabled and started so if you fail to disable and stop the .mount unit - the .automount unit will fail.

Step 1. Disable and stop your mount unit

sudo systemctl disable --now mnt-samba-server1_homes.mount

Stop 2. Based on the referenced mount unit - you create a corresponding automount unit using the same name - with the extension of .automount

/etc/systemd/system/mnt-samba-server1_homes.automount
[Unit]
Description=Automount Server1 Homes
ConditionPathExists=/mnt/samba/server1_homes

[Automount]
Where=/mnt/samba/server1_homes
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

Then enable and start the automount

sudo systemctl enable --now mnt-samba-server1_homes.automount

The share is only mounted when you access the share path and it is done so completely transparent even if it is from the terminal

cd /mnt/samba/server1_homes

Your permission issue is most likely because the client filesystem’s permission on server1_homes is read-only. A samba share mountpoint does not inherit the shares permissions - so even if the user connecting has read-write on the share itself the write will fail if the local mountpoint is read-only.

You need to ensure your client’s mountpoint is read-write - at least by o but you could use g as well

sudo chmod o+w /mnt/samba/server1_homes

Thanks for all the help. It looks like it’s working now.
Initially the mounts would fail just like previously, and I got these types of messages:

[    2.065292] systemd[1]: local-fs.target: Found ordering cycle on mnt-samba-server1_homes.automount/start
[    2.065295] systemd[1]: local-fs.target: Found dependency on network-online.target/start
[    2.065296] systemd[1]: local-fs.target: Found dependency on NetworkManager-wait-online.service/start
[    2.065297] systemd[1]: local-fs.target: Found dependency on NetworkManager.service/start
[    2.065299] systemd[1]: local-fs.target: Found dependency on dbus.socket/start
[    2.065300] systemd[1]: local-fs.target: Found dependency on sysinit.target/start
[    2.065302] systemd[1]: local-fs.target: Found dependency on systemd-journal-catalog-update.service/start
[    2.065303] systemd[1]: local-fs.target: Found dependency on local-fs.target/start
[    2.065305] systemd[1]: local-fs.target: Job mnt-samba-server1_homes.automount/start deleted to break ordering cycle starting with local-fs.target/start

But after some searching, I found that adding DefaultDependencies=no to the unit files solved the problem.

Also, I had to add file_mode=0777 and dir_mode=0777 to the options in the mount units to get the correct permissions.

I will do some more testing before I mark this as solved.

It is probably related to this - which I now realize only is relevant if it is a local partition - I think it can be safely removed. I will check with my working units.

I confused myself - it is the ‘local-fs.target’ messages - I don’t recall those messages in my log - but I have heard about it before

I think this has something to do with the credentials file being in the user’s home.

The difference to my system is I have the credentials in the mount unit.

Ok, I will try to play around with it and see what works. Thanks again.

One other thing - did you comment the lines in your fstab?

mount units and fstab cannot coexist - I just got the thought and it could be what local-fs is referring to.

Yes, I did.

When you get messages like the ones you get - it is not errors - it is messages - reordering loading sequence due to dependencies - network must be up.

But you clearly have a problem somewhere - a problem I don’t have although I have two smb mounts.

I have not paid enough attention to the logs as my system always worked - but I checked I had a few messages - and I can see where it lies - modify to look like below - I have forgotten to update the topic - so your topic made me revisit the guide and update accordingly

. mount unit

[Unit]
Description=Server1 Homes

[Mount]
What=//192.168.1.170/homes
Where=/mnt/samba/server1_homes
Type=cifs
Options=credentials=/home/myuser/myuser.cred,rw,_netdev,vers=2.0
TimeoutSec=30

[Install]
WantedBy=multi-user.target

.automount unit

[Unit]
Description=Automount Server1 Homes
ConditionPathExists=/mnt/samba/server1_homes

[Automount]
Where=/mnt/samba/server1_homes
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

Thank you for making me revisit this.

Note:

I have been deep diving into these messages and I found somthing on the Arch bugtracker.

This references this issue

It appears that the network-onlilne-target is creating a cyclic dependency.

I will comment whether this helps - when I have checked my system.

After reading comments on github and experimenting the _netdev option will force the unit into the right ordering cycle - no requires or after is needed when it is a _netdev.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.