19.1 Networks: Mounting Network Filesystems

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.

Using NFS Commands

To use nfs and it’s commands we must first install nfs-utils this will add some small functionality to our NFS mounting commands:

dnf install nfs-utils

You should just get a completed message.

nfs discovery

To find an nfs mount you can do a scan, on the host machine with the showmount command:

showmount -e server

Result:

[root@rhcsa ~]# showmount -e server
Export list for server:
/mnt/users 10.0.1.0/24
/mnt/rhcsa-nfs   10.0.1.0/24

This tell’s us that the server server is exporting 2 NFS shares for us to connect with.

nfs mount

To mount an nfs share it is made to look and work nearly exactly the same as a disk mount, mount server:/location /mountpoint like this the : seperates the server and mountlocation on the server.

First however that directory must exist:

mkdir -p /mnt/nfs

Now we can mount the nfs share:

mount server:/mnt/rhcsa-nfs /mnt/nfs

Go to the nfs share mount:

cd /mnt/nfs

Check the contents of the share:

ll

See if we can read the file:

cat /mnt/nfs/hello

Cthulu be blessed.

nfs fstab

Adding NFS to the fstab is simple!

server:/mnt/rhcsa-nfs /mnt/nfs  nfs      _netdev    0       0

To test the mount.

mount -va

Wouw it all works great! (hypotheticly)

autofs

Since Red Hat 7 they introduced the system called autofs this will when you enter the location of a network mount automaticly mount the share for you. This will increase performance as you get the share only when you need it:

To use autofs we need to follow the following steps:

  1. Install and enable autofs

  2. Create the automount file

  3. Create the nfs mount command file

1. Install autofs

Install autofs (your system probably already has it):

dnf install autofs -y

2. Create the automount file

To use autofs we need to make a file at the location /etc/auto.master.d the file must end with .autofs the rest of the name matters little:

So let’s create the file /etc/auto.master.d/home.autofs

vim /etc/auto.master.d/home.autofs

Give it the following entry:

/mnt/users /etc/auto.home

In this case:
/mnt/users is the location we want to automount.
/etc/auto.home is the location of the nfs mount command. Next we must create the /etc/auto.home file with the mount command.

3. Create the nfs mount command file

We will create the file /etc/auto.home:

vim /etc/auto.home

Add the following entry:

* -rw,sync server:/mnt/users/&

This does the following.

  • * Means the local mount point.

  • -rw,sync Mount nfs Read Write and Sync the disk immidiatly with every write.

  • server:/home/guests/ The mount server and nfs share location.

  • & Request the nfs mount location matching the directory you are accessing. Like a wild card.

Now we have a wildcard mount for multiple users.

Start the autofs server

Start and enable autofs:

systemctl enable autofs && systemctl start autofs

You can check with:

ls /mnt/users

You probably see that the directory is empty.

However there are 2 multi-mounts available:

  • andrew

  • susan

cd /mnt/users/susan

Now by accessing the automount will mount that specific location, with the file susanfile.

Same for andrew directory:

cd /mnt/users/andrew

With a file susanfile.