Configure autofs

6. Create and Configure File Systems

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


Autofs is a Linux service that automatically mounts file systems when you need them and unmounts them after a period of inactivity. This is useful in IT environments where servers or workstations need access to network shares like NFS or SMB but you don’t want all shares mounted all the time.


Key Concepts for the Exam

  1. Purpose of autofs
    • Automatically mounts file systems when accessed.
    • Automatically unmounts them after a period of inactivity.
    • Reduces system load by not keeping unused network file systems mounted.
    • Helps prevent errors if network file systems are temporarily unavailable.
  2. Components of autofs
    Autofs works using two main types of files: ComponentDescriptionMaster Map (/etc/auto.master)The main configuration file. It tells autofs which mount points to manage and what mapping files to use.Map Files (e.g., /etc/auto.home, /etc/auto.nfs)Contains detailed instructions for each mount point, such as network path and options.autofs serviceThe running service that monitors the mount points and mounts/unmounts on demand.

How autofs Works

  1. You define a master map in /etc/auto.master.
    Example: /mnt/nfs /etc/auto.nfs
    • /mnt/nfs β†’ the local directory where mounts will appear.
    • /etc/auto.nfs β†’ the map file containing details about remote file systems.
  2. You create the map file. Example /etc/auto.nfs: projects -rw,soft server1:/exports/projects
    backups -ro server2:/exports/backups
    • projects β†’ will appear under /mnt/nfs/projects when accessed.
    • -rw β†’ mount options (read/write), -ro β†’ read-only.
    • soft β†’ if server is unavailable, it won’t hang the client.
    • server1:/exports/projects β†’ the remote NFS path.
  3. Start the autofs service: sudo systemctl enable autofs
    sudo systemctl start autofs
  4. Access the mount point: ls /mnt/nfs/projects
    • Autofs automatically mounts the NFS share here when accessed.
    • After a period of inactivity (default ~5 minutes), autofs automatically unmounts it.

Useful Commands

  • Check status of autofs systemctl status autofs
  • Restart autofs after config changes sudo systemctl restart autofs
  • Debug autofs sudo automount -v
  • Show active mounts managed by autofs mount | grep autofs

Common Mount Options in autofs Map Files

OptionMeaning
rwMount the file system read/write
roMount read-only
softIf the server fails, the mount times out instead of hanging
hardClient waits indefinitely for server response
noautoPrevent automatic mounting at boot; only mount on access

Exam Tips

  • You must know the locations of the main configuration files:
    • /etc/auto.master β†’ master map
    • Map files like /etc/auto.home, /etc/auto.nfs β†’ details for mounts
  • Understand mount options like rw, ro, soft, hard.
  • Be able to start, stop, enable, and restart the autofs service.
  • Understand the concept: on-demand mounting and automatic unmounting.
  • You may be asked to configure autofs for local NFS mounts, not just examples.

Example Scenario for Exam Practice

  1. Configure autofs to mount NFS shares from a server:
    • Master map: /etc/auto.master /mnt/nfs /etc/auto.nfs
    • Map file: /etc/auto.nfs devasc -rw,soft server:/exports/devasc
      test -ro server:/exports/test
    • Enable and start autofs: sudo systemctl enable autofs
      sudo systemctl start autofs
    • Access the mount: ls /mnt/nfs/devasc

This will ensure the NFS share is mounted only when you access /mnt/nfs/devasc and unmounted automatically after inactivity.


Summary for the Exam

  • autofs automatically mounts/unmounts file systems on demand.
  • Master map (/etc/auto.master) defines directories and associated map files.
  • Map files define remote shares and mount options.
  • Service commands: systemctl start|stop|restart autofs.
  • Exam focus: configuring autofs for network shares (usually NFS), understanding map files, and using correct options.
Buy Me a Coffee