Daddyfix
Posts: 52
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

How to Install Autofs for NFS connections

Wed Jun 06, 2018 3:10 am

I spent a few days figuring out how to properly install autofs, and automount system on Raspberry Pi 3 Jessie. Hope this helps someone else

Install

First thing to do is install the automount package

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install autofs

Check Files in Package

When I installed autofs on RPi 3 Jessie only two files were installed. If you notice that automount was not installed then you have to get the .deb files from debian and install manually

Code: Select all

$ dpkg-query -L autofs
/.
/etc
/etc/init.d
/etc/init.d/autofs
Notice automount was not installed? now we are going to install it manually


Get Raspian Version

Code: Select all

$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Get Architecture

Code: Select all

dpkg --print-architecture
armhf

Download correct version & architecture

Download .deb and install based on your Raspian above
https://packages.debian.org/search?keywords=autofs

Code: Select all

$ cd /tmp
$ wget "wget http://ftp.ca.debian.org/debian/pool/main/a/autofs/autofs_5.0.8-2+deb8u1_armhf.deb"

Remove Old autofs and install autofs_5.0.8-2+deb8u1_armhf.deb

Code: Select all

$ sudo apt-get update
$ sudo apt-get remove autofs --purge
$ sudo dpkg -i autofs_5.0.8-2+deb8u1_armhf.deb

Check for automount files

Code: Select all

$ dpkg-query -L autofs
/.
/etc
/etc/init.d
/etc/init.d/autofs
/usr
/usr/lib
/usr/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf/autofs
...
/usr/sbin
/usr/sbin/automount
...
/usr/lib/arm-linux-gnueabihf/autofs/mount_nfs4.so
Notice automount was installed with autofs package


Configure


Make mount point directories /mnt/nfs/

Code: Select all

$ mkdir -p /mnt/nfs/mycloud
$ mkdir -p /mnt/nfs/mobilesvr

Edit /etc/auto.master and add a autofs file

Code: Select all

/mnt/nfs/mycloud        /etc/mycloud.nfs    uid=501,gid=1000 --timeout=6000 --ghost
/mnt/nfs/mobilesvr      /etc/mobilesvr.nfs  uid=0,gid=0      --timeout=6000 --ghost
uid and gid are user and group id's on the nfs servers.


Edit /etc/mycloud.nfs and add mount points
The following is a NFS filetype connection.

Code: Select all

storage     -fstype=nfs,rw,hard,nolock,noauto,x-systemd.automount   192.168.1.100:/nfs/Storage

Restart Service

Code: Select all

$ systemctl restart autofs.service

Test

Code: Select all

$ l /mnt/nfs/mycloud
file1.txt
file2.jpg
If the folder is not empty then you are succesfull.


Check Mounts

Code: Select all

$ mount | grep mycloud
/etc/mycloud.nfs on /mnt/nfs/mycloud type autofs (rw,relatime,fd=-1,pgrp=816,timeout=6000,minproto=5,maxproto=5,indirect)
/etc/mycloud.nfs on /mnt/nfs/mycloud type autofs (rw,relatime,fd=7,pgrp=13541,timeout=6000,minproto=5,maxproto=5,indirect)

epoch1970
Posts: 4789
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: How to Install Autofs for NFS connections

Wed Jun 06, 2018 9:12 am

Or simply do "apt-get install autofs5".
Automount is a bit of an admin thing, AFAIK it never was installed by default on Debian, and Raspbian follows suit.

Also, systemd now (from Jessie? in Stretch for sure) packs an automount service of its own. For simple jobs (there is nothing like maps, indirect or executable mounts in systemd's automount) you can do without installing autofs5.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Daddyfix
Posts: 52
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

Re: How to Install Autofs for NFS connections

Wed Jun 06, 2018 12:29 pm

@epoch1970

Geeesh did I ever waste a couple days! :(

Anyhow, thanks for the info on autofs5, and automount in systemd.

I guess I should asked someone here instead of going crazy! :D

Daddyfix
Posts: 52
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

Re: How to Install Autofs for NFS connections

Wed Jun 06, 2018 6:41 pm


mingenlee
Posts: 2
Joined: Wed Feb 26, 2020 12:23 am

Re: How to Install Autofs for NFS connections

Wed Feb 26, 2020 12:30 am

Is this method still work on Buster? I tried on Buster but it doesn't work anymore.

Daddyfix
Posts: 52
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

Re: How to Install Autofs for NFS connections

Wed Feb 26, 2020 1:18 pm

On Buster I use systemd automount NFS

Installation

Code: Select all

sudo apt-get install rpcbind nfs-common
Important

Automount units must be named after the automount directories they control.
Example: the automount point /home/lennart must be configured in a unit file home-lennart.mount.

On My RPi

Code: Select all

mkdir /nfs/nas
Use the following to find the NFS mounts from you NFS Server IP

Code: Select all

$ showmount -e 192.168.1.?
Export list for 192.168.1.?:
/nfs/RemoteNFSDirName 192.168.1.0/24
Setup auto mount Systemd file

/etc/systemd/system/nfs-nas-DIRNAME.mount

Code: Select all

[Unit]
Description=NFS Directory

[Mount]
What=192.168.1.?:/nfs/RemoteNFSDirName
Where=/nfs/nas/DIRNAME
Type=nfs
Options=rw,hard,intr,x-systemd.automount

[Install]
WantedBy=multi-user.target
Enable in Systemd

Code: Select all

$ systemctl enable nfs-nas-DIRNAME.mount
$ systemctl daemon-reload
$ systemctl start nfs-nas-DIRNAME.mount
$ systemctl status nfs-nas-DIRNAME.mount
Hope this helps you. It took many attempts to make it work for me. :)

sora03
Posts: 259
Joined: Mon Dec 29, 2014 4:11 pm
Location: Philippines
Contact: Website YouTube

Re: How to Install Autofs for NFS connections

Wed Feb 26, 2020 2:26 pm

You can also use /etc/fstab to mount NFS directories. (after you've installed nfs-common)

Code: Select all

172.16.1.1:/home/pi/Public  /media/user/Public  nfs noatime,nodiratime,rw,nocto,noacl 0 0
To mount manually:

Code: Select all

$ sudo mount -a
To setup Pi as the NFS server, install nfs-kernel-server
In your NFS server (Pi) to add directory, just edit /etc/exports:

Code: Select all

/home/pi/Public       172.16.1.0/24(ro,sync,no_subtree_check)
Mastodon: https://mastodon.social/@ssora

mingenlee
Posts: 2
Joined: Wed Feb 26, 2020 12:23 am

Re: How to Install Autofs for NFS connections

Thu Feb 27, 2020 7:39 pm

mingenlee wrote:
Wed Feb 26, 2020 12:30 am
Is this method still work on Buster? I tried on Buster but it doesn't work anymore.
I found out why it doesn't work for my Buster because the file /etc/autofs.pi redirected by /etc/auto.master has executable bit turn on. Automount thinks it's a shell script file instead of a configured file. Once I use command sudo chmod u-x /etc/autofs.pi then everything works fine. I found out this information from a posted from 2005 which means its a known feature. https://lists.fedoraproject.org/piperma ... 28314.html

Daddyfix
Posts: 52
Joined: Sun Dec 09, 2012 2:13 pm
Location: Sudbury, Ontario

Re: How to Install Autofs for NFS connections

Thu Feb 27, 2020 11:55 pm

mingenlee wrote:
Thu Feb 27, 2020 7:39 pm
mingenlee wrote:
Wed Feb 26, 2020 12:30 am
Is this method still work on Buster? I tried on Buster but it doesn't work anymore.
I found out why it doesn't work for my Buster because the file /etc/autofs.pi redirected by /etc/auto.master has executable bit turn on. Automount thinks it's a shell script file instead of a configured file. Once I use command sudo chmod u-x /etc/autofs.pi then everything works fine. I found out this information from a posted from 2005 which means its a known feature. https://lists.fedoraproject.org/piperma ... 28314.html
I'm a little confused...
Is the /etc/autofs.pi file a custom script that you wrote? I don't use auto.master cause it's the old way and didn't work very well for me if the remote NFS server was off or not running.
I found automount with systemd worked best.

I'm really curious about what is in your autofs.pi. could you post it?

Return to “Advanced users”