Skip to main content

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

  1. Run sudo apt update
  2. Then sudo apt install nfs-kernel-server
  3. 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 using mkdir /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
  4. Run sudo nano /etc/exports
  5. 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 and CTRL + X to close).
  6. Run sudo exportfs -a
  7. Then sudo systemctl restart nfs-kernel-server
  8. 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.
  9. The server setup is complete.

Client Setup

  1. First run sudo apt update
  2. Then sudo apt install nfs-common
  3. Make a folder for the server to mount to mkdir /home/Ubuntu/storage
  4. Edit fstab by running sudo nano /etc/fstab. On a new line put server_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 and CTRL + X to close).
  5. 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)

Mascot