AutoFS Setup an FStab Alternative

While setting up my media server stack I chose to separate my Media Service from my media storage and ran into issues where my NFS drives would lose their mount and be unable to reseat them without some kind of intervention. To resolve this problem I switched to using AutoFS.

With AutoFS, we can mount network drives (via NFS) to look like local drives, and have them auto reconnect on disconnect.

Alternatively you could chose to mount drives permanently by adding them to your FStab file. However, using the AutoFS utility is both a better and more reliable way of mounting drives.

Specifically AutoFS is a utility that mounts local or remote drives only when accessed. If the drive is not needed it will not be mounted and if you don’t use them it will be unmounted automatically and remounted when called. You can, optionally, keep the drives always mounted after first access.

Note: This guide assumes a fresh install of Ubuntu Linux with no previous FSTAB mappings to the mount points being addressed. If you have previously set these up in FSATB you will need to comment out the competing entries in /etc/fstab


Things to know about AutoFS

  1. In utilizing it you are mapping mount points (MP) with files (called an indirect map), a mount point with a location, or a device.
  2. In default configuration, it begins by reading maps defined in autofs.master located in the /etc directory. After which, it will opens a path for all MPs defined by the map files identified in the master file. Configuration parameters for AutoFS are located at
/etc/autofs.conf
  1. However, opening a path thread does not mean the MP is mounted immediately when starting AutoFS. This only occurs when the MP is accessed.
  2. Note you will not be able to create any folders inside the MP landing point so you will be directed to utilize a dedicated subfolder like /mnt/qs as opposed to allowing your MP to land inside of /mnt.
  3. Lastly, by default after five minutes of inactivity, the service will actively dismount MPs not actively being used. For my Media Service use case I prefer to set --timeout=0 which keeps my MPs from closing. However, if you prefer that an MP dismount after a period of inactivity you can set a timeout to a value greater than zero. This value is based in seconds.

Now that we know a little more about how this works let us install this service. To do so you will require sudo privileges on your host. Let set it for the entirety of this session using the following command:

$ sudo -i

Next we need to install the AutoFS utility on Linux. On install the AutoFS package will:

  • Create several configuration files in /etc including : auto.master, auto.net, auto.misc, etc.;
  • Create the AutoFS service in systemd;
  • Create the “automount” entry in the nsswitch.conf file and link to the “files” source
  1. Make sure your packages are up to date
$ apt-get update
  1. Now install AutoFS
$ apt-get install autofs
  1. Enable the AutoFS service to run at startup
$ systemctl enable autofs
  1. Let us ensure that everything happened as expected
$ systemctl status autofs

Next we will need to edit the auto.master file

At this point we will be accomplishing two things. First, we will be overriding the time out settings that control how long out inactive MPs will be allowed to persist. Second, we will be adjusting the landing point for our mounts to /mnt/qs

  1. To edit the file
nano /etc/auto.master
  1. Add the following line to the bottom of this file
/mnt/qs /etc/auto.nfsdb --timeout=0
  1. Save and Close by pressing Ctrl+X and Y then Enter to confirm

Next we will create our /etc/auto.nfsdb that will define our MP mappings.

  • You will need to create a line item entry for each mount being defined.
  1. Create the file. This command will open a blank file where you will map your mounts from the source system
nano /etc/auto.nfsdb
  1. Add a new line item for each mapping
  • Example: photo -fstype=nfs,ro,timeo=100,noatime 192.168.1.104:/mnt/user/photo
    • Let us breakdown each segment
      <Mount-Point> <Mount-Options> <Location_of_File System>
    • photo – This is the name I am giving the share on my local system
    • -fstype=nfs – defines the mapping as nfs
    • ro – Read Only
    • Timeo=100 – the time in deciseconds (tenths of a second) the NFS client waits for a response before it retries an NFS request
    • noatime – eliminates the need by the system to make writes for files which are simply being read. Since writes can be expensive.
    • 192.168.1.104:/mnt/user/photo<ip_address>:<path/to/folder> – is the discrete path to the source drive we are mounting
  1. Save and Close by pressing Ctrl+X and Y then Enter to confirm

Wrapping up

  1. Let us now restart the service and verify that everything is running
  • First run
systemctl restart autofs.service
  • Then run
systemctl status autofs.service
  • Looking for:
  1. Let us navigate to one of our new mappings to verify its working
ls /mnt/qs/photo
  1. Lastly Reboot and then verify for good measure
shutdown -r 0

Unraid Considerations

Stale File Handlers

Based on this recent posting in the UnRaid forums : NFS IS ABOUT USELESS IN UNRAID 6.8.0 you may begin to experience issues with stale file handlers.

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

Credit to @eph for sharing this info. Hoping to see it corrected in the next minor update of Unraid.

Let’s continue the discussion HERE.