Mounting SMB shares automatically in Fedora 40 using AutoFS
Introduction
Mounting SMB network shares in a portable Linux system is apparently not easy. The major problem is that mountpoints become unresponsive when the network gets disconnected. This causes the file manager to freeze, if it has a mounted directory open. AutoFS does not solve this problem completely, but at least it automatically unmounts shares after a while, and can remount them when the network connection is restored.
Installation
Open a terminal and enter a root shell:
sudo -iInstall autofs:
dnf install autofsEdit the /etc/auto.master file to add the following line:
/mnt/<name> /etc/auto.<name> --timeout 60 --browseThis means any shares defined in /etc/auto.<name> will be automatically mounted as subdirectories inside /mnt/<name>. They will also automatically be unmounted when unused for 60 seconds.
Now create and edit the /etc/auto.<name> file, to add shares:
<dir> -fstype=cifs,uid=1000,username=<username>,password=<password> ://<server>/<share>
<dir2> -fstype=cifs,uid=1000,username=<username>,password=<password> ://<server>/<share2>As this file contains credentials, you should make sure it is not world-readable:
chmod 600 /etc/auto.<name>Test your configuration by lanching automount in foreground mode:
automount -fvIf it all works exit automount and enable and start the systemd unit:
systemctl enable --now autofs