Odd Issue With Samba Cifs Auto-Mount

Hello, I hope everyone’s having a good weekend.

I have a rather odd issue with my SMB share that’s hosted off of a computer in my living room (running latest Mint currently). I’ve attempted to add the Samba share to the fstab entry on my Manjaro laptop as follows:

//192.168.x.xxx/SambaShare /run/media/user/SambaShare cifs credentials=/path/user/.userCredentials,uid=user,iocharset=utf8 0 0

When I either boot up or boot down the machine, I get a message in my terminal after the X session closes that there was a “Failure to mount /run/media/userSambaShare” and that a “Dependency fail for remote file system”.

What’s odd though is that as soon as I’m booted into the system, if I just run sudo mount -a, it mounts the drive without any complaints, and I have proper read and write access.

Here is the drive configuration on smb.conf on the Mint/Samba host machine:

[SambaShare] 
  path = /media/user/SambaShare 
  writeable = yes
  read only = no 
  guest ok = yes  
  create mode = 0777 
  directory mode = 0777
  valid user = @user @sambashare

Please let me know if there are any other outputs, information, or configurations you would like to see - I was unsure what else would be useful for this.

Do not use this folder. It should only be used for automatic temporary mounts done by programs like your file manager. Also the /run/media/$user folder is not available at startup. It is dynamically created after you log in.

Use a mount point in /media/ or a similar folder, but not in /run

Thank you, I attempted to create a mount point both in /mnt/Media as well as /media/user/Media to point the fstab mount to that folder, but the same error persists. I also attempted editing fstab to include username= and password= instead of using the credentials file, but that did not have an impact either.

‘sudo amount -a’ still works if I run it in terminal right after I log in, and is now mounting to /media/user/Media. I don’t know what fstab is trying to do on boot that isn’t jiving with the way this is set up.

You should add the _netdev Option. Also are you connected via a Ethernet Cable or via WiFi. If you use WiFi make sure it connects before you log in. Also make sure your network-online.target works correctly (Is started by an appropriate service).

I’m using Wifi, and also have VPN set on startup (however I’ve already attempted completely disabling all VPN killswitches/startup services, etc, which didn’t have an impact).

I attempted to add the _netdev option to fstab (to confirm, is it correct syntax to add it like this?):

//192.168.x.xxx/Media   /media/user/Media     cifs    _netdev,credentials=/path/user/.smbcreds,uid=user,iocharset=utf8 0 0

I also may be somewhat unclear on what you’re meaning by the network-online.target reference, but I checked for the service status as follows:

systemctl is-enabled NetworkManager-wait-online.service systemd-networkd-wait-online.service
enabled
disabled

So far no change on behavior. I’m not sure if you think I should alter something with the networking services (or I guess how to do it). I agree with you that based on the behavior, it seems like cifs is trying to mount the network drive before the network is actually up.

Thank you for helping me look into this.

looks good.

That is often a problem. In NM, make sure you store your Wifi password unencrypted (for all users). Otherwise you need to login before your Keyring is open and the password can be used.

Check the status

systemctl status network-online.target

It should show if it is active and since when. The time can be compared to the failed mount.


Sometimes it is easier to cerate a mount unit and don’t use the fstab at all. With a mount unit, you can use the automount feature. And even if you don’t want to use the automount, you can easily delay the mount with a mount unit a few seconds, so it always works.

If you connect your system to different Wifis, a NM dispatcher Script can also help you, to only try to mount if you conned to your Home network.

1 Like

Thank you, this took me a little bit to figure out as it’s my first time mounting drives in this fashion. It does seem to work appropriately now, I get no errors on boot up or shutdown, but it does seem that mounting the drive in this manner adds quite a lot of time to boot up. I’m not sure why it’s slower than the fstab method, but oh well.

For future reference if anyone has similar issues and reads this in the future, these links were also useful to me and include more examples and info on systemd unit mounting:

(I cannot post URLs, please search Github for Akiross post on " Automount of CIFS (smbfs) folders w/ systemd")

Another blog post is located on michlstechblog under the title " Systemd: (Auto-) Mount cifs shares"

And this is what my /etc/systemd/system mount and automount files looked like at the end:

/etc/systemd/system/media-user-Media.mount:

[Unit]
Description=remote smb mount

[Mount]
What=//192.168.x.xxx/Media
Where=/media/user/Media
Type=cifs
Options=credentials=/path/user/.smbcreds,uid=user,iocharset=utf8

[Install]
WantedBy=multi-user.target

/etc/systemd/system/media-user-Media.automount:

[Unit]
Description=Automount media share via SMB

[Automount]
Where=/media/user/Media

[Install]
WantedBy=multi-user.target

Thank you Xabbu very much for your help and pointing me in the right direction.

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