Skip to content

Setting Up an NFS Server and Accessing it from VMs in OpenStack

In environments like the Barcelona Supercomputing Center (BSC), where OpenStack volumes do not support multi-attachment, sharing data across multiple virtual machines (VMs) can be challenging. A Network File System (NFS) server provides a useful workaround by allowing multiple VMs to access the same file system over the network.

This guide explains how to set up an NFS server and how to mount the shared directory on OpenStack VMs.


πŸ” OpenStack Security Group Rules for NFS Access

When setting up an NFS server and clients inside OpenStack, make sure your security group allows the necessary traffic.

Here’s a complete set of Ingress rules to configure via the OpenStack Dashboard > Network > Security Groups:

πŸ”½ Ingress Rules (on the NFS Server)

Direction Ether Type Protocol Port Range Remote IP CIDR
Ingress IPv4 TCP 111 192.168.0.0/24
Ingress IPv4 UDP 111 192.168.0.0/24
Ingress IPv4 TCP 2049 192.168.0.0/24
Ingress IPv4 UDP 2049 192.168.0.0/24
Ingress IPv4 TCP 20048 192.168.0.0/24
Ingress IPv4 UDP 20048 192.168.0.0/24

πŸ› οΈ Step 1: Set Up the NFS Server

On the NFS Server VM

  1. Install NFS server packages

For Debian/Ubuntu:

sudo apt update
sudo apt install nfs-kernel-server -y

For RHEL/CentOS:

sudo yum install nfs-utils -y
sudo systemctl enable --now nfs-server
  1. Create a shared directory
sudo mkdir -p /mnt/nfs_share
sudo chown nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
  1. Configure /etc/exports

Add the following line to /etc/exports to allow access from your VM subnet (e.g., 192.168.0.0/24):

/mnt/nfs_share 192.168.0.0/24(rw,sync,no_subtree_check)
  1. Apply the export configuration
sudo exportfs -rav
  1. Enable firewall rules (if applicable)
sudo ufw allow from 192.168.0.0/24 to any port nfs

πŸ–₯️ Step 2: Access the NFS Share from OpenStack VMs

On Each Client VM

  1. Install NFS client

For Debian/Ubuntu:

sudo apt update
sudo apt install nfs-common -y

For RHEL/CentOS:

sudo yum install nfs-utils -y
  1. Create a mount point
sudo mkdir -p /mnt/nfs_clientshare
  1. Mount the NFS share

Replace NFS_SERVER_IP with your NFS server’s IP address:

sudo mount NFS_SERVER_IP:/mnt/nfs_share /mnt/nfs_clientshare
  1. Make the mount persistent (optional)

Add the following line to /etc/fstab:

NFS_SERVER_IP:/mnt/nfs_share /mnt/nfs_clientshare nfs defaults 0 0