• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Mount NFS File Systems Using ‘autofs’ in CentOS/RHEL

by admin

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:

The file /etc/auto.master is the main configuration file for ‘autofs’ service, this file contains the master map lists of the mount points on the system controlled by ‘autofs’, and their corresponding configuration files or network sources which are known as ‘automount maps‘.

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 map file is a separate file that defines the file systems to be mounted under any specified mount point. For example, the /etc/auto.misc file might define mount points in the /misc directory; another example is to use /mnt as another directory to mount the export. If any other directory is needed then a new file must be created under /etc/ directory with the name ‘auto.mount’ as a recommendation.

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
NOTE: Make sure that you have edited the ‘/etc/auto.master’ file and change the map file to the desired one.

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)

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. binwalk: command not found
  2. Shell Script to print pyramid of Stars
  3. Medusa: command not found
  4. wifi-menu: command not found
  5. flash Command Examples in Linux
  6. CentOS/RHEL : Unmounting a Windows Share Fails – “device is busy”
  7. How to Remove Network Printer in CentOS/RHEL
  8. Determining disk usage in Linux using “du” command
  9. CentOS / RHEL 7 : How to create custom script to run automatically during boot
  10. How to setup passwordless SSH login in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright