This post explains how to configure ‘autofs’ in order to mount NFS file systems with ‘autofs’ service.
1. Stop ‘autofs’ service, check if the service is running then proceed to stop it.
# service autofs status automount (pid 25285) is running... # service autofs stop Stopping automount: [ OK ] # service autofs status automount is stopped
2. Edit the /etc/auto.master file to set the file map:
This is how the file should looks like:
# Sample auto.master file # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # For details of the format look at autofs(5). # /misc /etc/auto.misc ---------------------> MAP FILE # # NOTE: mounts done from a hosts map will be mounted with the # "nosuid" and "nodev" options unless the "suid" and "dev" # options are explicitly given. # /net -hosts # # Include central master map if it can be found using # nsswitch sources. # # Note that if there are entries for /net or /misc (as # above) in the included master map any keys that are the # same will not be seen as the first read key seen takes # precedence. # +auto.master
The ‘map file’ can be changed to any other file under /etc with the name ‘auto.mount’ in order to mount the export to any other desired directory. For more information please proceed to step number two.
Edit the ‘auto.master‘ file and add the hash symbol in front of the line “/misc /etc/auto.misc”, then proceed to add the following line to the end of the file:
/- /etc/auto.mount
The file should look like the following example after the change:
# # /misc /etc/auto.misc # /- /etc/auto.mount
3. Create and/or edit the map file:
The following is an example of the ‘/etc/auto.misc’ file and the new file ‘auto.mount’
# This is an automounter map and it has the following format # key(mount-point) [ -mount-options-separated-by-comma ] location ===> THIS IS THE GENERAL FORMAT OF THE MAPS # Details may be found in the autofs(5) manpage cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom ===> EXAMPLE # the following entries are samples to pique your imagination #linux -ro,soft,intr ftp.example.org:/pub/linux #boot -fstype=ext2 :/dev/hda1 #floppy -fstype=auto :/dev/fd0 #floppy -fstype=ext2 :/dev/fd0 #e2floppy -fstype=ext2 :/dev/fd0 #jaz -fstype=ext2 :/dev/sdc1 #removable -fstype=ext2 :/dev/hdd mount_point_name -rw,soft,intr,rsize=8192,wsize=8192 NFS.example.net:/export_name ===> IP address can be used instead of the FQDN
If you do not want to use /misc directory nor the ‘auto.misc’ file, create a new file with the name ‘auto.mount’ and add the same parameters with the corresponding syntax, like in the example as follows:
# vi /etc/auto.mount
Append the following line:
/mount_point -fstype=nfs,rw NFS.example.net:/export_name
4. Start the ‘autofs’ service:
# service autofs start Starting automount: [ OK ]
5. Run ‘mount’ command to check that your NFS share is now mounted:
# mount NFS_IP_Address:/export on /mount_point type nfs (rw,vers=4,addr=NFS_IP_Address,clientaddr=local_IP_Address)