This tutorial will guide you through mounting a Network File System (NFS) volume on a Linux-based system. It is intended for administrators who want to learn how to mount this volume.
Although the package installation commands are specific to Debian-based systems, they can be adapted to the distribution of your choice by substituting the appropriate package management calls and package names.
Ensure that:
you have the appropriate access rights to mount NFS volumes.
you have the following details: IONOS_TOKEN
and NFS_CLUSTER_UUID
. You can retrieve them from the DCD or using the API.
The following example assumes that your cluster is located in Berlin, Germany. You must use the appropriate endpoint if the cluster is located elsewhere.
1.1. Execute the following command to retrieve the IP address of an NFS cluster:
Note: Remember to replace IONOS_TOKEN
and NFS_CLUSTER_UUID
with your authentication token and the NFS Cluster UUID, respectively.
Command
Description
NFS_CLUSTER_IP
This is the name of the environment variable being set.
-H 'accept: application/json'
This option specifies the Accept header to be used in the request, which is set to application/json to indicate that the client expects the response to be in JSON format.
-H "Authorization: Bearer ${IONOS_TOKEN}"
Specifies the Authorization header to be used in the request, which includes the IONOS API token.
https://nfs.de-txl.ionos.com/clusters/${NFS_CLUSTER_UUID}
The URL of the IONOS API endpoint that provides information about the NFS cluster.
jq .properties.connections[].ipAddress
The command-line JSON processor jq
that is used to parse the JSON response from the IONOS API and extract the IP address of the NFS cluster.
Result: Upon execution, the command makes an HTTP request to the IONOS API, retrieves the IP address of the NFS cluster, and exports it as an environment variable named NFS_CLUSTER_IP
, which can then be used in subsequent commands to mount the NFS cluster.
1.2. Execute the following command to retrieve the first NFS share path of an NFS cluster:
Note: Remember to replace IONOS_TOKEN
and NFS_CLUSTER_UUID
with your authentication token and the NFS Cluster UUID, respectively.
Command
Description
NFS_SHARE
The name of the environment variable being set.
https://nfs.de-txl.ionos.com/clusters/${NFS_CLUSTER_UUID}/shares
The URL of the IONOS API endpoint that provides information about the NFS shares of the specified cluster.
Result: Upon execution, the command makes an HTTP request to the IONOS API, retrieves the NFS share path of the first share, and exports it as an environment variable named NFS_SHARE
.
2.1. On the NFS client, open a command window, and install and configure the NFS client nfs-common
, and the necessary packages for an NFS client on a Linux system, specifically on Debian-based distributions, such as Ubuntu:
apt-get update && apt-get -y install nfs-common autofs
Command
Description
apt-get update
The command updates the package list on the system, ensuring that the package manager has the latest information about available packages and their versions.
apt-get -y install nfs-common autofs
The command installs new packages or updates existing ones.
-y
The flag automatically answers "yes" to any prompts that might appear during the installation.
nfs-common
The package provides common files and programs for NFS, including the mount.nfs
command.
autofs
The package provides a tool for automatically mounting and unmounting file systems when they are accessed.
2.2. Create directories that can be used as mount points for an NFS on a Linux client machine using the following command:
mkdir -p /mnt/nfs-cluster /data/nfs-cluster
Command
Description
mkdir
A command-line tool used to create new directories.
-p
This option stands for "parents" and indicates mkdir
to create the parent directories if they do not already exist.
/mnt/nfs-cluster
This is the first directory created in the /mnt
directory, a common location for mounting file systems.
/data/nfs-cluster
This is the second directory that will be created in the /data
directory.
Result: The command creates the following directories: /mnt
, /mnt/nfs-cluster
, /data
, and /data/nfs-cluster
.
2.3. Mount an NFS on a Linux client machine:
mount -t nfs ${NFS_CLUSTER_IP}:${NFS_SHARE} /mnt/nfs-cluster
Command
Description
mount
A command-line tool used to attach a file system to a directory on a Linux system.
t nfs
This option specifies the type of file system to be mounted, which in this case is an NFS.
${NFS_CLUSTER_IP}
This is the IP address of the NFS server or cluster exporting the file system. Remember to replace it with a valid IP address.
${NFS_SHARE}
This is the name of the exported file system or share you want to mount. Remember to mention the appropriate share.
/mnt/nfs-cluster
This is the mount point on the client machine where the NFS will be attached.
Result: Upon execution, the NFS exported by the server at ${NFS_CLUSTER_IP}
is mounted to the /mnt/nfs-cluster
directory on the client machine.
autofs
Alternatively, use autofs
to mount the share(s) on-demand:
1. The following command adds an entry to the /etc/auto.master
file, the main configuration file for the autofs
service. The entry / - /etc/auto.nfs
tells autofs
to use the /etc/auto.nfs
file as the configuration file for the mount point:
echo "/- /etc/auto.nfs" >> /etc/auto.master
Result: When you / - /etc/auto.nfs
entry to the /etc/auto.master
file, autofs
uses the /etc/auto.nfs
file as the configuration file for the / mount point, which allows autofs
to mount the NFS share automatically when the /mnt/nfs-cluster
directory is accessed.
2. Execute the following command to create a new file called /etc/auto.nfs
with a single entry that defines an NFS share to be mounted under the /data/nfs-cluster
directory:
echo "/data/nfs-cluster ${NFS_CLUSTER_IP}:${NFS_SHARE}" > /etc/auto.nfs
The entry "/data/nfs-cluster ${NFS_CLUSTER_IP}:${NFS_SHARE}"
defines an NFS share to be mounted under the /data/nfs-cluster
directory. The ${NFS_CLUSTER_IP}:${NFS_SHARE}
specifies the IP address and share name of the NFS server.
Note: Remember to replace the ${NFS_CLUSTER_IP}
and ${NFS_SHARE}
with the IP address and share UUID of the NFS server.
This command is typically used with the autofs
service, which is a Linux service that automatically mounts and unmounts file systems based on the contents of the /etc/auto.master
and /etc/auto.nfs
files.
Result: The entry in the /etc/auto.nfs
file indicates the autofs
to mount the NFS share at ${NFS_CLUSTER_IP}:${NFS_SHARE}
under the /data/nfs-cluster
directory. When the /data/nfs-cluster
directory is accessed, autofs
automatically mounts the NFS share.
3. Restart the autofs
service on a Linux system using the following command:
service autofs restart
Note: The exact command to restart the autofs
service may vary depending on the Linux distribution being used.
Restarting the autofs
service is typically necessary after making changes to the configuration files, such as adding or removing entries, or updating the IP address or share name of an NFS server. It re-reads the configuration files (/etc/auto.master
and /etc/auto.nfs
) and refreshes the list of automatically mounted file systems to ensure that the changes take effect and that the automatically mounted file systems are updated accordingly.
In this tutorial, you have learned how to successfully mount an NFS volume and share it on Debian-based Systems.
Here is a pivotal use case you can implement after configuring the Network File Storage via the DCD or the API: