How to set up the Raspberry Pi as an NFS server
Posted: Mon Aug 27, 2012 11:05 am
After struggling for a few days on how to set up the Raspberry Pi as a NFS server (without Kerberos), I've finally worked it out. This information has been cobbled from here, the forums, and hours of Googling, but I'm putting this together in one location so that people can access it easily. I'm also unsure if future distros will set NFS as default, so I'm not going to put it in the wiki. If anyone wants to do this, feel free.
Add NFS version 4 to the Raspian kernel
The current version of the Raspian distro (2012-08-16-wheezy-raspbian) does not have NFS version 4 enabled for RPC. To check if your kernel has RPC support for NFS version 4, runIf you see a line with vers=4 and service=nfs, then you are good to go. If not, then you'll have to build a new kernel. (N.B. this takes about 12 hours if building directly on the Raspberry Pi, although you could cross-compile instead.) The general instructions are in the wiki. Modify the configuration directly after the "zcat /proc/config.gz > .config" step. Edit the .config file, by changing
to
Then follow the rest of the instructions. After the new kernel has installed, try "rpcinfo -p" again and confirm version 4 support.
Setting the Pi up as a NFS server
On the Pi, execute the following in the terminal. (Anything after a # is a comment, and you don't have to type it in.)
If the final line throws up an error
then you might need to enable rpcbind. You can do this immediately with
or on boot with
followed by a restart.
If, after "/etc/init.d/nfs-kernel-server restart", you get the following error
apparently NFS should still work, but you can make this go away with
I haven't explored how to automate the NFS setup on reboot, but I manually do the following after a boot.
On the (Linux) client
I think you could use the avahi name of the pi here instead of the ip address, but I have the pi set up with a static ip address anyway, so it doesn't bother me. To unmount, just use
I hope this guide helps someone! Post any questions you have, but I'm not sure how helpful I'll be, since I don't really understand most of what I've done here anyway!
Add NFS version 4 to the Raspian kernel
The current version of the Raspian distro (2012-08-16-wheezy-raspbian) does not have NFS version 4 enabled for RPC. To check if your kernel has RPC support for NFS version 4, run
Code: Select all
rpcinfo -pCode: Select all
CONFIG_NFSD=m
# CONFIG_NFSD_V3 is not set
# CONFIG_NFSD_V4 is not setCode: Select all
CONFIG_NFSD=y
CONFIG_NFSD_V2_ACL=y
CONFIG_NFSD_V3=y
CONFIG_NFSD_V3_ACL=y
CONFIG_NFSD_V4=ySetting the Pi up as a NFS server
On the Pi, execute the following in the terminal. (Anything after a # is a comment, and you don't have to type it in.)
Code: Select all
sudo su
apt-get install nfs-kernel-server
mkdir /export
mkdir /export/arbitrary_local_name_of_share # this name will be seen by clients accessing the share
mount --bind /path/to/folder/to/export /export/arbitrary_local_name_of_share
nano /etc/default/nfs-common
Change "NEED_IDMAPD=" to "NEED_IDMAPD=yes"
Change "NEED_GSSD=" to "NEED_GSSD=no"
nano /etc/exports # add the following line
/export 192.168.1.0/24(rw,fsid=0,insecure,no_subtree_check,async,crossmnt) # I had to use crossmnt otherwise I only saw empty directories from the client
/etc/init.d/nfs-kernel-server restartCode: Select all
exportfs: could not open /var/lib/nfs/.etab.lock for locking: errno 13 (Permission denied)
exportfs: can't lock /var/lib/nfs/etab for writing
exportfs: could not open /var/lib/nfs/.xtab.lock for locking: errno 13 (Permission denied)
exportfs: can't lock /var/lib/nfs/xtab for writing
. ok
[warn] Not starting NFS kernel daemon: no support in current kernel. ... (warning).Code: Select all
sudo service rpcbind startCode: Select all
sudo update-rc.d rpcbind enable && sudo update-rc.d nfs-common enableIf, after "/etc/init.d/nfs-kernel-server restart", you get the following error
Code: Select all
mountdrpc.mountd: svc_tli_create: could not open connection for udp6
rpc.mountd: svc_tli_create: could not open connection for tcp6
rpc.mountd: svc_tli_create: could not open connection for udp6
rpc.mountd: svc_tli_create: could not open connection for tcp6Code: Select all
sudo modprobe ipv6Code: Select all
sudo mount --bind /path/to/folder/to/export /export/arbitrary_local_name_of_share
Code: Select all
sudo mkdir /mnt/pi # only required the first time
sudo mount -t nfs4 -o proto=tcp,port=2049 ip.address.of.pi:/ /mnt/piCode: Select all
sudo umount /mnt/pi