[Guide] Auto-Mounting Filesystems in Linux

2023.02.26

I came across this post yesterday morning and attempted to implement as I’ve recently (the past week) been having issues with not being able to see newly added files through my fstab nfs mount, even though the files are there on the server. My fstab mount has worked fine for a few years now, with the only thing changing recently is about 1.5 months ago I moved my lab to a different room.

I’ve been off Windows for about 3 years and home labbing for about the same 3 years. I would still consider my Linux knowledge to be very beginner level. Resolving the issues I had with autofs would probably take others much less time. I spent a couple hours between last night and this morning to get it working.

I had quite a few roadblocks, so I’m going to post what worked for me. Perhaps it will help someone else.

Mounting the NFS share from a Proxmox 7.3-6 vm running Ubuntu server version:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

Exporting the NFS mount from a Proxmox 7.3-6 vm (different node than the Ubuntu server) running openmediavault v6.3.2-1:

Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

Screenshot_20230226_095734


I followed the original post in this thread to the letter and received the following error.

user@server:~$ ls -l /mnt/nfs/media
ls: cannot access 'media': No such file or directory
total 0
d????????? ? ? ? ?            ? media

So I searched Google for a while (lots of wasted time on stack answers and forum posts) and finally came across the Ubuntu wiki entry for autofs (primary sources aren’t my go-to, as it seems they usually assume a higher working knowledge than I have), specifically this portion, as the first part had been covered here.

My /etc/auto.master file ended up the same as posted here. With only the following line appended to the end of it.

/mnt/nfs /etc/auto.nfsdb

My /etc/auto.nfsdb file ended up like this:

media -fstype=nfs4,rw 10.0.0.2:/media
media1 -fstype=nfs4,rw 10.0.0.20:/media1

Per this post “autofs is finicky about executable bits” so I removed everything else. I also switched to nfs4.

Now this still didn’t quite work for me. Somewhere along the way (don’t remember exactly), I discovered the /etc/autofs.conf file. In this file I made the following changes:

Note: I don’t want a timeout, these machines run 24/7. The reason I’m switching to autofs is to hopefully fix whatever is causing the Ubuntu server to not see new files on the NFS mount.

(If any of these are commented out, uncomment)
line 15 timeout = 0
line 54 browse_mode = yes
line 65 mount_nfs_default_protocol = 4


And now it works as expected.

user@server:~$ df -hT
Filesystem             Type   Size  Used Avail Use% Mounted on
10.0.0.2:/media        nfs4    37T   35T  1.7T  96% /mnt/nfs/media
10.0.0.20:/media1      nfs4    29T  1.0M   29T   1% /mnt/nfs/media1

user@server:~$ mount | grep nfs
10.0.0.2:/media on /mnt/nfs/media type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.30,local_lock=none,addr=10.0.0.2)
10.0.0.20:/media1 on /mnt/nfs/media1 type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.30,local_lock=none,addr=10.0.0.20)

It’s still quite possible I flubbed the instructions in this guide. But autofs is working for me with these adjustments.

Thank you to OP for the guide.

It’s been years since I first found and referenced this guide, and I still pull it up every time. Thanks again.

1 Like

I also have to throw in this since I was using this to setup my new (to me) prebuilt: make sure to

sudo apt install cifs-utils

on top of the directions from here and OP regarding mounting Samba shares. I was ripping out my hair to figure out why me shares were not mounting correctly….until I did some Google work and found out I was missing out a dependency. Now it works out fine.

I want to say thank you to OP for posting this, super helpful!

I just want to add this to in the mix SMB Stale File Handle, Unraid
As I was double checking the SMB shares via AnyDesk, I realized only ONE folder gets unmounted, which is weird cause I have 4 total mounts using AutoFS. A restart fixes it, but he problem rears its ugly head after a couple of days. After adding the mounting flag noserverino did this behavior stop appearing (so far, it’s been 4 days).
This might only apply to UnRaid, or even samba shares in general, but I wanted to note it down here since I was wondering what was causing the Stale File Handle error.

Probably because the OP specifically chose to use NFS rather than Samba.

I followed OP’s post #75, but either way now it works

Just rebuilt my linux box and wanted to report that this worked like a charm. Thank you!

Running into a weird issue. The mount starts up perfectly on a reboot, but Plex for some reason doesn’t have access to the mounted folder. It can see the top level, but is unable to access the folder at all. If I then restart the plex docker container, everything works. It seems to be a permission issue maybe related to a timing thing…any idea here?

I’m facing a little bit of an issue I can’t seem to figure out.

Here is my auto.nfsdb file:

Here you can see there is a folder in in the Sports share (all other mounts seem to work because I can see subfolders and files from the terminal):

However Plex doesn’t seem to be able to find this subfolder (or any other subfolder within one of the mounts):

Here is my docker-compose file:

Any idea what I’m doing incorrectly?

1 Like

For anyone having a 3 minute or so delay when restarting/shutting down the quicksync machine the below helped me. This stops autofs prior to reboot/shutdown.

sudo nano /lib/systemd/system/autofs.service

add the below under [Service]

ExecStop=umount -a -f -t nfs

Should look like this:

[Unit]
Description=Automounts filesystems on demand
After=network.target ypbind.service sssd.service network-online.target remote-fs.target
Wants=network-online.target nfs-client.target
Documentation=man:autofs(8)

[Service]
Type=forking
PIDFile=/run/autofs.pid
EnvironmentFile=-/etc/default/autofs
ExecStart=/usr/sbin/automount $OPTIONS --pid-file /var/run/autofs.pid
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=umount -t nfs -af
TimeoutSec=180

[Install]
WantedBy=multi-user.target

1 Like

Created an account just to say thank you! I followed several guides using etc/fstab and kept running into issues. This guide worked like a charm!

Is anyone else’s Plex server not mounting NFS shares after the latest UNRAID 7.1.3 update? Working again after I downgraded to 7.1.2