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: Mount and Unmount Network File Systems Using NFS

NFS Overview

The Network File System (NFS) is a distributed file protocol that enables seamless sharing of files and directories across a network of computers. Developed by Sun Microsystems, NFS allows clients to access remote files as if they were local, facilitating efficient collaboration and data sharing in a heterogeneous computing environment. It operates on the client-server model, where the server exports specific directories to be accessed by authorized clients, providing a transparent and standardized method for remote file access and management.

Lesson Setup (NFS Server)

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

Mounting and Unmounting NFS Shares

Server one is to be used for the remainder of the lesson.

To mount an NFS share you need to see what shared locations have been made available. The showmount command is used to do this and is a part of the nfs-utils package which will need installing.

Check what shared locations are available:

Install nfs-utils package:

sudo dnf -y install nfs-utils

Check for available shares on server two. The -e flag is used to show the NFS server's export list:

showmount -e <server two IP>

Expected output:

/nfs/exports/rhcsa_share *

A mount point needs creating where you wish the available share to be mounted at:

Create NFS Share mount point:

sudo mkdir -pv /nfs/imports/rhcsa_share

Command output:

mkdir: created directory '/nfs'
mkdir: created directory '/nfs/imports'
mkdir: created directory '/nfs/imports/rhcsa_share'

You will now need to test that mounting of the share works:

Mount NFS share:

Mount NFS share /nfs/exports/rhcsa_share to local mount point /nfs/imports/rhcsa_share:

sudo mount <server two IP>:/nfs/exports/rhcsa_share /nfs/imports/rhcsa_share

Confirm NFS share is mounted:

df -h /nfs/imports/rhcsa_share

Command output:

Filesystem                                        Size  Used Avail Use% Mounted on
<server two IP>:/nfs/exports/rhcsa_share   10G  6.4G  3.7G  64% /nfs/imports/rhcsa_share

Confirm access to the share is working:

# Change to share directory
cd /nfs/imports/rhcsa_share

# Copy files to share
cp -v /usr/share/doc/gzip/* ./

# List contents of share
ls -lh

Output from the cp and ls commands above should be similar to:

# cp output
'/usr/share/doc/gzip/AUTHORS' -> './AUTHORS'
'/usr/share/doc/gzip/ChangeLog' -> './ChangeLog'
'/usr/share/doc/gzip/NEWS' -> './NEWS'
'/usr/share/doc/gzip/README' -> './README'
'/usr/share/doc/gzip/THANKS' -> './THANKS'
'/usr/share/doc/gzip/TODO' -> './TODO'

# ls output
-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

Now the share has been proven to mount ok, it is time to unmount the share:

Unmount NFS share:

Ensure you are not in the share directory from previous exercise:

# Change to home dir
cd

unmount NFS share:

sudo umount -v /nfs/imports/rhcsa_share

Command output:

/nfs/imports/rhcsa_share: nfs4 mount point detected
/nfs/imports/rhcsa_share: umounted

In the previous exercises the share was mounted manually, but you will want the share to mount persistently for the exam through the /etc/fstab file.

Persistently mount an NFS share:

Update /etc/fstab with NFS entry:

echo '<Server 2 IP>:/nfs/exports/rhcsa_share /nfs/imports/rhcsa_share nfs rw 0 0' | sudo tee -a /etc/fstab

Reload systemd daemon:

sudo systemctl daemon-reload

Confirm entry is valid:

sudo findmnt --verify /nfs/imports/rhcsa_share

Command output:

Success, no errors or warnings detected

Mount the NFS share:

sudo mount -v /nfs/imports/rhcsa_share

Command output:

mount.nfs: timeout set for Sun Aug  6 10:47:41 2023
mount.nfs: trying text-based options 'vers=4.2,addr=<server 2 IP,clientaddr=<server 1 IP>'

Confirm NFS share is mounted:

df -h /nfs/imports/rhcsa_share

Command output:

Filesystem                                        Size  Used Avail Use% Mounted on
<server two IP>:/nfs/exports/rhcsa_share   10G  6.4G  3.7G  64% /nfs/imports/rhcsa_share

Lesson Tidy Up

If your Server Two gets switched off, for example if you only switch it on when a lesson requires, then ensure you comment out the /etc/fstab entry for the NFS share. If you do not do this, when you reboot or start up Server One you will have a delay in the start up whilst connection to the NFS share waits and times out.

Disable NFS mounting from /etc/fstab:

sudo sed -i.$(date +%Y%m%d%H%M) '/rhcsa_share/s/^/#/' /etc/fstab
sudo systemctl daemon-reload


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.