Solved autofs for NFS mounts - looking for help and example configurations

Hi, I just had a look at the new automounter autofs(5) that is now in FreeBSD 10.2 and am trying to find out the best way to set it up to mount NFS shares locally upon access.

At present I have in /etc/fstab something along the lines of 172.1.1.1:/share /mnt nfs ro,noauto with the noauto option enabled because I don't want the shares to mount at boot. I would like for the shares to become accessible once users access them.

I have enabled amd_enable="YES" in rc.conf. It seems that I also have to list explicitly the shares that I would like to mount also in the auto_master.

Does anyone have any examples of how they have set this up for themselves?
 
  • Thanks
Reactions: Oko
It's autofs(5) as the service now; amd(8) is the legacy automount daemon. That means it's sysrc autofs_enable=YES to enable and not sysrc amd_enable=YES.

Here's an example to remotely mount user home directories where several users on the system have their home directory pointed to /zfs/homedirs.
/etc/auto_homedirs
Code:
*  -intr,nfsv4  192.168.1.100:/zfs/homedirs/&
/etc/auto_master
Code:
/zfs/homedirs  auto_homedirs

See auto_master(5) for more examples and guidance and take notes of the "maps" that you can do like the example above.
 
  • Thanks
Reactions: Oko
Ok, please bear with me, I want to get this right and fully understand what is happening. I think I have understood.
Code:
autofs_enable=YES
I have placed in rc.conf

I want one directory from another machine which is mounted in fstab as
Code:
172.1.1.1:/share /mnt nfs ro,noauto
on a local machine. So I have placed the following in /etc/auto_master:
Code:
/mnt2  172.1.1.1:/share
However when cd'ing into that directory, there is a brief pause, but it does not list the files in that share.

I have also tried:
Code:
/mnt2 -nfs  172.1.1.1:/share
Code:
/mnt2 -fstab 172.1.1.1:/share
And the same occurs, a brief pause but no listing of files. Do I need to specify the NFS version? I am using NFSv3. What else am I missing here? I've followed both autofs(5) and auto_master(5), but the examples seem to throw me for a loop each time.
 
Indeed. This is what I did (from the notes that I made):

Enabling autofs(5)

The first step in enabling autofs(5) is to add autofs_enable="YES" to /etc/rc.conf so that it and its corresponding daemons are loaded at boot.

Once autofs_enable="YES" is added you have to create a master "map" for each of the directories that you want mounted locally. To do this it is necessary to edit the /etc/auto_master file using your text editor of choice.

In that file you will see something like this:

Code:
# $FreeBSD: releng/10.2/etc/auto_master 283242 2015-05-21 13:42:37Z trasz $
#
# Automounter master map, see auto_master(5) for details.
#
/net  -hosts  -nobrowse,nosuid,intr
# When using the -media special map, make sure to edit devd.conf(5)
# to move the call to "automount -c" out of the comments section.
#/media  -media  -nosuid
#/-  -noauto

Code:
/mnt/mounts  /etc/auto.mounts #The line I added

#I have added the above line because I want the /mnt/mounts directory to serve as the place where all the foreign mounts are going to occur on the local machine. I tabbed over and added /etc/auto.mounts which calls the auto function to work on the mounts folder.

Once the /etc/auto_master file has been edited. I created an "auto" file with the same name of the place where I want the foreign mounts to occur locally by using ee /etc/auto.mounts

Once in the newly created /etc/auto.mounts file I added the following lines:

Code:
001  -intr,nfsv3 192.168.1.101:/a001/001
003  -intr,nfsv3 192.168.1.103:/a003/003
ports  -intr,nfsv3 192.168.1.101:/a001/ports

On the left, are the names of the folders that I wanted mapped to the /mnt/mounts folder. To the right are the NFS mounts with options for each of the foreign mounts that will happen on the local machine. I am using nfsv3, but nfsv4 can be used similarly.

Reboot

After reboot, the user only needs to navigate to the folder where his/her mounts are designated. Via the command line you won't see anything listed until you ls in the directory. Within a GUI, there might be a few seconds delay before the directory's contents are displayed for the first time.

After a period of time the folder may unmount, but it remounts if you navigate back to the directory. This is intended. Apologies for any formatting errors.
 
Note that there is even a simpler way: enable autofs, with the default auto_master, and do this: cd /net/172.1.1.1/share :)
 
Back
Top