Note:

Use autofs on Oracle Linux 8

Introduction

The following tutorial provides step-by-step procedures to configure autofs to mount NFS shares. The benefit of autofs is the file system is mounted only when accessed.

Objectives

In this lab, you’ll:

What Do You Need?

The NFS server is provisioned automatically in the hands-on-Lab environment but needs to be created separately if running elsewhere. A tutorial on creating an NFS server is documented in Create an NFS server on Oracle Linux 8.

(Hands-on Lab) Connect to the Compute Instance

Note: This step is specific to the Oracle provided free lab environment.

The Desktop environment will display before the instance(s) are ready. Deployment of this environment can take two to five minutes, depending on the number of resources and provisioning steps needed.

First, to access the lab compute instance(s), connect to the Oracle Cloud Console and copy the compute instance Public IP address.

  1. Sign in to Oracle Cloud Console, and select your Compartment.

  2. Click Instances.

  3. Copy the Public IP to a temporary location (such as a text file) on your computer.

    copy public ip

    To copy, highlight the IP address with the mouse and press Ctrl+C.

  4. Right-click the Virtual Desktop and select Open Terminal Here.

  5. Connect to the instance.

    ssh -i ../.ssh/id_rsa oracle@<IP_ADDRESS_OF_COMPUTE_INSTANCE>
    

    Where <IP_ADDRESS_OF_COMPUTE_INSTANCE> is the IP address copied from the Oracle Cloud Console.

  6. Accept the ECDSA key fingerprint by typing yes at the prompt.

  7. You are now connected to the compute instance for this lab.

If the connection fails with the Permission denied (publickey,gssapi-keyex,gssapi-with-mic) message, wait a bit longer for the provisioning process to complete and try making the ssh connection again.

Install the autofs Package

  1. Open a terminal and connect to your client instance.

  2. Install the NFS utilities and autofs packages.

    sudo dnf install -y nfs-utils autofs
    

    This command will install the daemon and tools associated with the NFS client and automount function.

  3. Verify the autofs files exist in the /etc directory.

    ls -lh /etc/auto*
    

    autofs file listing

Create Mount Point

  1. Create a directory to use as the mount point for the autofs service.

    sudo mkdir /nfs-mount
    

Configure a Master Map File

This is the first of two files read by the autofs service. The master map file (/etc/auto.master) contains entries in the following format:

mount-point [map-type[,format]:]map [options]

Rather than edit the main file, the service also includes and reads files conforming to this format when placed in the /etc/auto.master.d directory.

  1. Add a Master Map Entry File to /etc/auto.master.d.

    echo "/nfs-mount  /etc/auto.mynfs  --timeout=180" | sudo tee /etc/auto.master.d/mynfs.autofs > /dev/null
    

    This entry defines the mount point as /nfs-mount and the map file as auto.mynfs. The share will automatically unmount after 180 seconds if there no action performed on the share. The file created has an extension of .autofs.

  2. Verify the entry.

    ls -lh /etc/auto.master.d
    cat /etc/auto.master.d/mynfs.autofs
    

    confirm changes

For more details, check out man auto.master.

Configure a Map File

This is the second file read by the autofs service. The map files contain entries using the following format:

mount-point mount-options location

  1. Create the map file /etc/auto.mynfs.

    echo "mynfs  -fstype=nfs,rw,soft,intr  <SERVER_IP_ADDRESS>:/nfs-share" | sudo tee /etc/auto.mynfs > /dev/null
    

    Where:

    • mynfs is a mount point.
    • -fstype=nfs is the file system type, and rw,soft,intr are mount options.
    • <SERVER_IP_ADDRESS> is the IP address of the server instance hosting the NFS server.
    • :/nfs-share is the NFS share.

For more details on the mount options, check out man mount.

Start Service

  1. Start and enable the autofs service in a single step.

    sudo systemctl enable --now autofs
    

    start autofs

Try to Access the Mount Point

The mount point for the NFS share is /nfs-mount/mynfs.

  1. Change to the mount point and get a directory listing.

    cd /nfs-mount/mynfs; ls -l
    

    get directory listing

  2. Get a file system disk usage report.

    df -Th
    

    df report

    The output shows the NFS share and the autofs mount point details.

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.