NFS Mount
This tutorial will go over the Why
and How
to setup an NFS mount between instances on Massed Compute.
Why would you want to NFS Mount
The primary reason to NFS mount one server directory to another instance is to access and interact with file systems over a network as if they were mounted locally. This has several benefits but the key ones for us
- Shared storage
- Remote access
- Resource consolidation
Lets say you are looking for a persistent storage option and don't want to constantly pay for a GPU instance. You can use a CPU node as your persistent storage and NFS mount a folder from the CPU node onto each GPU instance you deploy to share data.
How can you setup an NFS mount
These instructions are done in two parts. The terminology we will use will be server
and client
The server
in our case is going to be our persistent storage and the client
will be any target instance we will NFS mount our storage instance on.
Server Setup
- Run
sudo apt update
- Then
sudo apt install nfs-kernel-server
- Determine which folder or folders you want to share with your client instance. We would recommend sharing all of
/home/Ubuntu
or making a new folder usingmkdir /home/Ubuntu/data
. The rest of the example we will use/home/Ubuntu/data
as the folder we want to mount to any additional client - Run
sudo nano /etc/exports
- Add a new line that is setup like this
/path/to/foler client_ip(rw,sync,no_subtree_check)
in our example/path/to/folder
would be/home/Ubuntu/data
and the client_ip would be the IP address of your client instance. Once the line is added save and close the file (CTRL + O
to save andCTRL + X
to close). - Run
sudo exportfs -a
- Then
sudo systemctl restart nfs-kernel-server
- We need to update some firewall rules so run
sudo ufw allow from client_ip to any port nfs
replace client_ip with the IP address of your client instance. - The server setup is complete.
Client Setup
- First run
sudo apt update
- Then
sudo apt install nfs-common
- Make a folder for the server to mount to
mkdir /home/Ubuntu/storage
- Edit fstab by running
sudo nano /etc/fstab
. On a new line putserver_ip:/home/Ubuntu/data /home/Ubuntu/storage nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,nconnect=16 0 0
. Remember to replace server_ip with the IP address of your server instance from above. Save and close the file (CTRL + O
to save andCTRL + X
to close). - Finally run
sudo mount -a
Once this setup is complete you can then drop a file in /home/Ubuntu/data
on you rserver instance and see it show up at /home/Ubuntu/storage
on your client instance.
If you want to add more instances or you terminate your client and reprovision a new instance, repeat steps 5-9 on the Server Setup instructions above and all of the Client Setup on the new client instance.
Recommendation
It is recommended for you to update /etc/exports
on the server setup to comment out any link you create on a client instance that you terminate. Meaning when you terminate a client instance, it is recommended to update /etc/exports
on the server (line 4 & 5 of Server Setup)