Operations 8 min read

Master Dynamic Linux Mounts with autofs and Save System Resources

This guide explains why static /etc/fstab entries can waste resources, introduces the autofs daemon for on‑demand mounting, and provides step‑by‑step commands and configuration examples to set up automatic CD‑ROM mounting on a Linux server.

Open Source Linux
Open Source Linux
Open Source Linux
Master Dynamic Linux Mounts with autofs and Save System Resources

Both Samba and NFS services normally require their mount information to be written into /etc/fstab, causing the remote resources to be mounted automatically at boot. While convenient, mounting many remote resources can heavily load network bandwidth and server hardware, and unused mounts waste resources. Manually running mount each time works but is cumbersome.

The autofs automount service solves this problem. Unlike the static mount command, the autofs daemon is a Linux system daemon that detects when a user attempts to access an unmounted filesystem and mounts it automatically. By placing entries in /etc/fstab, the system still mounts them at boot, but autofs only performs the actual mount when the filesystem is accessed, conserving network and hardware resources.

# yum install autofs
Loaded plugins: langpacks, product-id, subscription-manager
......
Running transaction
Installing : hesiod-3.2.1-3.el7.x86_64 1/2
Installing : 1:autofs-5.0.7-40.el7.x86_64 2/2
Verifying : hesiod-3.2.1-3.el7.x86_64 1/2
Verifying : 1:autofs-5.0.7-40.el7.x86_64 2/2
Installed:
autofs.x86_64 1:5.0.7-40.el7
Dependency Installed:
hesiod.x86_64 0:3.2.1-3.el7
Complete!

In production Linux servers, many devices may need to be mounted. Writing all mount information directly into the autofs master configuration file makes it bulky and hard to maintain. Therefore, the master file should follow the "mount‑point sub‑map" format, where each mount point points to a separate sub‑configuration file.

For example, a CD‑ROM is typically mounted at /media/cdrom. The mount point in the master file is written as /media, and the corresponding sub‑map file (with a .misc suffix) contains the detailed device information.

# vim /etc/auto.master
# Sample auto.master file
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
/media   /etc/iso.misc
/misc    /etc/auto.misc
# NOTE: mounts done from a hosts map will be mounted with the "nosuid" and "nodev" options unless "suid" and "dev" are explicitly given.
/net -hosts
+dir:/etc/auto.master.d
+auto.master

In the sub‑configuration file, use the format "mount‑point filesystem‑type‑and‑options :device". To mount the CD‑ROM at /media/iso, the sub‑map entry looks like:

# vim /etc/iso.misc
iso   -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

Start and enable the autofs service:

# systemctl start autofs
# systemctl enable autofs
ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service'

Now, even though the /media/iso directory does not exist initially, you can cd into it and autofs will automatically mount the CD‑ROM, allowing you to list its contents. The following commands demonstrate the state before and after the automatic mount.

# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 17% /
... (other filesystems) ...
# cd /media
# ls
# cd iso
# ls -l
(total listing of CD contents)
# df -h
... (now shows /dev/cdrom mounted on /media/iso) ...
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationSystem AdministrationMountautofs
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.