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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. How to create sparse files in Linux using ‘dd’ command
  2. What are Bash Exit Codes in Linux
  3. After Reboot RAID1 Disk Gets Removed/Out of Sync (CentOS/RHEL)
  4. How to disable NUMA on EFI Boot Loaders using GRUB2 (CentOS/RHEL 6)
  5. How to verify the integrity of a file with md5 checksum
  6. How to configure VNC Server on Oracle Linux 6
  7. How to allow only specific non-root user(s) to use crontab
  8. How To Disable MD5-based HMAC Algorithm’s for SSH
  9. How to Change Default Permission of /var/log/messages in CentOS/RHEL
  10. How to Calculate Memory Usage in Linux using sar, ps, and free

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary