Mount Network Storage (NFS & AutoFS)
Master network file system mounting with NFS and automatic mounting with AutoFS. Learn to configure NFS clients, create persistent mounts, and implement on-demand mounting with wildcard maps.
📋 Table of Contents
🎯 Introduction to Network Storage
Network File System (NFS) allows sharing directories over the network. AutoFS provides automatic, on-demand mounting of NFS shares and local filesystems.
NFS Versions
| Version | Features |
|---|---|
| NFSv3 | Legacy, UDP/TCP, no encryption |
| NFSv4 | Default in RHEL 9, TCP only, Kerberos support |
| NFSv4.2 | Latest, server-side copy, sparse files |
NFS vs AutoFS
| Method | Pros | Cons |
|---|---|---|
| /etc/fstab | Simple, mounts at boot | Always mounted, boot hangs if server down |
| AutoFS | On-demand, auto-unmount, no boot delays | More complex setup |
Required Packages
# Install NFS utilities (client)
sudo dnf install -y nfs-utils
# Install AutoFS
sudo dnf install -y autofs
# Verify installation
rpm -q nfs-utils autofs
📂 NFS Client Configuration
Discovering NFS Shares
# Show exported shares from NFS server
showmount -e server.example.com
# Output example:
Export list for server.example.com:
/shared 192.168.1.0/24
/home/users *
/data client1.example.com
# Check NFS server availability
ping server.example.com
rpcinfo -p server.example.com
Manual NFS Mount
# Create mount point
sudo mkdir -p /mnt/nfs
# Mount NFS share (NFSv4)
sudo mount -t nfs4 server.example.com:/shared /mnt/nfs
# Mount with NFSv3
sudo mount -t nfs -o vers=3 server.example.com:/shared /mnt/nfs
# Verify mount
df -h /mnt/nfs
mount | grep nfs
# Unmount
sudo umount /mnt/nfs
Persistent NFS Mount (/etc/fstab)
# Edit /etc/fstab
sudo vi /etc/fstab
# Add NFS mount (NFSv4)
server.example.com:/shared /mnt/nfs nfs defaults 0 0
# With options
server.example.com:/shared /mnt/nfs nfs defaults,_netdev 0 0
# NFSv3 specific
server.example.com:/shared /mnt/nfs nfs defaults,_netdev,vers=3 0 0
# Test before reboot
sudo mount -a
# Verify
df -h /mnt/nfs
Common NFS Mount Options
| Option | Description |
|---|---|
| _netdev | Wait for network before mounting (critical for NFS!) |
| soft | Return error if server timeout |
| hard | Keep retrying (default, safer) |
| ro | Read-only |
| rw | Read-write |
| vers=4 | Force NFSv4 (default) |
| sec=krb5 | Use Kerberos authentication |
Always include _netdev option for NFS mounts in /etc/fstab!
Without it, system may hang at boot if network isn't ready. This ensures the system
waits for network before attempting NFS mounts.
Procedure: Mount NFS Share Persistently
- Check available shares:
showmount -e server.example.com - Create mount point:
sudo mkdir -p /mnt/shared - Test manual mount:
sudo mount -t nfs4 server.example.com:/shared /mnt/shared df -h /mnt/shared - Add to /etc/fstab:
sudo vi /etc/fstab server.example.com:/shared /mnt/shared nfs defaults,_netdev 0 0 - Unmount and test fstab:
sudo umount /mnt/shared sudo mount -a df -h /mnt/shared
🔄 AutoFS - Automatic Mounting
AutoFS mounts filesystems automatically when accessed and unmounts after idle timeout (default 5 minutes).
AutoFS Configuration Files
# Main configuration
/etc/auto.master # Master map (defines mount points)
/etc/auto.master.d/ # Additional master map files
# Map files (define what to mount)
/etc/auto.misc # Default indirect map
/etc/auto.net # Network automount
/etc/auto.home # Home directories (example)
AutoFS Service
# Start AutoFS
sudo systemctl start autofs
# Enable at boot
sudo systemctl enable --now autofs
# Restart after config changes
sudo systemctl restart autofs
# Check status
systemctl status autofs
# Reload configuration
sudo systemctl reload autofs
Master Map Format
# /etc/auto.master format:
# mount-point map-file [options]
/mnt/auto /etc/auto.nfs --timeout=60
/home /etc/auto.home --timeout=300
📍 AutoFS Direct Maps
Direct maps specify the exact mount point. Use /- in master map.
Procedure: Configure Direct Map
- Create map file:
sudo vi /etc/auto.direct # Add direct mount (absolute path) /mnt/data -rw,soft server.example.com:/exports/data - Add to master map:
sudo vi /etc/auto.master # Add line: /- /etc/auto.direct - Restart AutoFS:
sudo systemctl restart autofs - Test access (triggers mount):
ls /mnt/data df -h /mnt/data - Verify automount:
mount | grep autofs
Direct Map Format
# /etc/auto.direct
# mount-point options location
/mnt/project -rw,soft nfsserver:/exports/project
/backup -ro nfsserver:/backups
/share -rw 192.168.1.100:/shared
📂 AutoFS Indirect Maps
Indirect maps create subdirectories under a parent mount point. More flexible than direct maps.
Procedure: Configure Indirect Map
- Create map file:
sudo vi /etc/auto.shares # Add indirect mounts (relative paths, no leading /) data -rw,soft server.example.com:/exports/data backup -ro server.example.com:/exports/backup docs -rw server.example.com:/exports/docs - Add to master map:
sudo vi /etc/auto.master # Add line (parent directory): /mnt/remote /etc/auto.shares --timeout=60 - Restart AutoFS:
sudo systemctl restart autofs - Test access:
ls /mnt/remote/data # Mounts server:/exports/data ls /mnt/remote/backup # Mounts server:/exports/backup ls /mnt/remote/docs # Mounts server:/exports/docs - Check mounts:
df -h | grep remote mount | grep autofs
Indirect Map Format
# /etc/auto.shares
# key options location
docs -rw nfsserver:/exports/documentation
home -rw nfsserver:/home/&
tools -ro nfsserver:/opt/tools
Direct: Uses /- in master map, absolute paths in map file
Indirect: Uses parent directory in master map, relative keys in map file
When to use: Indirect is preferred for multiple related mounts
🎯 AutoFS Wildcard Maps
Wildcard maps use * to match any key, useful for user home directories.
Home Directory Automount
# Create map for home directories
sudo vi /etc/auto.home
# Wildcard entry (& substitutes the key)
* -rw,soft nfsserver:/home/&
# Add to master map
sudo vi /etc/auto.master
/home /etc/auto.home --timeout=300
# Restart AutoFS
sudo systemctl restart autofs
# Access user homes (auto-mounts on access)
cd /home/john # Mounts nfsserver:/home/john
cd /home/alice # Mounts nfsserver:/home/alice
Wildcard Examples
# Multi-user shares
sudo vi /etc/auto.users
* -rw nfsserver:/users/&
# Department shares
sudo vi /etc/auto.dept
* -rw fileserver:/departments/&
# Access:
ls /mnt/users/bob # Mounts /users/bob
ls /mnt/dept/sales # Mounts /departments/sales
Complex Wildcard with Subdirectories
# Multi-level structure
sudo vi /etc/auto.projects
* -rw projectserver:/projects/&/current
# Creates structure:
/mnt/projects/alpha → projectserver:/projects/alpha/current
/mnt/projects/beta → projectserver:/projects/beta/current
Procedure: Setup Wildcard AutoFS for User Homes
- Create map file with wildcard:
sudo vi /etc/auto.home * -rw,soft,_netdev server.example.com:/home/& - Add to master map:
sudo vi /etc/auto.master /rhome /etc/auto.home - Restart AutoFS:
sudo systemctl restart autofs - Test with different users:
ls /rhome/user1 # Auto-mounts server:/home/user1 ls /rhome/user2 # Auto-mounts server:/home/user2 - Verify mounts:
df -h | grep rhome mount | grep autofs
Troubleshooting AutoFS
# Check AutoFS status
systemctl status autofs
# View AutoFS logs
journalctl -u autofs -n 50
# Test with verbose logging
sudo automount -f -v
# Check master map parsing
sudo cat /etc/auto.master | grep -v '^#'
# Verify map file syntax
sudo cat /etc/auto.home
# Check if mount point exists (shouldn't exist before access)
ls -ld /mnt/auto
# Force unmount stuck AutoFS
sudo umount -l /mnt/auto/*
• Don't manually create AutoFS mount points (AutoFS creates them)
• Use indirect maps for multiple related shares
• Set appropriate timeout (default 300s, use --timeout= option)
• Always restart autofs after configuration changes
• Check logs if mounts don't trigger: journalctl -u autofs
📝 Practice Questions
Question 1: What option is CRITICAL for NFS mounts in /etc/fstab?
_netdev tells systemd to wait for network before mounting. Without it,
system can hang at boot if NFS server is unreachable. Always use:
server:/share /mnt nfs defaults,_netdev 0 0
Question 2: What symbol is used in AutoFS master map for direct mounts?
Direct maps use
/- as mount point in /etc/auto.master.
Map file then uses absolute paths. Indirect maps use a parent directory instead.
Example: /- /etc/auto.direct
Question 3: What does the "&" symbol mean in AutoFS wildcard maps?
In
* -rw server:/home/&, the & is replaced with whatever key is accessed.
Accessing /home/john mounts server:/home/john. Perfect for user home directories.
Question 4: After editing AutoFS maps, what must you do?
Always restart autofs after changing configuration files:
sudo systemctl restart autofs. Can also use reload but
restart is safer. Check status: systemctl status autofs
Question 5: What command shows NFS exports from a server?
showmount -e queries NFS server for available exports.
exportfs -v is run on the NFS server to show its exports.
mount | grep nfs shows locally mounted NFS shares.
Question 6: Indirect map: "/shares /etc/auto.data" - Where does "docs" key mount?
Indirect maps create subdirectories under parent mount point. Master map shows /shares as parent, map file has "docs" key, so mount point is /shares/docs. Direct maps would use absolute path in map file instead.