Introduction

In this challenge, you will learn how to configure the autofs service to automatically mount remote file systems on demand. Autofs is a program that uses the kernel automounter to automatically mount filesystems when they are accessed and unmount them after a period of inactivity. This is particularly useful for managing network shares like NFS.

Configure autofs to mount a remote NFS share

Your task is to configure autofs to automatically mount an NFS share. The environment has been pre-configured with an NFS server on localhost exporting the /shared directory. You will create two configuration files: a master map file that tells autofs which directories to watch, and a specific map file that defines the mount details.

Tasks

  • Create the autofs master map file at /etc/auto.master.d/nfs.autofs.
  • Create the autofs map file at /etc/auto.nfs to define the NFS mount.
  • Restart the autofs service to apply the new configuration.
  • Verify that the NFS share is mounted automatically upon access.

Requirements

  • The master map file must be created at /etc/auto.master.d/nfs.autofs.
  • The content of /etc/auto.master.d/nfs.autofs must be exactly:
/mnt/nfs  /etc/auto.nfs
  • The map file must be created at /etc/auto.nfs.
  • The content of /etc/auto.nfs must be exactly:
shared  -fstype=nfs,soft,intr  localhost:/shared
  • The autofs service must be restarted using the command:
sudo systemctl restart autofs

Example

After completing the configuration, accessing /mnt/nfs/shared should succeed and list the contents of the remote share. For example, you should see the test.txt file.

ls /mnt/nfs/shared

Expected output:

test.txt

Summary

In this challenge, you configured the autofs service to mount an NFS share on-demand. You learned how to create a master map file in /etc/auto.master.d/ and a corresponding map file defining the mount specifics. By restarting the autofs service, you applied these configurations, enabling seamless, automatic access to a network filesystem. This skill is essential for efficiently managing network resources in a Linux environment.

✨ Check Solution and Practice