This document explains how to automaticly mount NFS drives on client machines.

2. What are the advantages of automounting NFS drives versus standard mounting!?

To mount devices you must be login as root. That means either admin must be present all the time, volume must be mounted 24/7 or users must have root acces. Often neither of mentioned is acceptable.

3. How autofs works?

NFS mountpoint (preconfigured directory) exists all the time, and volumes are not mounted. When user enters mountpoint, autofs mounts NFS filesystem in that directory. While apps use that directory, or files/dirs beneath it, mountpoint is locked and volume stays mounted. T seconds after usage of volume is finished, autofs umounts it. You can even "hide" mountpoint, lack of "--ghost" feature will make sure of it
Things can be made simplier by adding symbolic links and/or icons to the mountpoint. So you can have an icon on your fvwm+rox desktop, which starts file manager browsing from mounted NFS volume. Once file manager is halted, autofs umounts dir. The best thing is, you can be user vulgaris, and everything will still work.

4. Prerequisits?

Offcourse, you need fully working NFS access. That means that topics like setting up NFS server and clients, granting access and mounting NFS volumes is beyond scope of this document. You'll need root access, too. If you can mount NFS volume on your client machine, then you're ready to go. And how to mount NFS volume? Simple:

There are practicly none. If you know how to set up autofs to work with dvdrom drive, then it will be a piece of cake to set it up to automount NFS volumes - and vice versa. You'll even notice that these two autofs howto's are pretty much the same, but are divided into two documents in userfriendly spirit - so that user don't get confused, as it's much easier to understand one thing at a time.

Note that it doesn't matter if it's builtin or a module, do it how you prefer. If it's compiled as a module, it will be loaded automatically upon startup of autofs daemon, so you don't need to load it manually. After exiting menuconfig and saving new kernel config file, you should recompile it. If autofs is built into the kernel (<*>) then you can just run "make bzImage" and copy new image in /boot, and if it's selected as a module (<M>) then you don't need to recompile kernel image, but just modules ("make modules modules_install"). After doing this, don't forget to re-emerge additional kernel modules (like nforce-audio, sys-fs/fuse, lircd, fglrx.....) that you use.

3. fetch and compile autofs

Code:

# emerge net-fs/autofs

4. setup "/etc/autofs/auto.master"

Code:

/nfs /etc/autofs/auto.nfs --option1 --option2

Quote:

1. First option tells autofs under what directory devices will be mounted
2. Second option tells autofs what configuration file to use for selected dir
3. Third come the options that will be passed to automounter. --timeout=1 means that any device configured in auto.nfs file will be umounted after 1s of inactivity. --ghost can be added too, and some other opts. "--ghost" option tells to autofs that mountpoints must exist all the time, regardless if the volumes are mounted or not. This is nice if you wish to have list of all volumes present in destination directory all the time.
NOTE: You can have multiple configuration files, for different dirs or different devices...just as auto.nfs file can have multiple volumes, so auto.master can also have multiple auto.* files defined...and the sky is limit! This way, you can have different options for each mountpoint (e.g.: if you don't want automatic umounting of NFS mounts, or ghosting for cd/dvd devices, etc). This flexibility really show's off if you want different filesystems to umount after different period of inactivity.
NOTE 2: If you don't pass any options in auto.master, then daemon will act on default policy settings. These are set in 6th step of this howto. BUT, this options will be passed to ALL mountpoints! You can still override them, offcourse, by setting them up here, in auto.master file.

1. First option tells autofs what is the name of dir to mount device on. Dir will be placed under directory stated previously in auto.master (in this case: /nfs/mountpoint0).
2. Second option configures fstype and various permisions what will be passed to mount. First we have filesystem type (nfs), then read/write mode, and "hard,intr" option which are nfs specific, and are described in NFS Howto.
3. Third place addresses remote NFS volume to be mounted.

So basicly. if you don't understand, mounpoint0 and mounpoint1 are empty dirs created upon autofs daemon startup, and located in /nfs (or any other dir set up as root dir of auto.nfs file - see the section 4 of this document). server0-dns-or-ip is name or ip address of server with shared volume, /dir1/dir2/shareddir0 is a path on that server that leads to shared dir named "shareddir0". I hop you finally get it

6. setup additional options in "/etc/conf.d/autofs"

Code:

daemonoptions='--timeout=1 --ghost'

Quote:

This file is parsed during autofs daemon startup, and checked for daemonoptions. If you don't want ghosting on all your mountpoints, don't put it in dameonoptions but in auto.master file, third section.

NOTE: This kind of setting up options is Gentoo-specific. Other distros use other methods, and if you wish to have distro-unspecific setup, then all the options should be set like described in section 4. This also stands for other distro users.

NOTE 2: If you don't know, --ghost is pretty nice option. It request that directories in the automount must be shown but not mounted until accesssed. This way you can eliminate the need of symlinks, and this makes life a lot easier

NOTE 3: '--ghost' option is avaliable ONLY in automount 4.x, not in 3.x, and must be put in daemonoptions variable, not localoptions like before.

7. start autofs daemon and add it to runlevel

Code:

# /etc/init.d/autofs start
# rc-update add autofs default

8. test automounter
Make sure you're connected to server, and you can mount filesystem correctly from the console. Also be sure to umount NFS volumes autofs is set upon, cause you'll probably get error if you try to mount same volume twice.
Then, try to access /nfs/mountpoint0 dir. If it's all ok, system will wait for a few seconds until NFS volume mounts, and then you'll have access to it. Congratulations!

9. make symbolic links and/or icons
NOTE: If you use automounter4, and have --ghost option enabled, than you can skip this step. I will leave it online for users of old, 3.x version wich didn't support ghosting.
Access NFS's volume mountpoint and automount it (acces /nfs/mountpoint0 trough xterm for example). Open new xterm window and type (as root):

Code:

# cd /mnt
# ln -s /nfs/mountpoint0 mountpoint0
...etc...

Now, when volumes are not mounted, you can access symlink although it points to non existing dir. Once accessed, symlink will start chain of events that'll led to creation of target dir and automount of NFS volume.

That's it!!!

What am I using (in time of writing this doc)?
- kernel 2.6.12-gentoo-r6
- autofs 4.1.3-r4

I recomend the latest version of autofs -> 4.1.3-r4. Also I've been running many versions of kernels back to 2.4.23 with no problems regarding autofs, so if you have problems, it's very unlikely that they're kernel based...

Disclaimer: All damage done to your system by following this howto is not my responsability, do this at your, and your risk only. This document can have errors too, so please correct me, nobody's perfect (excpet Seven of Nine). I tried to explain even smallest details but it's unlikely that everyone will understand everything. So, if you have any troubles using autofs or have any doubts with this howto, feel free to mail me. Live long and prosper \V/

heh, i'm suprized no one has posted to this. seems like a very handy feature.

i actually have a windows (smb) share i need to automount. i'll probably use this guide as reference... i'm hoping the principle is the same just samba instead of nfs._________________Sheepdog
Why Risk It? | Samba Howto

for some reason it seems to freeze up when using konqueror to browse mounted shares, and emerge also chunks up when portage is mounted using autofs. i'm not sure if this is an autofs problem or what, but has anyone else who have used autofs had this problem?_________________Sheepdog
Why Risk It? | Samba Howto