Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.

RHCSA - Create & Configure File Systems: Configure autofs

autofs Overview

Autofs, on Red Hat Linux, is a dynamic filesystem mounting service that enables on-demand mounting and unmounting of network-based or removable file systems. It streamlines filesystem management by automatically handling mounts and unmounts based on user or application requests, eliminating the need for static entries in the /etc/fstab file. This efficient approach enhances resource utilization, optimizes system performance, and simplifies overall administration by ensuring that network shares or external devices are accessible only when required.

Lesson Setup (NFS Server)

If you followed lesson Mount and Unmount Network File Systems Using NFS, you would have already performed this lesson setup so it is not required again:

To actively participate in the exercises, you will need both Server One and server two available. Server two is where NFS will be setup so that the exercises for this exam objective can be performed against. This NFS setup is not apart of the exam objective.

Set up NFS server on server two:

Install NFS packages:

sudo dnf -y install nfs-utils

Enable and start the NFS Server and RPC Bind Service:

sudo systemctl enable --now nfs-server rpcbind

Create a shared location:

sudo mkdir -pv /nfs/exports/rhcsa_share

Give everyone access: (Do not do this in production. This step is to allow the exercises in relation to the exam objective to work and not how to demonstrate how to configure an NFS server fully.)

sudo chmod 777 /nfs/exports/rhcsa_share

Export the shared location:

echo "/nfs/exports/rhcsa_share *(rw)" | sudo tee /etc/exports

Export the shared location:

sudo exportfs -r

Configure the firewall:

sudo firewall-cmd --add-service nfs --permanent
sudo firewall-cmd --add-service rpc-bind --permanent
sudo firewall-cmd --add-service mountd --permanent
sudo firewall-cmd --reload

Configuring autofs

autofs Package

The first step in configuring autofs involves installing the required autofs package as it may not already be installed.

Install autofs:

sudo dnf -y install autofs

autofs Configuration Files

In the /etc/auto.master configuration file, you specify a directory and the corresponding map file that contains the details of file systems that need to be mounted within that directory. You can specify many directory and the related map files in the /etc/auto.master file.

The map file is typically called /etc/auto.<mountpoint> and in our exercise this will be /etc/auto.rhcsa_share.

Setup autofs configuration and map file:

Setup the auto.master file to map to file auto.rhcsa_share:

sudo echo '/nfs/autofs /etc/auto.rhcsa_share' | sudo tee -a /etc/auto.master

Setup auto.rhcsa_share map file:

sudo echo 'rhcsa_share <server 2 IP>:/nfs/exports/rhcsa_share' | sudo tee -a /etc/auto.rhcsa_share

The setup of these files will create mount point rhcsa_share under directory /nfs/autofs that points to Server Two.

autofs Service

The autofs service is disable by default, therefore it needs enabling and starting.

Enable and start the autofs service:

sudo systemctl enable --now autofs

Test the autofs Configuration

The autofs configuration is now complete so it is time to perform some tests.

Confirm you can connect successfully and perform actions against the remote share:

Ensure remote share rhcsa_share is currently not mounted:

df -h | grep '/nfs/autofs/rhcsa_share'

The above command should return nothing.

Change to the /nfs/autofs/rhcsa_share directory:

cd /nfs/autofs/rhcsa_share

Check if the remote share isn ow mounted:

df -h | grep '/nfs/autofs/rhcsa_share'

The output should show:

<server 2 IP>:/nfs/exports/rhcsa_share   10G  6.4G  3.7G  64% /nfs/autofs/rhcsa_share

If you followed along with the previous lesson, you would have uploaded gzip docs to the share. Confirm you can see these docs:

ls -lh

Output should show:

-rw-r--r--. 1 user1 user1   98 Aug  6 10:31 AUTHORS
-rw-r--r--. 1 user1 user1 111K Aug  6 10:31 ChangeLog
-rw-r--r--. 1 user1 user1  24K Aug  6 10:31 NEWS
-rw-r--r--. 1 user1 user1 6.0K Aug  6 10:31 README
-rw-r--r--. 1 user1 user1  13K Aug  6 10:31 THANKS
-rw-r--r--. 1 user1 user1 3.4K Aug  6 10:31 TODO

Confirm that you can remove a file:

rm -v TODO

Command output:

removed 'TODO'

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.