[[linux_wiki:auto_mount_network_shares]]

Auto Mount Network Shares

General Information

Automatically mounting network shares with autofs. This is the client configuration and assumes a working server setup with NFS or CIFS shares already.

Checklist

  • Distro(s): Enterprise Linux 6/7
  • Other: Network server with shared directory (NFS or CIFS)

Install Required Packages

Pre-reqs:

  • Assuming that all client/server regular nfs/cifs mounting works before continuing. See below for configuration.


Install autofs

yum install autofs

Autofs Config

The master map file contains entries that point to other config files for specific mount instructions.

  • EL6: /etc/auto.master
  • EL7: /etc/auto.master.d/<name>.autofs
    • In EL7, the “/etc/auto.master” file is part of the RPM; any updates to the autofs package could overwrite changes you make, so it is recommended to create your own master map file under /etc/auto.master.d/. The name does not matter, as long as it ends in “.autofs”


Master Map File Contents

  • First column = name of the mount point on the local client system
  • Second column = config file that controls its mounting
  • Third column (optional) = default mount options for all mounts defined in config file

Example

# File: /etc/auto.master OR /etc/auto.master.d/<name>.autofs
 
# Direct mounts: look in auto.direct for mappings
/-     /etc/auto.direct
 
# Indirect mounts: look in auto.home for mappings of subdirectories of /home/
/home  /etc/auto.home --timeout=600
  • Direct Maps ⇒ One or more full path mounts to one or more remote servers. This is similar to regular NFS mounts that you would see in /etc/fstab.
    • Above example: /- /etc/auto.direct
  • Indirect Maps ⇒ Directories on the remote server that can all be mounted under the same local mount point. (IE: All sub directories of the listed local mount “/home”)
    • Above example: /home /etc/auto.home –timeout=600

Note: All direct map entries must be defined as “/-” in the /etc/auto.master or /etc/auto.master.d/<name>.autofs file.

# File: /etc/auto.direct
# Reminder of master map contents for reference:
#   /-     /etc/auto.direct
 
# Direct mappings: local mountpoint from remote mountpoint
/network-shares/nfs-share    -rw    192.168.1.151:/data/nfs
/network-shares/nfs-share2   -rw    192.168.1.151:/data/nfs2
/network-shares/cifs  -fstype=cifs,rw,credentials=/root/.ssh/.cifs-share  //192.168.1.151/cifs-share
  • First column ⇒ local mount point
  • Second column ⇒ mount options
  • Third column ⇒ remote shared directory

Note: This example works best when implemented using LDAP authentication to ensure that user id's are matched up between NFS server and clients.

Naming local and remote directories

# File: /etc/auto.home
# Reminder of master map contents for reference:
#   /home  /etc/auto.home --timeout=600
 
# Indirect mappings: sub directories of /home/
yoda    192.168.1.151:/home/yoda
luke    192.168.1.151:/home/luke
vader   192.168.1.200:/home/vader


Naming local only (Ampersand Wildcard)

yoda    192.168.1.151:/home/& 
  • The “&” is replaced by the key in the first column (yoda)


All wild cards (Asterisk and Ampersand Wildcards)

*    192.168.1.151:/home/&
  • “*” is assigned the directory that is accessed. If someone tried to access “/home/yoda”, the “*” value is “yoda”.
  • The “&” in the remote server line is replaced by the key in the first column (*). So if someone accesses local “/home/yoda”, the remote system (192.168.1.151) gets an access attempt to “/home/yoda”

Start and Enable Auto Mounter on Boot

  • EL7
    systemctl start autofs
    systemctl enable autofs
  • EL6
    service autofs start
    chkconfig autofs on

Reload Auto Mount Config (to enable changes made after service startup)

  • EL7
    systemctl reload autofs
  • EL6
    service autofs reload

  • linux_wiki/auto_mount_network_shares.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)