Chapter 14 ⏱️ 55 min read 📚 Advanced

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.

🎯 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 Use _netdev

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

  1. Check available shares:
    showmount -e server.example.com
  2. Create mount point:
    sudo mkdir -p /mnt/shared
  3. Test manual mount:
    sudo mount -t nfs4 server.example.com:/shared /mnt/shared
    df -h /mnt/shared
  4. Add to /etc/fstab:
    sudo vi /etc/fstab
    server.example.com:/shared  /mnt/shared  nfs  defaults,_netdev  0  0
  5. 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

  1. Create map file:
    sudo vi /etc/auto.direct
    
    # Add direct mount (absolute path)
    /mnt/data  -rw,soft  server.example.com:/exports/data
  2. Add to master map:
    sudo vi /etc/auto.master
    
    # Add line:
    /-  /etc/auto.direct
  3. Restart AutoFS:
    sudo systemctl restart autofs
  4. Test access (triggers mount):
    ls /mnt/data
    df -h /mnt/data
  5. 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

  1. 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
  2. Add to master map:
    sudo vi /etc/auto.master
    
    # Add line (parent directory):
    /mnt/remote  /etc/auto.shares  --timeout=60
  3. Restart AutoFS:
    sudo systemctl restart autofs
  4. 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
  5. 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 vs Indirect

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

  1. Create map file with wildcard:
    sudo vi /etc/auto.home
    *  -rw,soft,_netdev  server.example.com:/home/&
  2. Add to master map:
    sudo vi /etc/auto.master
    /rhome  /etc/auto.home
  3. Restart AutoFS:
    sudo systemctl restart autofs
  4. Test with different users:
    ls /rhome/user1    # Auto-mounts server:/home/user1
    ls /rhome/user2    # Auto-mounts server:/home/user2
  5. 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/*
💡 AutoFS Best Practices

• 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?

  • A) rw
  • B) _netdev
  • C) defaults
  • D) soft
Answer: B) _netdev
_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?

  • A) *
  • B) /-
  • C) /mnt
  • D) &
Answer: B) /-
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?

  • A) Match all files
  • B) Substitute with the key (username/directory)
  • C) Background process
  • D) Optional parameter
Answer: B) Substitute with the key
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?

  • A) Reboot the system
  • B) Run mount -a
  • C) systemctl restart autofs
  • D) Nothing, changes are automatic
Answer: C) systemctl restart autofs
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?

  • A) nfs-list server.example.com
  • B) showmount -e server.example.com
  • C) exportfs -v
  • D) mount | grep nfs
Answer: B) showmount -e server.example.com
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?

  • A) /docs
  • B) /shares
  • C) /shares/docs
  • D) /etc/auto.data/docs
Answer: C) /shares/docs
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.