Tech Projects, Reviews, Howtos, Linux Fun, And Anything On My Mind.

How-to setup NFS shares in debian

This is a re-write of malco2001's (HOWTO: NFS Server/Client) from the ubuntu forums.
The original How-to can be found here

Step-1 Install NFS Server Support On The Machine that will Host The Share

at the terminal type:
sudo apt-get install nfs-kernel-server nfs-common portmap
(This installs the needed software)

sudo dpkg-reconfigure portmap
(chose "no" do not bind loopback)

sudo /etc/init.d/portmap restart
(restarts the portmap service)

At this point you should choose were you want the folder that you want to share. Or an existing folder, like your Music folder. In my example coming up I chose to make a folder called "shares" in my home directory.

Step-2 Editing /etc/exports

The export file is used to tell the system which folders to share, and how they are shared.

In the terminal type:
sudo gedit /etc/exports
(This opens the file with gedit. you can use any text editor you want like; vi, vim, nano. Or type "sudo apt-get install gedit".)

At the end of the file add this line, except replace the [] with your info
/home/[username]/[name of file you want to share] [your routers ip]/24(rw,no_root_squash,async)
(example: /home/darren/shares 192.168.0.1/24(rw,no_root_squash,async) after save the file. )

In the terminal type:
sudo /etc/init.d/nfs-kernel-server restart
(after changing the export file you need to restart the nfs server)

Then Type:
sudo exportfs -a
(You have to enter this command to set your changes)

Then type:
sudo /etc/init.d/portmap restart
(This ensures that the path to the share is set)

*If you get any error while going through Step-1, go back and check the edits you made. It is very easy to mis a step or even just one letter. "Rinse Lather Repeat" as the saying goes.

And your done on this machine!!!

Step-3 Installing NFS Client Support On The Other System

In step-1 we installed both server and client software, I recomend doing the same on this system as well. this will save you time if you chose to host a share on this system as well. If you chose not to this is all you need.

In the terminal type:
sudo apt-get install portmap nfs-common
(this installs the the needed software)

In the terminal type:
sudo dpkd-reconfigure portmap
(Just like you did on your host system, chose "no")

In the terminal type:
sudo /etc/init.d/portmap restart
(this restarts portmap)

Now you just need to make the folder were the share will be mounted in. you can put this anywere you want. If you chose to share your music folder, you might want to put the folder in your music folder. Example: /home/darren/music/sharedmusic. Were "sharedmusic" is the name of the new folder. just make sure you know the full path to the file.

in my example I made a folder called "sharefolder"

Step-4 The Test

In your terminal replacing the [] with your info type:
sudo mount [HostsIP]:/[path to hosts share] [path to your mount folder]
(example: sudo mount 192.168.0.109:/home/darren/shares /home/darren/sharefolder )

You may need to restart your services. In the terminal type:
sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-common restart

If you do not get any errors it means that it worked. You can go to your new mounted share folder. If not "Rinse Lather Repeat".

If you restart your system you will need to re-enter:
sudo mount [HostsIP]:/[path to hosts share] [path to your mount folder]

In the original How-To, the guide showed you how to set your system to auto mount your shares by editing your "fstab" file. To be honest I could not get this to work, and the original how-to has 44 pages of posts from people with the same problem. I tryed different ways of setting up the shares and studied all the fstab variables with no luck. If your thinking about writing a bash file to auto mount, keep in mind that the mount command requires ROOT privileges.

If you want to try it click here. I just mount the share after a reboot. The same way you did in your test.

One thing you might want to know is that the terminal remembers all the commands you have entered. When in your terminal just press the "up key"

You will notice that NFS is a lot faster then smb or windows shares. The share folder feels and acts like a folder on your system.

Thanks again to malco2001 from the Ubuntu forums for the fun how-to.

No comments:

Post a Comment