Return to

Having issues automounting samba share

I have a linux box that is running manjaro and I set up manjaro and it works as a server/test machine for my linux endeavors. I have a gaming machine that runs windows but trying to determine the best possible solution to move to linux full time, and a laptop that has manjaro as well for practicing networking stuff. I setup an automount in fstab on the laptop that is supposed to automount the samba share but get a failed automount. I setup the credentials from what I read was best practices. I made a file with a period “.crendentialsfile” and put the username and password for accessing samba and placed it in the /etc/samba/credentials/ directory. Changed it to root ownership I believe and gave it rw but later changed it to just read permissions.
I can automount the directory by $sudo mount -a and that works fine. I am not sure what I need to do or change as it seems like I had correctly setup the fstab line with the correct information but it won’t automount.

I’ve run into this as well. It’s because the wireless networking doesn’t initialize until after the auto mount fails, which results in the mount failing. I’m on the road right now but I can provide you with the mount options I use to have the auto mount wait until networking is active before it attempts to mount. You can attempt to search this but the fstab option you’ll find as a result doesn’t actually work. It’s something else that took me some time to find. Also of note is that even with my solution it still sometimes fails to mount all my shares correctly. I believe this happens when I have an application that attempts to use a share before it has been auto mounted which results in that one specific share not mounting. ‘Sudo mount -a’ will also fail, but if I type ‘sudo mount/mnt /media’ it will restore that share.

I’d love to hear from someone who has a better understanding of how all this works as to why this is still such an issue in -current year-

So if you use systemd this is mostly handled for you. You don’t provide a lot of detail. I’ll share one of my NFS automount fstab lines:              /home/zlynx/catbox      nfs  defaults,proto=tcp6,x-systemd.automount,noauto 0 0

You can see I have automount and noauto set so it will wait until it is accessed by something.

You can find a whole list of fstab options that systemd will interpret in man systemd.mount and search for fstab. There’s an FSTAB section.

Unless your systemd has been messed up seriously by the distro, or you’ve been hacking on it yourself, it should automatically detect a netdev FS type and order it before the which in turn should rely on


Thanks for the input and I appreciate it.

Sorry, I was typing this from my main PC that is a windows machine.
I added this to the /etc/fstab file
//server/directory /mnt/location cifs _netdev,nofail,credentials=/etc/samba/credentials/.crednetialsfile,iocharset=utf8 0 0

I believe I go that information from the manjaro Wiki site and from another forum somewhere. It works fine when I do $ sudo mount -a but it will not automount.
I have been trying to learn linux over the course of a year (covid free time after work hours to keep myself busy and learn new stuff that I enjoy). I have used linux a little before but never really used it too much besides just installing it on an old computer and playing around with it.
The reason I had to automount is because SMPlayer will not play movies from opening a directory and typing \IPaddress to access the samba share and opening a movie or tv show in that manor. VLC will work but for some reason I read in other forums that SMPlayer requires the share to be mounted and it does work when mounted. I like VLC, coming from windows, but it performs horribly in Linux when it sometimes freezes or won’t close and have to look up how to kill the proccess in terminal.

I have not really tried to do setup a systemd service yet as I am still working on other linux aspects but maybe I should try with the proper guidance.

Thank you for your time and assistance.

Check the logs to see if there is an error. Typically, it’s /var/log/messages.

Search for server your trying to mount in the syslog and post output here.

I’m knew with trying to figure out journalctl and reading logs. It is something I really want to get better at as I am hoping I can get into an IT job and move my way up into sysadmin work or something similar in the future.
From doing a journalctl -b | grep mount (I’m not sure if that is right but that’s kind of what I found as a quick way to see what happened during boot from a quick search).

I got a few errors.
mount error (101): Network is unreachable.
Then refer to mount.cifs(8) manual page.
mnt-smbshare.mount: Mount process exited, code=exited, status 32/n/a
mnt-smbshare.mount: Failed with result ‘exit-code’
Failed to mount /mnt/smbshare
Attempting to mount //‘username’/‘Directory’
CIFS: no dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later. To use less the less secure SMB1 dialect to access old servers which do not support SMB3.1.1, specify vers=1.0 on mount.
CIFS: VFS: cifs_mount failed w/return code = -101

It is best to use the journal’s included search features. You could do journalctl -b -g mount and it will grep for you.

That seems to be pretty obviously the major problem. I don’t believe that you have this set to automount. It is probably trying to mount on boot.

When I do the same journalctl command on my machine I get this:

Set up automount home-zlynx-catbox.automount.

And then later:

home-zlynx-catbox.automount: Got automount request for /home/zlynx/catbox, triggered by 2852 (pool)

Which is where it actually mounts.

You shouldn’t need _netdev as it should figure that out from cifs. Also nothing there made it automount. You need to add x-systemd.automount and noauto

Thank you, will try and see what happens. I got that info from the manjaro wiki and some forum posts that others had done when I ran into some problems. Will see what happens and reports. Thank you again.

Unfortunately that does not seem to work. The manjaro wiki has the following as what is supposed to work:
// SERVER / sharename /mnt/ mountpoint cifs _netdev,nofail,username= myuser ,password= mypass 0 0

The username and password can be altered to have a credential file that is protected.
I will probably have to look at a tutorial to use systemd and try that out to get the automount to work. I am a little frustrated and not really sure how to proceed.
Thanks for you help though, I appreciate your insight and feedback.

Ok I’m home now. Here is what an entry in my fstab on my laptop uses, and it works fairly well:

//xx.xx.xx.xx/media /mnt/media cifs credentials=/etc/cifsauth,file_mode=0777,dir_mode=0777,noauto,x-systemd.automount,x-systemd.device-timeout=3,_netdev 0 0

Just install autofs and smbclient. In /etc/auto.master add an entry
/- auto.smbmedia

(Notice the space after -)

Edit the /etc/auto.smbmedia file (it doesn’t exist at first) and add
/mnt/media -fstype=cifs,uid=1000,gid=1000,credentials=/home/uruser/.credentialsfile ://server/sharename

UID and GID are usually 1000 for the first user. Check to see if you have 1000 by looking into /etc/passwd at the line with your username. Server can be either a DNS record or IP. /home/uruser/.credentialsfile should have:
chmod 600 /home/uruser/.credentialsfile

Inside the file, you should have:

Sorry for the messy format, I’m phoneposting :face_vomiting: If I were home or had access to any of my devices, I’d give you my script which auto-creates the /etc/auto.smbmedia file and automatically adds all smb shares in /mnt.

He’s using a systemd distro. Do NOT install autofs.


Care explaining why? Other than the stupid systems timeout when rebooting / shutting down, what’s wrong with it? Worked perfectly fine on Fedora 31 through 34, CentOS and Oracle Linux 7 and 8, Ubuntu 18.04 and 20.04 and on Arch. It worked on other non-systemd and pre-systemd OS as well.


Because someone who is learning how to use auto mounting does not need to learn the configuration details of old technology that isn’t used much anymore.

The autofs system starts multiple new daemons which have no reason to exist when the system is already managing it.

Someone who gets confused may try to list a filesystem in both fstab and auto.master. It is now a race condition as to what happens.

I used to use autofs too. Ten years ago. Just drop it.


Now that you’ve made the change that @zlynx mentioned, does the command @zlynx suggested with journalctl still display the same messages or are there new ones? Please report.

1 Like

I just remembered this post. Here’s the script if anyone wants it. Requires autofs, cifs-utils and smbclient installed. Works on Ubuntu 16.04+, Fedora 31+, CentOS 7+, Debian 9+. It also worked on Void Linux when I tested it long ago, just modify “systemctl” with “sv” are it’s good to go. It should also work on other distros and it’s simple enough that you can hack the heck out of it. Tested with bash, dash and oksh. Should work with other shells.

Originally this was used in a business environment, whenever I gave Linux users access to a new samba share, instead of me manually remoting and editing /etc/auto.customsmb file to add the new mounts, or worse, let them edit and break it, I would make them run this script whenever they got rights on a new share, or for the most Linux newbies, I’d ssh and run it myself. The script was slightly edited to allow user input of the domain name or IP of the samba server, it had it hard-coded (since we only had 1 server and I wanted to make it simple to run for most people). Remember to make the file executable by runing chmod u+x on it.

[ -z $1 ] && echo "please add samba's domain name or IP like so: \"./ nas-name.local\"" && exit 1
VARUID=$(grep $VARUSER /etc/passwd | cut -d ':' -f3)
VARGID=$(grep $VARUSER /etc/passwd | cut -d ':' -f4)
VARTMPCFG=$(mktemp /tmp/autofstmpconf.XXXXX)

chmod 644 ${VARTMPCFG}

for VARFLD in $(smbclient -A /home/${VARUSER}/.smb.credentials -gL ${VARREMOTESMB} | grep Disk | cut -d '|' -f2) ; do
    echo /mnt/remote/${VARFLD} -fstype=cifs,uid=${VARUID},gid=${VARGID},credentials=/home/${VARUSER}/.smb.credentials,rw ://${VARREMOTESMB}/${VARFLD} >> ${VARTMPCFG}
    [ ! -d /mnt/remote/${VARFLD} ] && sudo mkdir -p /mnt/remote/${VARFLD}
sudo /bin/sh -c '[ -f /etc/auto.smbmedia ] && rm -f /etc/auto.smbmedia & mv ${VARTMPCFG} /etc/auto.smbmedia && chown root:root /etc/auto.smbmedia && systemctl restart autofs'

As mentioned above, add this line in /etc/auto.master before the +auto.master line:
/- auto.smbmedia

And the /home/$(whoami)/.smb.credentials file should look like so:

Run the script and it should auto configure autofs for your samba share. I strongly believe it should go without saying, but just to avoid any copyright questions (I don’t believe in that nonsense), the above code is licensed under

The MIT License

Copyright © 2021 Biky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


I use Samba only on Windows nowadays. I prefer sshfs for Linux, since I can just use my ssh key to authenticate and I don’t percieve any noticable speed difference. And I don’t like auto-mountings shared folders, I just keep a few scripts that I use to mount my samba location and my phone running PrimitiveFTPd and otherwise manually mount other locations as needed. But autofs comes in really handy when you don’t want 24/7 mounted remote folders, but want the ease of use of auto-mounting locations on-demand.

1 Like