Tag Archives: raspberry pi

Setup your personal NFS Server on RPI in 6 Steps

Setting up NFS server on a raspberry is straight forward. But sometimes trivial things become a reason for headache when something goes wrong. I had the opportunity to work on a project where I needed to edit and compile binaries on RPI. As RPI is not a good candidate for an IDE so I mounted the whole home folder to my Ubuntu desktop and used eclipse IDE. It enabled me to access the code more easily, saving so much pain and time.

Today, I am going to share how can you enable NFS server on RPI and how to mount it on your linux system (read Ubuntu).

For RPI, my distro was raspbian but it should be almost similar for other distro’s too. Once you have got your RPI booted up and logged into the raspbian follow the steps below –

Step – 1 : Install NFS Kernel Driver into raspbian

As it is not installed by default, fire up a terminal and issue the following command

sudo apt-get install nfs-kernel-driver nfs-common

If you get complain that it cannot find nfs-kernel-driver then first issue the repo update command

sudo apt-get update

Step – 2 : Specify which path to export (Read share)

Now that you have installed the kernel driver, the setup process will generate a file  /etc/exports

To enable your desired path to be shared, open the file in your favorite editor and add some rules at the end of the file. The general rule can be described as –

<path-to-share> <allowed-client-ip-to-connect> (options)

So if I want to share /home/fadedreamz directory with everyone, I need to add the following rule to that file –

/home/fadedreamz * (rw,sync,no_subtree_check)

Remember, to avoid corruption it is best to use sync option. async is faster but very very dangerous, as it can cause data/fs corruption. * means that we will allow everybody (i,e it will match with any ip).

Step – 3: Restart the nfs server

This is straight forward

sudo service nfs-kernel-driver restart

At this point if you have no error then you can skip to Step – 5.

Step – 4: Troubleshoot nfs server

If you are having issue running the nfs server, which is stopping saying something is wrong with portmapper, then first try updating the rpcbind rules

sudo update-rc.d rpcbind defaults

Now try to start the nfs kernel server again

sudo service nfs-kernel-server restart

If this still fails due to the same goddamn’ portmapper then just restart the rpcbind service

sudo service rpcbind restart

And then try to start the nfs kernel server, now it should run without any issue.

sudo service nfs-kernel-server restart

Step – 5: Add mount rule for client

We want to mount it whenever we want. So, open up /etc/fstab file in your client pc and add the following rule (I am considering my exported path is /home/fadedreamz from Step – 2)

# format is 
# <server-ip>:<expoted-path> <mount-point> <file-system> <fs-options> <options> 
# so if our server-ip is 192.168.0.1 (for e,g) then following rule is needed
192.168.0.1:/home/faedreamz   /home/ubuntu/rpi   nfs4    users,_netdev,rw  0  0

Here users option will allow any user to mount the fs (without root permission). This is very convenient considering you can mount the fs from nautilus by clicking the auto created entry point (Read below to find more). # in the file is used to explain what is what, they are comments and will be ignored by the nfs-kernel-server.

Step – 6:  Mount the filesystem and enjoy

Just issue

sudo mount -a

in a terminal and enjoy the NFS fs in the mount point you specified earlier.

One benefit of using the mount point within the home directory is that nautilus (File Explorer) automatically create a sidebar entry which allow the user to navigate quickly and easily.

That’s it, you now have a full functioning NFS Server and a client connected to with. Now go edit your source code using powerful IDE and compile it instantly on RPI 🙂

Or you may choose to do whatever you like 🙂