[Guide] Auto-Mounting Filesystems in Linux

If you’re like me and use NFS to share files between multiple servers, you may occasionally run into a connection issue when you reboot - if the client comes up before the server, it won’t mount the NFS filesystems automatically. If you’re around, you can just remount them manually, but if it happens when you’re away you could be out of luck. One way to make sure this doesn’t happen is to use autofs for your NFS mounts. It’s super easy to set up, and once it’s configured the filesystems will mount and remount automatically whenever they are accessed, as long as the remote system is available.

Before we begin, I should note that autofs will NOT fix stale file handle errors. That’s a separate issue that is usually caused by hard links on union filesystems. If you get these stale file errors in unraid, you should disable hard links. You can find this setting under Settings > Global Shares Settings. Look for Tunable (support Hard Links): and set it to No. Once you’ve made this change, reboot both your unraid system and your ubuntu system and you should be back in business.

  • If you haven’t already done so, make sure you disable automatic emptying of the trash in Plex. Go to Settings > Library, and uncheck the option Empty trash automatically after every scan, then scroll down and save your changes. This will prevent Plex from deleting any custom posters or metadata you may have in the event that something goes wrong and Plex can’t find your files.
0. Install autofs
  • Open a terminal and run the following command to install autofs:

    sudo apt install -y autofs
    • Enter your password if prompted. You will see a bunch of scrolling text, and you may see a warning saying start and stop actions are no longer supported, which is fine. In the end, you should see a couple lines starting with Processing triggers for.... If you see a warning other than the start/stop warning, or you don’t see the processing triggers lines, take a screenshot of the output and post here or in the tech-support channel on Discord before proceeding.
1. Configure autofs
  • You need to edit a couple of configuration files using your favorite text editor. I recommend using nano if you’re new to linux, so these steps will use nano.

    • First, you need to edit the auto.master file.

      • Enter sudo nano /etc/auto.master. Once nano opens, use the Page Down or arrow keys on your keyboard to scroll to the bottom. Then, add the following text below the last line in the file:
      /mnt/nfs /etc/auto.nfsdb --timeout=0 --browse
      • Adjust the folder (/mnt/nfs) to point to the parent folder where you want your NFS shares to mount. In my example, I entered /mnt/nfs so my NFS volumes will mount inside that, like /mnt/nfs/tv or /mnt/nfs/movies. Please note, that you won’t be able to create any folders inside of this folder on your own, so you need to use a dedicated sub-folder like /mnt/nfs instead of just using the /mnt folder.

      • If you want the filesystem to unmount when it’s not used for a while, you can set the timeout to a value greater than zero, in which case it will auto unmount if there has been no activity for that many seconds. Leaving the timeout at zero disables the automatic unmount.

      • Save the file. In nano, press Ctrl+O (Letter O), and then press Enter to save. Then, press Ctrl+X to close nano

    • Next, you need to create the file /etc/auto.nfsdb.

      • Run sudo nano /etc/auto.nfsdb

        • You should get a blank nano screen where you can just start entering text. This file is where you are going to enter all of the different NFS mounts.

        • For each mount, you will need to add a line similar to the following:

        tv -fstype=nfs,ro,timeo=100,noatime
        • There are a couple things you’ll need to adjust here. The first parameter tv is the name of the folder to create on your local system. This folder will be created inside the parent folder you defined above. So, in my example, the tv folder will be mounted inside the /mnt/nfs folder I entered in step 1.

        • The parameters in the middle should be left alone

        • The last parameter ( is the IP and folder of the remote NFS filesystem. Adjust it as necessary, following the pattern <ip_address>:<folder/to/folder> (note the colon separating IP and folder is required). NOTE - folder names in linux are case-sensitive, so make sure you enter the name correctly. TV is not the same as tv, nor is Movies the same as movies. I recommend using all lower-case letters for your share names, but if you’ve already been using upper-case, it can work as long as you match the case exactly.

        • Add additional lines for every NFS folder you want auto-mounted. Once you’ve added all the folders, save the file and close nano.

2. Disable and remove the previous mounts
  • Now that the auto-mounting is configured, you’ll need to disable the standard mounting of the folders in fstab, if you are re-using the folders for the autofs mounts.

    • First, stop any running programs that are accessing files inside these folders. Most likely it will just be Plex. Run sudo systemctl stop plexmediaserver to close it.

    • Next, unmount the folders. Run sudo umount /mnt/tv (replacing tv with whatever your folder name is), and repeat this for every other folder you have mounted.

      • If you get an error when you try unmounting any folder, verify that all the programs that were accessing it have been closed. If you’re not sure what’s accessing the folder, enter sudo lsof | grep /folder/name to see a list of any processes that have open files in that folder.
    • Next, comment out the lines you added to fstab for the folders.

      • Run sudo nano /etc/fstab and scroll down to the lines you added
      • Add a # symbol in front of each line that you added
      • Save the file and exit nano
3. Restart the autofs service
  • Now that the folders are unmounted and the configuration files have been updated, you need to restart the autofs service so it will read the new configuration. Run the following command to start the service:

    sudo systemctl restart autofs.service
  • Next, verify the service started correctly by running:

    systemctl status autofs.service
    • It will show a few lines of text, and as long as the Active: line shows active (running) then you can continue. If it shows inactive or anything else, double-check the auto.master and auto.nfsdb files to verify that they don’t contain any spelling errors in the lines you added.
  • Change to one of the folders you want mounted and make sure you can see files in the folder. Run ls /mnt/nfs/tv for my example. This may take a few seconds to load the first time, but as long as it shows your files, then you’re nearly done. If it doesn’t show anything, double-check the configuration files above to make sure the folders and parameters were all spelled correctly, then restart the autofs service again and repeat this step.

3.5 Special Note for Plex Libraries
  • If you already have your Plex libraries configured with your old folders from the fstab file, you will need to do one of two things:
    1. Edit your libraries in Plex for the new folders (follow these same steps for every library you have)
      • Add the new folders where your media is located. DO NOT delete the old folder from the library yet.
      • Rescan the library if it doesn’t start scanning automatically.
      • Once finished scanning, edit the library again and remove the old folder.
      • Empty the Plex trash to remove the entries from the old folder
    2. Create a symbolic link pointing the old folder to the new folder (follow these steps for every library you have)
      • In the terminal, enter the following command ln -s /<new_media_folder> /<old_media_folder>
        • For example, if my old folder was /mnt/tv and my new folder is /mnt/nfs/tv I would type ln -s /mnt/nfs/tv /mnt/tv
4. Reboot and verify your work
  • As long as you’ve made it this far, everything should work smoothly on subsequent reboots. While not technically required, I would recommend rebooting the system and checking that the folder mounted properly after the reboot.

Just went through this guide successfully and there are two things I want to emphasize:

  1. It is critical that what ever path you put in /etc/auto.master for the parent folder ends in a / is it does not this will not work.
  2. It is critical that if you are currently using an fstab set up that you unmount them per the instructions otherwise they will still be running on fstab even if you reboot.
  3. It is critical that if you are currently using an fstab set up that you use a different folder inside of /mnt to do your new mounts

These things are more or less stated above but I wanted to be double sure everyone avoids my trials and tribulations

Here’s what I’m getting on step zero:

All of those operations succeeded properly. It looks like you had the support libraries installed already, so it just had to install autofs itself. You’re good to proceed with step 1.

1 Like

Thank you. I followed your “Migrating Plex Metadata from Unraid to Ubuntu” guide, so are there any tweaks I need to make from the guide above?

I have my stuff in “/mnt/user/media” in Unraid and mounted as “/media” in Ubuntu for Plex.

If you migrated your metadata, you’re going to need to do a couple extra steps. Autofs needs exclusive access to whatever root folder you point it at. This is fine if you’re pointing it at a subfolder, like the /mnt/nfs folder I use above, but that won’t work if Plex is expecting the media to be in folders directly under the root folder /. The good news is there’s an easy workaround in symbolic links. Follow the guide above as normal, throwing your autofs mounts in /mnt/nfs or whatever subfolder you want under /mnt. Test the mounts to make sure they work, and then, before you reboot, perform the following step for each path you added to autofs:

sudo ln -s /mnt/nfs/tv /tv (Substitute your paths as necessary)

Check that they work by typing ls /tv and verify that your TV folders are listed properly. After you reboot, run the same command again as a final check.

having a new issue and need a hand from the masters… i set this up last year and all was working perfectly until maybe a month ago.

i have sonarr/radarr/lidarr on my anniversary build server, and plex on a separate box running ubuntu, as desrcibed by jdm in the transcode post. shares are mounted within ubuntu as per this thread. all was working perfectly but the other week i noticed that the TV episodes stopped pulling into plex automatically. only the tv shows. movies and music worked fine. but on reboot, tv shows would import correctly into plex.

sonarr is working perfectly fine, as is plex – i’ve posting about them in their respective forums and the logs look good. i’ve traced the problem (i think) to the automounting file system.

This is weird: tv shows stream fine and I’m able to view them without any issue at all. But when I check all the shares in /mnt on ubuntu, the /tv share isn’t there! But then I run an ls /mnt command and all three media directories are present but the /tv share is either missing or i cannot cd /mnt/tv into it.

Looks like when I reboot /mnt/tv is there and an ls command works fine. But after a while I lose it.

No clue how or why this is happening, since all 3 directories are located Within the same unraid share and they’re all streaming fine.

any thoughts?

i’ve retraced all my steps using this post and checked that all settings in fstab and autofs are correct, which they are. any help would be greatly appreciated.

I haven’t experience your issue, so I don’t have a quick answer for you, but I do have a couple suggestions. First, disable the automatic library scan in Plex, and configure Sonarr, Radarr and Lidarr to use Plex Connect to notify Plex when new media is added. To enable Plex Connect, follow these steps in Sonarr, Radarr and Lidarr:

  1. Go to Settings > Connect, and click the add button.
  2. Select Plex Media Server from the available options.
  3. Enter a name for your server at the top
  4. Enter the IP or hostname for your Plex server in the hostname field. Leave all other settings at their defaults.
  5. Click the Authenticate with Plex.tv button and log in to your Plex account.
  6. Click the Test button
  7. If the test was successful, save the connection.

After you’ve enabled the connections, go into your Plex server settings, and disable the options to Scan my library automatically and Run a partial scan when changes are detected. You can leave the periodic scan enabled, and set it to run daily.

Run your system like this for a few days and see if the issue comes up again. If it does, then I’d recommend enabling debug logging for autofs temporarily so the logs can hopefully be used to pinpoint the issue. To enable logging, open the file /etc/autofs.conf in your text editor, scroll down until you see # logging = none, and change it to logging = debug. Save the file, then restart the autofs daemon sudo systemctl restart autofs. Once debug logging is enabled, everything autofs does will be logged in /var/log/syslog, hopefully including whatever is causing the issue. If it comes to this point, please note that the syslog file isn’t used exclusively by autofs, so the relevant information may be scattered among log lines from other programs. I wouldn’t recommend posting the log file anywhere without filtering it first to display only the automount logs.

thanks mthrboard! will make those changes and report back!

If you are like me and named your unraid Share “TV Shows” you will need to take an extra step in your auto fs command. that hinders you from automounting it.

Replace tv with below:
“TV\ Shows”

I have migrated successfully to autofs on my system. Interestingly enough, I originally wanted to do this because I was getting “stale file handle” when using fstab. Unfortunately, I am still having the same issue.

In checking the logs, I see the following entries repeatedly:

Apr 9 12:49:51 dionysus kernel: [684639.585302] fsid 0:73: expected fileid 0x901000025857ba7, got 0x27000011a31bce
Apr 9 12:49:51 dionysus kernel: [684639.585797] NFS: server error: fileid changed
Apr 9 12:49:51 dionysus kernel: [684639.585797] fsid 0:73: expected fileid 0x901000025857ba7, got 0x27000011a31bce

I currently trying to figure this out but wondering if this has to do with using cache and then moving to the array? Does anyone have any experience with this?

If you run into stale stale file handlers or similar things, read up on the unraid forums about this hot mess.

The TL;DR; fix: Settings > Global Shares Settings: Shut down array, switch Tunables Hard Links to No.

I’m testing a resolution which is to disable Hard Links on NFS Shares in Unraid 6.8. In the next minor release, there is a slight promise of seeing Hard Links per NFS share.


Thanks very much for this guide! Working great, just have 1 issue which I am hoping you can point me in the right direction for -
Any advice on what would be the best way to set permissions to allow the default ‘plex’ user to be able to delete files through the Plex UI?

Right now when I try to do this I get a permissions error (400) from the logs.
“Jun 28, 2020 14:23:40.641 [0x7f9920cfb700] DEBUG - Completed: [] 400 DELETE /library/metadata/6473?includeExternalMedia=1 (13 live) TLS GZIP 14ms 463 bytes (pipelined: 13)”

I did a test of trying to change one of the lines in /etc/auto.nfsdb from -fstype=nfs,ro to -fstype=nfs,rw but that didnt seem to work.
Then I added the ‘plex’ user to the group ‘users’ because I see that group has full permissions to all of my folders in /mnt/nfs but not down to the file level which is what I need it seems.

I know that I need to give addtional permissions to the plex user but just not sure of the best/cleanest/easiest way to do it.

What are you using for NAS? I would think the permissions would be controlled there, not on the Plex side.

1 Like

I am able to mount my NFS shares via the autofs guide you have kindly posted. I am however having issues when trying to mount a second drive that is on my network. This one is a mergerfs mount so i believe this should be mounted with the “fuse” para.

this is what i am trying,

mergerfs -fstype=fuse,ro,timeo=100,noatime :

We were just talking about this in the Discord. You have to add a _netdev parameter to your fstab

thank you for the link,

So i should now revert back to connecting my drives with fstab and not use autofs?

Wrong issue, Keep calm and configure on.

For those who use PlexDVR, you should change “ro” to “rw”

1 Like

What’s the significance of the prerequisite (disable automatic trash emptying in Plex)? I’m not using any custom posters or metadata so will I be okay to keep automatic emptying enabled?