Skip to content

Setting up an NFS Share and Connecting it to a VM

Warning

NFS is currently only available upon request. Currently only the NFS protocol in version 4 over TCP is supported.

This guide will walk you through the process of creating a network, launching a VM, creating an NFS share, and making the share available to the VM using the OpenStack CLI.

Prerequisites

  • OpenStack CLI installed and configured
  • Access to SysEleven OpenStack Cloud
  • Sufficient permissions to create networks, VMs, and NFS shares

For more information on setting up the OpenStack CLI, refer to the OpenStack API Access guide.

Steps

1. Create a Network and Subnet

First, we'll create a network and subnet for our VM. For more detailed information on networking, see the Networks documentation.

openstack network create mynetwork
openstack subnet create --network mynetwork --subnet-range 192.168.1.0/24 mysubnet

2. Create a Router and Connect to External Network

Create a router and connect it to the external network and our new subnet:

openstack router create myrouter
openstack router set myrouter --external-gateway ext-net
openstack router add subnet myrouter mysubnet

3. Create an SSH Key

We'll need an SSH key to access our VM. For more details, see the SSH Keys documentation.

openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey

4. Launch a VM

Now, let's create a VM. For more information on creating servers, refer to the Servers documentation.

openstack server create --flavor m2c.tiny --image "Ubuntu 22.04" --key-name mykey --network mynetwork myvm

5. Configure Security Group

We need to allow SSH access to our VM. For more details on security groups, see the Security Groups documentation.

openstack security group create mysecgroup
openstack security group rule create --proto tcp --dst-port 22:22 --remote-ip 0.0.0.0/0 mysecgroup
openstack server add security group myvm mysecgroup

6. Assign a Floating IP

To access our VM from the internet, we need to assign a floating IP:

openstack floating ip create ext-net
openstack server add floating ip myvm <FLOATING_IP>

Replace <FLOATING_IP> with the actual IP address created in the previous step.

7. Create an NFS Share

Now, let's create an NFS share. For more information, see the NFS Shares documentation.

openstack share create --name myshare --share-type nfs NFS 10

8. Create a Network Port for NFS Access

NFS shares are available via the "nfs-net" network. To mount an NFS share inside a VM the VM requires access to this network. The easiest way to achieve this is to add a second network port to the VM. Your project needs shared access towards the "nfs-net", this can be setup by an cloud administrator, please contact our support team if you see issues creating a port in the "nfs-net" network inside of your project. A security group is not necessary for NFS as long as the default security group is used for the port. Please keep in mind that the "nfs-net" is dedicated to provide nfs shares and does not provide internet access. Network interfaces can be configured using DHCP. DHCP in this network will only provide an IP but not Gateway and no DNS server.

Create a port on the NFS network:

openstack port create --network nfs-net nfsport
openstack server add port myvm nfsport

9. Configure NFS Access

Allow access to the NFS share from our VM:

openstack share access create --access-level rw myshare ip <NFS_PORT_IP>

Replace <NFS_PORT_IP> with the IP address of the nfsport created in step 8.

10. Mount the NFS Share

Get the NFS share export location:

openstack share show myshare -c export_locations

Output:

+------------------+---------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                           |
+------------------+---------------------------------------------------------------------------------------------------------------------------------+
| export_locations |                                                                                                                                 |
|                  | id = 93027cb6-d73e-4373-8d12-dd4b8f9b4610                                                                                       |
|                  | path = nfs.dus2.cloud.syseleven.net:/volumes/_nogroup/28f13429-05d7-4f7d-8fe1-a76c672e2297/cf790fa7-55ab-4597-9d2d-b3c4657e67d3 |
|                  | preferred = False                                                                                                               |
+------------------+---------------------------------------------------------------------------------------------------------------------------------+

SSH into your VM and mount the NFS share:

ssh ubuntu@<FLOATING_IP>
sudo apt update && sudo apt install -y nfs-common
dhclient ens7 # replace ens7 with the correct interface

Mount the NFS share:

sudo mkdir /mnt/myshare
sudo mount -t nfs4 -o proto=tcp,port=2049 <EXPORT_LOCATION> /mnt/myshare

Replace <EXPORT_LOCATION> with the path from the previous command.

11. Test the NFS Share

Create a test file on the NFS share:

echo "Hello, NFS!" | sudo tee /mnt/myshare/testfile.txt
cat /mnt/myshare/testfile.txt

If you see "Hello, NFS!" output, your NFS share is working correctly.

Conclusion

You have successfully created a network, launched a VM, created an NFS share, and mounted it to your VM. By repeating the steps above, you can mount an NFS share to multiple VMs.