Mount a Network File System Volume on Debian-based Systems
5 min
overview this tutorial will guide you through mounting a network file system (nfs) volume on a linux based system 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 prerequisites 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 target audience this tutorial is intended for administrators who want to learn how to mount this volume what you will learn by the end of this tutorial, you will learn to mount an nfs volume on debian based systems for efficient and scalable file storage solutions procedure retrieve the ip address and nfs share path retrieve the ip address and nfs share path of an nfs cluster from the api and export it as an environment variable the following example assumes that your cluster is located in berlin, germany you must use the appropriate endpoint https //docs ionos com/cloud/backup and storage/network file storage/api how tos if the cluster is located elsewhere 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 export nfs cluster ip=`curl s x get h 'accept application/json' h "authorization bearer ${ionos token}" https //nfs de txl ionos com/clusters/${nfs cluster uuid} | jq properties connections\[] ipaddress | cut c2 | cut d'/' f 1` 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 api token https //nfs de txl ionos com/clusters/${nfs cluster uuid} the url of the 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 api and extract the ip address of the nfs cluster expected result upon execution, the command makes an http request to the 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 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 export nfs share=`curl s x get h 'accept application/json' h "authorization bearer ${ionos token}" https //nfs de txl ionos com/clusters/${nfs cluster uuid}/shares | jq items\[0] metadata nfspath | cut d'"' f2` 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 api endpoint that provides information about the nfs shares of the specified cluster expected result upon execution, the command makes an http request to the api, retrieves the nfs share path of the first share, and exports it as an environment variable named nfs share install and configure the nfs client and the necessary packages 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 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 expected result the command creates the following directories /mnt , /mnt/nfs cluster , /data , and /data/nfs cluster 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 expected 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 optionally, mount the share(s) using 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 expected 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 note remember to replace the ${nfs cluster ip} and ${nfs share} with the ip address and share uuid of the nfs server 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 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 expected 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 final result after following this tutorial, your debian based system should have the nfs volume mounted and accessible at the specified mount points you can now read and write files to the nfs share, enabling efficient and scalable network file storage for your applications and users conclusion in this tutorial, you have learned how to successfully mount an nfs volume and share it on debian based systems
