- Home
-
Autofs (Automounter)
Linux Autofs (Automounter) Cheatsheet
Comprehensive Autofs guide covering automatic filesystem mounting, master maps, indirect/direct maps, NFS configuration, troubleshooting, and best practices for on-demand network filesystem mounting in Linux.
Free account required
What is Autofs?
Autofs (automounter) is a kernel-based filesystem that automatically mounts filesystems on-demand when accessed and unmounts them after a period of inactivity. It's ideal for NFS shares and network drives, reducing boot time and network traffic.
Table of Contents
How Autofs Works
The Automount Process
User attempts to access a directory managed by autofs (e.g., cd /mnt/nfs/server1)
$ cd /mnt/nfs/server1
# Autofs detects access attempt
Autofs daemon consults the map file (/etc/auto.nfs) to see if the directory maps to a remote filesystem
# Checking /etc/auto.nfs
server1 -fstype=nfs,rw 192.168.1.100:/export/data
If entry exists in map file, autofs dynamically mounts the remote filesystem to the specified mount point
# Mount performed automatically
mount -t nfs 192.168.1.100:/export/data /mnt/nfs/server1
# User can now access files transparently
If no matching entry in map file, access is denied with "No such file or directory" error
$ cd /mnt/nfs/nonexistent
bash: cd: /mnt/nfs/nonexistent: No such file or directory
After timeout (default 5 minutes), autofs automatically unmounts the filesystem if not in use
# After 5 minutes of inactivity
# Autofs automatically unmounts
umount /mnt/nfs/server1
Autofs vs /etc/fstab
Feature | Autofs | /etc/fstab |
---|---|---|
Mount Time | On-demand (when accessed) | At boot time |
Auto Unmount | Yes (after timeout) | No (manual unmount) |
Network Failure | Doesn't block boot | Can hang boot process |
Resource Usage | Minimal (mounts as needed) | Always mounted |
Use Case | Network shares, optional mounts | Critical system filesystems |
Key Benefits of Autofs
- Faster Boot Times: No waiting for network mounts during startup
- Reduced Network Traffic: Only active mounts consume bandwidth
- Resilience: System doesn't hang if remote server is down
- Resource Efficiency: Filesystems unmount when not in use
- Transparent Operation: Users access files as if locally mounted
- Centralized Management: Single configuration file for all mounts
Installation & Setup
Install Autofs
Before installing autofs, ensure your VPS environment meets basic requirements. See our performance benchmarks to find optimal server configurations.
# Debian/Ubuntu
$ sudo apt update
$ sudo apt install autofs
# RHEL/CentOS/Rocky/Alma
$ sudo dnf install autofs
# Arch Linux
$ sudo pacman -S autofs
Enable and Start Autofs Service
# Enable autofs to start at boot
$ sudo systemctl enable autofs
# Start autofs service
$ sudo systemctl start autofs
# Check service status
$ sudo systemctl status autofs
# Restart after configuration changes
$ sudo systemctl restart autofs
Main Configuration Files
/etc/auto.master
Master configuration file (defines mount points and map files)
/etc/auto.*
Map files (define what and how to mount) - learn more about Linux filesystem management
/etc/autofs.conf
Global autofs daemon settings (optional)
Master Map Configuration (/etc/auto.master)
Master Map Syntax
# Format:
# mount-point map-file [options]
# Examples:
/mnt/nfs /etc/auto.nfs --timeout=60
/misc /etc/auto.misc --timeout=300
/- /etc/auto.direct --ghost
Mount Point: Base directory for autofs mounts
Map File: Configuration file defining individual mounts
Options: Timeout, ghost mode, etc.
Example: /etc/auto.master
# /etc/auto.master - Master autofs configuration
# Mount NFS shares at /mnt/nfs/*
/mnt/nfs /etc/auto.nfs --timeout=60
# Mount miscellaneous filesystems at /misc/*
/misc /etc/auto.misc --timeout=300
# Direct mounts (full path specified in map)
/- /etc/auto.direct --ghost
# Mount home directories from NFS server
/home /etc/auto.home --timeout=120
# Include other master map files
+auto.master
Common Master Map Options
Option | Description | Example |
---|---|---|
--timeout=N | Unmount after N seconds of inactivity | --timeout=60 |
--ghost | Show mount points even when not mounted | --ghost |
--verbose | Enable verbose logging | --verbose |
--nobrowse | Don't show directory until accessed | --nobrowse |
Map Types (Direct vs Indirect)
Indirect Maps (Most Common)
Indirect maps mount filesystems as subdirectories under a common parent directory. The mount point is relative to the parent specified in auto.master.
Example: /etc/auto.master
/mnt/nfs /etc/auto.nfs --timeout=60
Example: /etc/auto.nfs (Indirect Map)
# Key Options Location
server1 -fstype=nfs,rw 192.168.1.100:/export/data
server2 -fstype=nfs,ro,soft nfs.example.com:/share
backup -fstype=nfs,rw,noatime 10.0.0.50:/backups
Access paths: /mnt/nfs/server1, /mnt/nfs/server2, /mnt/nfs/backup
Direct Maps (Full Path)
Direct maps specify the full mount path. Use "/-" in auto.master to enable direct mounts. Useful for mounting to specific paths outside a common parent.
Example: /etc/auto.master
/- /etc/auto.direct --ghost
Example: /etc/auto.direct (Direct Map)
# Full-path Options Location
/opt/software -fstype=nfs,ro nfs-server:/software
/data/shared -fstype=nfs,rw 192.168.1.200:/shared
/mnt/archive -fstype=nfs,ro,soft backup.local:/archives
Access paths: /opt/software, /data/shared, /mnt/archive (exact paths)
When to Use Each Type
- Multiple similar mounts (NFS servers)
- User home directories
- Common mount point prefix
- Scalable configurations
- Specific mount paths
- System directories (/opt, /data)
- Mixed filesystem locations
- Integration with existing paths
Common Configuration Examples
NFS Shares (Most Common)
Configure NFS network shares for automatic mounting. Use our Port Scanner tool to verify NFS port 2049 is accessible.
# /etc/auto.master
/mnt/nfs /etc/auto.nfs --timeout=60
# /etc/auto.nfs
# Basic NFS mount
data -fstype=nfs,rw nfs-server.local:/data
# NFS with soft mount (recommended for non-critical data)
backup -fstype=nfs,rw,soft,timeo=10 192.168.1.50:/backups
# NFS with specific version (NFSv4)
media -fstype=nfs4,ro,noexec media-server:/media
# Multiple NFS servers (failover)
shared -fstype=nfs,rw,soft nfs1:/shared,nfs2:/shared
CIFS/SMB Shares (Windows)
# /etc/auto.master
/mnt/windows /etc/auto.smb --timeout=120
# /etc/auto.smb
# Basic SMB mount with credentials
share1 -fstype=cifs,rw,username=user,password=pass ://server/share1
# SMB with credentials file (more secure)
share2 -fstype=cifs,rw,credentials=/etc/.smbcreds ://192.168.1.10/share2
# Guest access (no credentials)
public -fstype=cifs,ro,guest ://fileserver/public
# /etc/.smbcreds (chmod 600)
# username=myuser
# password=mypassword
# domain=WORKGROUP
SSHFS (Secure File Transfer)
Mount remote filesystems securely via SSH. For security best practices, see our OpenSSH hardening guide.
# /etc/auto.master
/mnt/ssh /etc/auto.sshfs --timeout=60
# /etc/auto.sshfs
# SSHFS with key-based authentication
remote1 -fstype=fuse,rw,allow_other,IdentityFile=/root/.ssh/id_rsa :sshfs\#[email protected]\:/data
# SSHFS with compression
remote2 -fstype=fuse,rw,compression=yes :sshfs\#[email protected]\:/backup
User Home Directories
# /etc/auto.master
/home /etc/auto.home --timeout=300
# /etc/auto.home
# Wildcard entry - mounts home directory for any user
* -fstype=nfs,rw nfs-server:/home/&
# Access:
# /home/john → mounts nfs-server:/home/john
# /home/jane → mounts nfs-server:/home/jane
CD-ROM / USB Auto-mounting
# /etc/auto.master
/misc /etc/auto.misc --timeout=5
# /etc/auto.misc
# CD-ROM drive
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# USB drive
usb -fstype=auto,async,nodev,nosuid :/dev/sdb1
Common Mount Options
rw, ro, soft, hard, intr, timeo=10, retrans=3, noatime
username=user, password=pass, uid=1000, gid=1000, file_mode=0755
Commands & Management
Service Management
# Check autofs status
$ sudo systemctl status autofs
# Restart autofs (after config changes)
$ sudo systemctl restart autofs
# Reload configuration without restart
$ sudo systemctl reload autofs
# Enable at boot
$ sudo systemctl enable autofs
# Stop autofs
$ sudo systemctl stop autofs
Testing & Debugging
# Run automount in foreground (debug mode)
$ sudo automount -f -v
# Check autofs mounts
$ mount | grep autofs
# View active autofs mount points
$ sudo automount -m
# Check map file syntax
$ sudo autofs-check-config /etc/auto.master
# Force unmount all autofs mounts
$ sudo killall -HUP automount
Manual Mount Testing
# Test NFS mount manually (before adding to autofs)
$ sudo mount -t nfs 192.168.1.100:/export/data /mnt/test
# Test CIFS mount manually
$ sudo mount -t cifs -o username=user //server/share /mnt/test
# Unmount test mount
$ sudo umount /mnt/test
# Check if NFS server is accessible
$ showmount -e 192.168.1.100
Viewing Logs
For advanced log analysis and parsing techniques, see our Linux log parsing guide.
# View autofs logs (systemd)
$ sudo journalctl -u autofs -f
# View system logs
$ sudo tail -f /var/log/syslog # Debian/Ubuntu
$ sudo tail -f /var/log/messages # RHEL/CentOS
# Enable debug logging in /etc/autofs.conf
logging = verbose
Map File Management
# Edit master map
$ sudo nano /etc/auto.master
# Edit indirect map
$ sudo nano /etc/auto.nfs
# After editing, restart autofs
$ sudo systemctl restart autofs
# Or reload without full restart
$ sudo systemctl reload autofs
Troubleshooting Common Issues
Common Problems & Solutions
Symptoms: Directory doesn't appear or shows empty
Solution:
# Check if autofs is running
$ sudo systemctl status autofs
# Try accessing the directory
$ ls /mnt/nfs/server1
# Enable ghost mode in auto.master
/mnt/nfs /etc/auto.nfs --ghost
# Check for typos in map files
$ cat /etc/auto.master
$ cat /etc/auto.nfs
Symptoms: "Permission denied" when accessing mounted directory
Causes: NFS export restrictions, firewall, UID/GID mismatch. Check file permissions for more details.
# Check NFS exports on server
$ showmount -e nfs-server
# Verify firewall allows NFS (port 2049) - use our Port Scanner tool
$ sudo firewall-cmd --list-services
# Check mount options (add uid/gid if needed)
data -fstype=nfs,rw,uid=1000,gid=1000 nfs-server:/data
Symptoms: Access hangs, system becomes unresponsive
Solution: Use soft mount with timeout
# Use soft mount to prevent hanging
data -fstype=nfs,rw,soft,timeo=10,retrans=3 nfs-server:/data
# Test server connectivity first
$ ping nfs-server
$ telnet nfs-server 2049
Symptoms: Map file changes don't take effect
Solution:
# Always restart autofs after changes
$ sudo systemctl restart autofs
# Or reload for less disruption
$ sudo systemctl reload autofs
# Check syntax before restarting
$ sudo automount -f -v # Test in foreground
Symptoms: Autofs can't unmount, "device busy" error
Solution:
# Find processes using the mount
$ sudo lsof +D /mnt/nfs/server1
$ sudo fuser -m /mnt/nfs/server1
# Kill processes if safe
$ sudo fuser -km /mnt/nfs/server1
# Or wait for timeout to expire
Debug Checklist
Use these diagnostic tools: DNS Lookup for hostname resolution and Port Scanner for connectivity testing.
systemctl status autofs
ping server
, showmount -e server
journalctl -u autofs -f
automount -f -v
Best Practices
soft
mount option to prevent system hangs if NFS server becomes unavailable. Add timeout and retry values.data -fstype=nfs,rw,soft,timeo=10,retrans=3 nfs-server:/data
--ghost
option to show mount points even when not mounted, improving discoverability for users./mnt/nfs /etc/auto.nfs --ghost --timeout=60
# /etc/auto.smb
share -fstype=cifs,rw,credentials=/etc/.smbcreds ://server/share
# /etc/.smbcreds (chmod 600 root:root)
username=myuser
password=mypassword
mount
command before adding to autofs to verify connectivity, permissions, and options.# /etc/auto.nfs - NFS shares from file server cluster
# Contact: [email protected] | Updated: 2025-01-19
data -fstype=nfs,rw,soft fileserver1.local:/data # Production data
-fstype=nfs4
.journalctl -u autofs
to track mount/unmount events.Host Your Network File Systems
Running NFS, CIFS, or other network filesystems? Compare VPS providers to find the perfect infrastructure for your autofs configurations with reliable storage, fast networking, and minimal latency. Compare performance metrics or explore our server tools.
Need help? Contact us | Learn about VPSMetrics | Privacy Policy