File sharing Mac to RPi


Some notes on very basic file sharing between Mac and Pi. The idea here is to have files (e.g. code under development) on the Mac rather than on the RPi file system.

Using NFS

Using NFS as it is simple and “native” to unix systems. You will notice that there is no user authentication involved so while this is OK for a personal development environment it is not suitable for a network where there might be untrusted users.

Creating a share on the Mac

In summary:
  1. Select the folder you want to share and list it in /etc/exports.
  2. Tell nfsd to start sharing

A comfortable route is to use Bresink’s NFSManager to configure this. Alternatively roll up your sleeves, read the man pages etc. (e.g. HT4695, exports, nfsd).

Here is an example exports file line:
/Users/nickbirch/Documents/RaspberryPi -alldirs -mapall=507 -sec=sys:krb5 10.1.2.11

The folder to export:
/Users/nickbirch/Documents/RaspberryPi

Allow the share to b mounted at any subdirectory:
-alldirs

Map the userid on the client (the RPi in this case) to the user id on the Mac (this ensures the RPi has normal R/W access to the files in the share). In this case my user ID on the Mac is 507. Use “ls -ln” on one of your files to see what user id you have:
-mapall=507

Random security settings. Unless you run a kerberos authentication server to manage single sign on you don’t really need this:
-sec=sys:krb5

Limit access to the share to a single IP address (the address of the RPi in this case). This provides some security:
10.1.2.11

Now tell nfsd that you have edited the /etc/exports file:
nfsd checkexports


Mounting the Share on the Raspberry Pi

In summary:
  1. Create a mount point
  2. Mount the exported file system

The “mount point” is just a directory on the RPi file system to which the exported directories will be attached. For example to create a directory “imac” in the pi user’s home directory as the mount point:
cd
mkdir /home/pi/imac

Now mount the export on to the mount point:
sudo mount 10.1.2.6:/Users/nickbirch/Documents/RaspberryPi /home/pi/imac/ -o nolock

“sudo” run the command as root

“mount” the mount command

“10.1.2.6:” specify the computer exporting the files

“/Users/nickbirch/Documents/RaspberryPi” the share on the computer

“./imac/“ where to mount the files

“-o no lock” needed to make it work! Otherwise you get a message “Either use '-o nolock' to keep locks local, or start statd.”. See the mount man page for more info.


Before running mount “df” lists the file systems as follows:

pi@raspberrypi ~ $ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 1804128 1555064 157416 91% /
/dev/root 1804128 1555064 157416 91% /
tmpfs 18808 208 18600 2% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 37616 4 37612 1% /tmp
tmpfs 10240 0 10240 0% /dev
tmpfs 37616 0 37616 0% /run/shm
/dev/mmcblk0p1 57288 34560 22728 61% /boot

After running mount we see the following:

pi@raspberrypi ~ $ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 1804128 1555064 157416 91% /
/dev/root 1804128 1555064 157416 91% /
tmpfs 18808 212 18596 2% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 37616 4 37612 1% /tmp
tmpfs 10240 0 10240 0% /dev
tmpfs 37616 0 37616 0% /run/shm
/dev/mmcblk0p1 57288 34560 22728 61% /boot
10.1.2.6:/Users/nickbirch/Documents/RaspberryPi/ 1875000064 783927104 1090816960 42% /home/pi/imac

This mount is volatile and will be forgotten when you next boot the RPi. To make it permanent roughly the same arguments as we use for mount are placed in the /etc/fstab file:

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 0
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
10.1.2.6:/Users/nickbirch/Documents/RaspberryPi /home/pi/imac/ nfs nolock 0 0

There are numerous options for mount & fstab (e.g. see nfs). For example, to force use of TCP protocol rather than UDP the “proto=tcp” option can be used.

In mount:
sudo mount 10.1.2.6:/Users/nickbirch/Documents/RaspberryPi /home/pi/imac/ -o nolock,proto=tcp

In /etc/fstab:
10.1.2.6:/Users/nickbirch/Documents/RaspberryPi /home/pi/imac/ nfs nolock,proto=tcp 0 0


Performance test

Time copying a video file on the share to /dev/null:
pi@raspberrypi ~ $ ls -l imac/TestFolder/test.mov
-rw-r--r-- 1 507 507 192370357 Apr 20 2008 imac/TestFolder/test.mov

pi@raspberrypi ~ $ time cp imac/TestFolder/test.mov /dev/null

real 0m19.579s
user 0m0.010s
sys 0m3.970s

The file copies to /dev/null in 19.6 seconds. This gives a transfer rate of about 78 Mbps (bits per second) which is probably reasonable given the 100 Mbps ethernet interface on the RPi.

Copying the same file to the FLASH card on the RPi takes about twice as long:

pi@raspberrypi ~ $ time cp imac/TestFolder/test.mov cptest.mov

real 0m34.963s
user 0m0.040s
sys 0m8.340s