Skip to content

NFS Server Setup

When using a platform that supports Network Mode, OpenCPI uses NFS to share files between the development host and the embedded target platform. The development host is the NFS server and the embedded platform is the NFS client.

The development host will typically share the contents of the OpenCPI install directory, as well as any directories containing OpenCPI projects with assets that may be needed on the embedded platform.

NFS Configuration

Create a new .exports file in /etc/exports.d.

sudo gedit /etc/exports.d/user_ocpi.exports
Add a line to the file for each directory that will be shared over NFS using the format below.
<FULL_PATH_TO_DIRECTORY> <ALLOWED_IP>[/<ALLOWED_NETMASK>](rw,sync,no_root_squash,crossmnt)

An example is shown below.

/home/bob/opencpi/ 10.0.0.0/16(rw,sync,no_root_squash,crossmnt)
/home/bob/projects/ 10.0.2.0/24(rw,sync,no_root_squash,crossmnt)
/home/bob/private_projects/ 10.0.2.2(rw,sync,no_root_squash,crossmnt)
In the above example the opencpi directory is available to any IP in the range 10.0.X.X, the projects directory is available to 10.0.2.X, and the private_projects directory is only available to 10.0.2.2.

SELinux Configuration

If you are using SELinux (On by default on CentOS 7), then it is typically necessary to set the following boolean options:

sudo setsebool -P nfs_export_all_rw 1
sudo setsebool -P use_nfs_home_dirs 1

Firewall Configuration

To allow NFS through the firewall, use the following options.

sudo firewall-cmd --permanent --zone=public --add-service=nfs
sudo firewall-cmd --permanent --zone=public --add-port=2049/udp
sudo firewall-cmd --permanent --zone=public --add-service=mountd
sudo firewall-cmd --permanent --zone=public --add-service=rpc-bind
sudo firewall-cmd --reload
Note the exact commands many vary slightly depending on your existing firewall and network configuration.

Enable the NFS Server

To enable the NFS server run the following commands.

sudo systemctl enable rpcbind
sudo systemctl enable nfs-server
sudo systemctl enable nfs-lock
sudo systemctl enable nfs-idmap
sudo systemctl restart rpcbind
sudo systemctl restart nfs-server
sudo systemctl restart nfs-lock
sudo systemctl restart nfs-idmap

Note that the exact services needed may vary depending on which Linux distribution you are using. If any of the services fails to start, then it may not be required on your distribution.

Test the NFS Server

mkdir test_nfs_mnt
# mount -t nfs -o udp,nolock,soft,intr <NFS_SERVER_IP>:<FULL_PATH_OF_NFS_SHARE> test_mnt
sudo mount -t nfs -o udp,nolock,soft,intr 10.0.2.2:/home/bob/opencpi/ test_nfs_mnt
# Check you can read and write files on the NFS share
echo "TEST123" > test_nfs_mnt/nfs_test123.txt
cat test_nfs_mnt/nfs_test123.txt
rm test_nfs_mnt/nfs_test123.txt
sudo umount test_nfs_mnt
rm -r test_nfs_mnt