sparhawk
Posts: 8
Joined: Mon Aug 27, 2012 9:39 am

How to set up the Raspberry Pi as an NFS server

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, run

Code: Select all

rpcinfo -p
If 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

Code: Select all

CONFIG_NFSD=m
# CONFIG_NFSD_V3 is not set
# CONFIG_NFSD_V4 is not set
to

Code: Select all

CONFIG_NFSD=y
CONFIG_NFSD_V2_ACL=y
CONFIG_NFSD_V3=y
CONFIG_NFSD_V3_ACL=y
CONFIG_NFSD_V4=y
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.)

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 restart
If the final line throws up an error

Code: 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).
then you might need to enable rpcbind. You can do this immediately with

Code: Select all

sudo service rpcbind start
or on boot with

Code: Select all

sudo update-rc.d rpcbind enable && sudo update-rc.d nfs-common enable
followed by a restart.
If, 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 tcp6
apparently NFS should still work, but you can make this go away with

Code: Select all

sudo modprobe ipv6
I haven't explored how to automate the NFS setup on reboot, but I manually do the following after a boot.

Code: Select all

sudo mount --bind /path/to/folder/to/export /export/arbitrary_local_name_of_share
On the (Linux) client

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/pi
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

Code: Select all

sudo umount /mnt/pi
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!

Wm.A.Weezl
Posts: 12
Joined: Thu Oct 18, 2012 1:54 am

Re: How to set up the Raspberry Pi as an NFS server

Thu Oct 18, 2012 2:03 am

Thanks, it worked for me with Wheezy version of 2012-09-18.

I can confirm that you can use the avahi name in place of the IP address when you mount the nfs share on the client. When setting up the server (the Pi) I did have to issue
sudo service rpcbind start
but I didn't need to do the modprobe step.

Liquidant
Posts: 11
Joined: Thu Jan 10, 2013 6:28 pm

Re: How to set up the Raspberry Pi as an NFS server

Mon Apr 15, 2013 4:43 pm

Thanks for this.
I have my NFS server up and running great.

I do have a some problems though i'm hopping you might be able to help with.

I have 3 folders I want to share to 2 other Rpi's.

1 is local the other is at my girlfriends house.

I have done the following in the /etc/exports file
sudo nano /etc/exports

/exoport/movies 192.168.0.0/24(rw,fsid=0,insecure,no_subtree_check,async,crossmnt)
/export/TV 192.168.0.0/24(rw,fsid=0,insecure,no_subtree_check,async,crossmnt)
once the rest of the guide is followed both directories point to only one location..... movies

should I mount --bind both directories or is there something else i should be doing ?


EDIT:

I managed to sort this out.

I all ready have the external drive mounted to an RPi /mnt/usb

I edited the /etc/exports file to use this.
/mnt/usb/Movies 192.168.0.0/24(ro.nohide,crossmnt)
/mnt/usb/TV 192.168.0.0/24(ro,nohide,crossmnt)
restarted both nfs-kernel and rpcbind

my 2nd local RPi now sees both folders

seeing as port 2049 is port forwarded to my RPi with the external HDD connected I assume the RPi at my girlfriends will connect with no problems once I enter my ip address.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to set up the Raspberry Pi as an NFS server

Mon Apr 15, 2013 5:06 pm

Just out of curiosity, what is the reason for wanting to do this?

Note that I am not in any way saying that this is a bad thing, or asserting that there is no good reason to want to do it.

My question is more along the lines of:

1) Who is your intended audience? Who do you think would benefit from setting up the Pi as an NFS server?

2) Why wouldn't most people want to use, say, Samba, instead? Is NFS more, or less, efficient than Samba?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

sparhawk
Posts: 8
Joined: Mon Aug 27, 2012 9:39 am

Re: How to set up the Raspberry Pi as an NFS server

Tue Apr 16, 2013 1:39 am

@Joe Schmoe, are you talking to me or to Liquidant?

If me, then NFS is faster and less resource-intensive than samba. Hence my intended audience is anyone who wants better speed and less resource drain! :shock:

(However, I'm not sure how well Windows works with NFS.)

Liquidant
Posts: 11
Joined: Thu Jan 10, 2013 6:28 pm

Re: How to set up the Raspberry Pi as an NFS server

Sat Apr 20, 2013 10:17 am

I tried samba and all though it worked nice on the local network if I wanted to connect from anywhere else like a friends house I needed to do it via a VPN. Both worked on the RPi but it was a bit to much.
It was recommended to use NFS and have my drive formatted to ext

I've now got the NFS server running with 3 shares on my ext formatted external drive.

As I mentioned above the 3 shares where all pointing to 1 folder so I changed the /etc/exports

I have now found out that although this works with the RPi it does not work with windows

I changed back to

Code: Select all

/mnt/usb/Movies      192.168.0.0/24(ro,insecure,no_subtree_check,async,crossmnt)
/mnt/usb/TVShows     192.168.0.0/24(ro,insecure,no_subtree_check,async,crossmnt) 
I changed it to ro and removed fsid=0

it now points to all 3 shares on both my RPi running raspbmc and my PC running xbmc.


I also have the RPi running a twonky server so I can stream my movies to any device in my house and even over 3G or a friends wireless.

Return to “Beginners”