Setting up a NFS

Hi,

I am setting up a NFS for Linux to Linux sharing after wrong assuming SAMBA would do it. I am following the guide here but have some questions.

  1. Why create a temp folder?
    2 What are exports?
    3 What is being exported?

this is the code that I am referring to

mkdir /tmp/nfsdemo/
chmod 1777 /tmp/nfsdemo/
echo '/tmp/nfsdemo/ *(rw,all_squash,insecure,no_subtree_check,fsid=0)' > /etc/exports
exportfs -ra

I already have a mounted external hard drive:

/mnt/sda1

Thanks,

Aaron

What is being exported is part of the server's filesystem. Whatever it is that you want to share.

That example is just to make a sample export. So, what you want is to edit /etc/exports to have:
/sharedroot/folder 192.168.1.1/24(fsid=root,rw,insecure,no_subree_check,async)

Notes:

  1. 192.168.1.1/24 to your LAN's address/netmask. This makes it so that only clients on that network can connect the the NFS server. The firewall should also prevent outside connections, but I like to be safe.
  2. Using async basically says allow the server to tell the client any operation succeeded before it gets written out to disk. It is a slight risk of data corruption if the server crashes in the middle of file transfers, but in my experience it's no more risky than a crash itself and not using it hobbles performance so badly it's not worth using NFS. But if you want absolute data safety, change async to sync

Once that's done, you don't need the exportfs command. Just do:
/etc/init.d/nfsd restart

Once that is done, on the client you want to do this:
mount -t nfs 192.168.1.1:/ /local/mountpoint -o async,soft,nfsvers=4

Notes:

  1. 192.168.1.1 - change to the server's address of course
  2. The async is different on the client than on the server. On the client it means it delays sending writes on the network until memory constraints require it to. Basically it means to cache writes as long as possible. Good for performance and on a good LAN pretty safe
  3. nfsvers=4 causes the client to use NFS version 4. Don't use v3 - I have found on every OpenWrt device I have ever tried it on that NFS v3 is prone to causing the network stack to hang under load. NFS v4 is slightly less performant than v3, but much more stable.
  4. soft causes the client to fail with an error if it looses connection, as opposed to hard' which will cause it to basically wait forever if the connection drops. Word of warning, don't ever use hardif the client will be automounting the remote filesystem with its fstab, or else if the remote isn't available you can lose the ability to boot. TBH, I never recommendhard` in any practical circumstance.

At some point you'll prolly want to add the mount to your client's fstab. Just shout out if you want a hand with that.

1 Like

What does this mean?

mount.nfs: Stale file handle

I receive that message after I try to mount the directory of the client.

sudo mount -t nfs 10.1.1.4:/ /mnt/sda1 -o async,soft,nfsvers=4

Sounds like there is a stale mount somewhere. Perhaps it was mounted and the client reset. I would suggest restarting the nfs server and trying again.
\etc\init.d\nfsd restart

1 Like

You have the slash around the wrong way it suppose to be

/etc/init.d/nfsd restart

1 Like

Found this article explains what the problem is and has a solution that fixed the problem.

1 Like

Just be careful, if you are getting stale mounts so often you have to clean them out with a cron job, there are other problems.

1 Like

Ah ok! I also, found this article explains how to mount shares on the different Linux systems correctly.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.