Configuring NFS shares for the robot

From Robotic Agriculture Data Acquisition
Jump to: navigation, search

The easiest way to copy programs and log files to and from the robot is to use a NFS share located on a desktop computer in the lab, and have the robot connect to it. That will store all the files on the desktop so they are accessible when the robot is not used.

Client Side Configuration

To mount an NFS share on the client, simply run this command: sudo mount -t nfs ipaddress:/shared/directory /mount/location

With the following arguments:

  • ipaddress = IP address of the NFS server the share is hosted on
  • /shared/directory = The exported directory location configured on the server
  • /mount/location = The folder to mount the NFS share into on the robot

An example mount command is the following:

sudo mount -t nfs 192.168.0.196:/home/shared /mnt/nfs

This will mount a share located at /home/shared on computer 192.168.0.196 into the folder /mnt/nfs on the robot.

Possible Errors

mount.nfs: mount system call failed

If this error happens, verify the server networking settings are configured correctly (see Server Networking Configuration).

Server Side Configuration

NOTE: All these steps will require sudo privileges on the machine.

Networking Configuration

NOTE: Any RedHat machine configured by ETG will have an issue with the networking configuration described below. Anytime the computer is restarted or the network cycles (disconnects and reconnects), the custom entries in the /etc/hosts.allow file will be removed. Simply follow the steps below and re-add them if that is the case, or use the script system described in /etc/hosts.allow Networking Script.

Due to a bug in RedHat Linux, a networking file must be modified to allow the robot to connect to the computer's NFS shares. TO do that, follow these steps:

  1. Open a terminal by going to Applications->System Tools->Terminal
  2. Type sudo vi /etc/hosts.allow
    When prompted, type the user password
  3. Once the program opens, type 'i'
  4. Create a new line with the following format: ALL: ipaddress
    Example: ALL: 192.168.0.53
  5. Hit the escape key, then type 'wq'. This exits Vi and saves the file.

/etc/hosts.allow Networking Script

A system has been developed to overcome the issue presented by the resetting of /etc/hosts.allow after every reboot. It consists of two files:

computerAddresses

This file contains the IP addresses of every computer that should be in the /etc/hosts.allow file. Each address should be on its own line. A sample file is shown below

192.168.0.53
192.168.0.52

checkHosts.allow.sh

This file is the actual script that will run and add the addresses to the file if they are not there. It must be located in the same directory as the computerAddresses file, and it must have the executable option (chmod +x checkHosts.allow.sh will add it). The script may prompt for the user's sudo password when it adds an address to the hosts.allow file. The contents of the script are shown below.

#!/bin/bash
# This script will check the hosts.allow file to make sure it has entries for
# all the computers that must connect over NFS

# Read in the addresses from the file computerAddresses located in this same directory
# Iterate over each address and see if it exists in the hosts.allow file
for ADDRESS in $( cat computerAddresses );
do
    printf "Checking for %s......" $ADDRESS
    if [ -z "$( grep $ADDRESS /etc/hosts.allow )" ]
    then
        # The address was not found in the file
        printf "not found, adding to the file\n"
        
        # Create a command to run as root to add the address to the file
        COMMAND='echo ALL: '$ADDRESS' >> /etc/hosts.allow'
        sudo bash -c "$COMMAND"
    else
        printf "found in file\n"
    fi
done

The script will produce the following output (assuming 192.168.0.53 is already in the /etc/hosts.allow file and 192.168.0.52 is not):

Checking for 192.168.0.53......found in file
Checking for 192.168.0.52......not found, adding to the file

NFS Server Process Configuration

Configuration of the NFS daemon is done through the '/etc/exports' file. This file contains the description of all the shares hosted on the computer. To add a new share to the file, follow these steps:

  1. Open a terminal by going to Applications->System Tools->Terminal
  2. Type sudo vi /etc/exports
    When prompted, type the user password
  3. Once the program opens, type 'i'
  4. Create a new line with the following format: /shared/directory ipaddress/netmask(options)
    In general, the following should work for a lab computer's setup:
    /home/shared 192.168.0.0/255.255.255.0(rw,sync,fsid=0,no_subtree_check)
  5. Hit the escape key, then type 'wq'. This exits Vi and saves the file.
  6. Restart the NFS server running on the computer.
    For older Linux installs (init.d system): Type sudo /etc/init.d/nfs restart
    This command should produce several lines of output, the important ones say Starting ...: [ok] It is important that all those lines say 'ok', if they do not then there is an error somewhere. Verify the previous steps completed accurately and try again.
    For newer Linux installs (systemd system): Type sudo service nfs restart
    This command should produce only one line saying Redirecting to /bin/systemctl restart nfs.service. If it contains more lines, there may be errors present in the configuration. Verify the previous steps completed accurately and try again.

At this point, the NFS server should be configured correctly and clients can connect to it.