Easy-Peasy Ubuntu Linux NFS File Sharing

Ubuntu logo
In this brief blog entry I will note the steps it took for me to use the Network File System (NFS) protocol to share files between another Linux computer. All machines in this lab are either Debian GNU/Linux (unstable) or Ubuntu Linux (breezy badger 5.10 w/ back-port upgrades). After reading countless threads and comments for file sharing they all pretty much suggested SaMBa as the simplest solution. In case you aren't familiar SaMBa software will allow a UNIX machine to act as a file server to Windows clients. SMB is fine if you _need_ to share with DOS but we don't need that here. Another option is NFS.

NFS, Network File System, is a file sharing protocol in a UNIX network. It is the de facto UNIX standard. It is strongly associated with UNIX systems, though it can be used on any platform such as Macintosh and Microsoft Windows operating systems.

Installation and configuration.



I will be doing this whole set-up through terminal seeing the shares-admin Ubuntu package gave up after a little tweaking.

First install the necessary packages from your local repository. Aptitude may be switch with apt-get for a _less then modern_ installation.

sudo aptitude -P install nfs-kernel-server nfs-common portmap

When configuring portmap do =not= bind loopback. If you do you can either edit /etc/default/portmap by hand or run:

sudo dpkg-reconfigure portmap

If you have edited the file by hand you can restart portmap via:

sudo /etc/init.d/portmap restart

Note: It is not necessary to install NFS on client machines which are not going to be sharing any of their own directories.

Sharing Local Folders

To specify a folder you will need to edit /etc/exports, which can be done like (replace vi for your favorite editor):

sudo vi /etc/exports

For an example I will share, with full read/write and privileges, my temporary directory. This directory will be broad casted to every local IP from 192.168.1.1 through 192.168.1.255.

/home/czar/tmp 192.168.1.1/24(rw,no_root_squash,async)


To share a read only drive, for example on a Windows NTFS drive, you can use something like the following:

/media/hdc5/music 192.168.1.1/24(ro,async)
sudo /etc/init.d/nfs-kernel-server restart

After making changes to /etc/export you can make the shares effect by issuing the:

sudo exportfs -a

Use on the _Other_ PC

Last you will need to mount the volume on the other computer. So, ether shift screens or SSH to lab2 and open a terminal. You can only mount into another folder which must be created.

sudo mkdir ~/music

Now mount music from lab1 into ~/music at lab2.

sudo mount 192.168.1.2:/media/hdc5/music ~/music

That's it!

Hopefully everything went well and you can now browse to ~/music locally on lab2. If you encounter errors, do not worry and read them carefully. To mount my first NFS volume felt as if it took weeks. NFS simply owns in a LAN UNIX environment. However I have seen warnings not to share via TCP/IP unless you are on a nice secured BSD system.

Also See

Zemanta Pixie

Thanks, this worked great

Thanks, this worked great with a little help from https://wiki.ubuntu.com/NFSServerHowTo aswell.

Ubuntu to you too

This worked perfectly.

This worked perfectly.

There was no need for any changes from your recipe. :)

NFS was really useful in my unix-days at university (I have also used AFS to transfer files from other universities) and I really wanted to run it here when I needed to transfer files between my two computers.

Works a treat

Worked a treat for me, and I've been using samba since ever!

I used apt-get, no issues there.

Couldn't believe it was that simple!

Cracking stuff. :) I had a

Cracking stuff. :) I had a small hiccup to begin with (portmap was wrong on my client machine), but otherwise perfect. Cheers :)

THANK YOU!

Such a simple and easy step-by-step guide into getting NFS working for Ubuntu. Worked perfectly and your instructions were clear. THANK YOU!!!!!

One more thing though...

It is a nice straightforward recipe. Now like easy things we try to make them bend, and come up with a knot. :) I've exported my cdrom to another server.

I'm trying to unmount my cdrom and get

umount: /media/cdrom0: device is busy

When I find out to unmount my cdrom from NFS, I'll post it here.

Thanks again!
Dave

Thank you!

Thank you! I finally got a NFS connection between my 2 computers. No more samba for me :)

Unmounting cdrom

Dave Dumaresq; are you still having trouble unmounting your cdrom?

Try the umount switch -l, as in umount -l /media/cdrom0. It should force the unmount, even if otherwise the device is reported as busy.

mount: XXX failed, reason given by server: Permission denied

when i run this on my client machine:
sudo mount 10.0.0.27:/media/windows/PUBLIC /mnt/27

i get the following error:
mount: 10.0.0.27:/media/windows/PUBLIC failed, reason given by server: Permission denied

i set the permissions of the files i'm going to share to 777 just to make sure but it didn't seem to help

Slow mount

I basically can mount nfs volumes. in my ubuntu desktop, mounting is super slow, I couldn't figure out is it the nfs software running in server or the client mount program running slow.

nfs server running on 128MB 300MHz SUSE 10.1
nfs client running on 384MB 800MHz UBUNTU 6.10

If your mounting is slow try

If your mounting is slow try checking the syslog on the client. Probably your portmap is not running or it has trouble connecting. If the RPC calls don't get through, they will time out and NFS will fall back on other methods. This is what causes the delay.

A good usefull setps

Czar,

It's a perfect tutorial.

Simple an clean.

Congratulations, dud

Hugs

NFS Sharing - Grrr!

I'm having zero luck with NFS sharing between two unbuntu machine -- I've always thought Linux was a strong networking platform but I'm finding it very crude -- like the early days with Novell. Would it be so hard to put together a little GUI for all this?!

Czar -- could you revisit the example above and follow it through with one example?

1. Share one folder on a computer 'server' and show all the steps that need to be done.

2. Then show how to connect to the shared folder from a a computer 'client'. Unfortuntely the example above switches examples so it is hard to follow the syntax.

All I need to see is the syntax to share just one little folder -- I can take it from there.

I'm getting nothing but permission denied errors as described by one of the posters above.

Thanks -- Matt

Won't grant write access

After 60-70 hours of flipping through documentation I finally cross-referenced enough material on NFS to finally figure out the syntax of setting up file sharing between two identical Ubuntu 6.06 Drake computers.

I now have read only access to the shared folder on the server. I wanted read/write access and configured the system as follows:

The server is 192.168.0.2
The client is 192.168.0.3

On the server I added the following line to the /etc/exports file:
/home/server/shared 192.168.0.3(rw,sync)

On the client I executed the line:
sudo mount 192.168.0.2:/home/server/shared /home/client/shared

I can see but I can't modify -- when I try to delete a file it says I don't have permissions for the parent folder?

Can someone save me days of random experimentation and random wanderings through masses, volumes, libraries of arcance and incomplete linux documentation and suggest what the problem is?

Matt.

Re: "Won't grant write access"

regarding " Won't grant write access" ---
we had this same problem.. to fix it? you'll need to fix the UID's of the users..
-------------
for us? we had a small enough set up that we just some manual tweaking (vs., e.g. getting NIS, or another solution up) and? after doing that it worked...
-------------
some further misc pointers to get you going:
(A) see? the first section of: https://help.ubuntu.com/community/SettingUpNFSHowTo
on "User Permissions"
(B) investigate: sudo systemsettings ==> Users & Groups ==> Modify, notice? what the modify dialog let's you change, and? what it does not.. and so, hence (C)
(C) we also did mucking around with chmod, and chown to get it fully working ...
-------------

Connecting two ubuntu machines

I have two Ubuntu 6.06 computers, a laptop and a desktop PC. I want to connect the laptop to the desktop PC via UTP cross over cable. My problem is: How can I configure the localnetwork (ip, mask, etc.) for this direct connect? And I want to share files between the two computers with read/write/execute privileges. How to do this?
Please, help me, if you can! Thanks very much!

big ups yourself, it worked

big ups yourself, it worked for me with a ubuntu 6.10 share and mythdora 3.2 perfectly

How About NAS Boxes

I am trying to setup connections between an Ubuntu Linux system and a NAS box running specially modified version of Redhat Linux. I have setup a user with NFS protocol attachments, and assigned him to a share on the NAS box. When I try to connect to that share I get message telling me that the mount failed...permission denied. If I send a user name with the mount attempt, I get a different message. Has anyone ever done a NFS mount like this? If so, what syntax did you use on the mount command?

Thanks!

OSX as client

If you use osx as the client, add "insecure" to the /etc/export like "/exported/path 192.168.0.1/24(ro,async,insecure)" or you will encounter "Operation not permitted" when you try to mount the exported path.

Never share NFS across the internet

Hi,

I read your article (very good explained) but also checked another article (at http://www.unhandledexceptions.com/tutorials/tut_11.html) . Most of them are the same, but the other article explicitly states "NEVER ALLOW NFS TO BE SHARED ACROSS THE INTERNET". I guess that if you are connected with one or both PC's to the internet, you also open your PC for potential problems. Therefore I also changed my /etc/hosts.deny and /etc/hosts.allos (see http://www.unhandledexceptions.com/tutorials/tut_11.html for details).

Never the less, I think your article is very good and clear!

Regards,

Marc

SO much easier than Samba!

I've been messing with Samba all weekend trying to make it do what I did in minutes following this tutorial! I'm SO glad I found this page! Thanks!

Hi, before i try this i have

Hi, before i try this i have a question. Will this work if i've set up my ubuntu machines to use DHCP. The problem i have is that the router provided by my isp needs my boxes to use DHCP rather than me manually assigning an ip... Any ideas?

Re: 'sudo mount

Re: 'sudo mount 192.168.1.2:/media/hdc5/music ~/music':

I tried the above (well, was actually along the lines of 'mount 192.168.0.2:/media/remote-nfs-mount ~/locally mounted remote-nfs-mount').

It didn't work (Got 'permission denied' stuff), so I tried this:

'mount 192.168.0.2:/media/remote-nfs-mount /media/locally mounted remote-nfs-mount'.

This seemed to work alright, and I copied my stuff across fine:

'cp -R /stuff-to-be-copied /media/remote-nfs-mount'

'diff -R /stuff-to-be-copied /media/remote-nfs-mount'

NOTES:

Ubuntu 6.06 on both machines; all commands run as 'root' user.

I created mount points on both machines of the exact same name/place (i.e. '/media/copied-data').

Also did 'chmod -r 777 /media/copied-data' on both machines (so I had write access??).

HTH.

Thank you, thank you, thank you, thank you!!!

Wow. It's absurd how long it took to find a simple howto like this. I've been using samba/scp for transferring between systems @home for so long. Everytime I tried to find howtos for NFS, they were either overly complicated or they were *actually* howtos for samba.

This was so easy. I'll never scp between my local servers again!!!

Thank you, thank you, thank you!

Re: Easy-Peasy Ubuntu Linux NFS File Sharing

Yup. As above comments say, this is definitely a concise guide to NFS. Just enough what you may need :)

Thanks mate, brilliant!

Just wanted to add something here that wasn't explicitly stated in your excellent 'no frills' guide: it is not necessary to install NFS on client machines which are not going to be sharing any of their own directories.

Problem mounting NTFS disk

Firstly, thank you for this great tutorial. I think i'm NEARLY there!

I have followed your example for mounting a NTFS volume. When I restart the NFS kernel daemon i get a message at the end stating:

"exportfs: Warning: /media/sdc5 does not support NFS export."

Further info:

Both machines are running ubuntu 7.10 (beta) which i believe supports writing to NTFS

exports file entry on host reads:
/media/sdc5 /255.255.255.0(rw,no_root_squash,async)

fstab file entry on host machine reads:
"/dev/sdc5 /media/sdc5 ntfs rw,users,auto,umask=000 0 0"

Thanks for any help you can provide.

KB

RE: Problem mounting NTFS disk

Hi king boogie, I'm having the exact same error you describe when trying to export my NTFS partition from Ubuntu Gutsy. Have you figured out how to solve this issue?

Thanks in advance.

well it almost worked just that way

i did exactly as the instructions said, but it would not mount from my server to my laptop until i installed the nfs server kernel and all the stuff in step 1 onto my laptop.. i kept getting errors about missing software or its the wrong filesystem, but as soon as i did that, and edited my fstab my music directory comes right up. my laptop has 60 gigs o space and my desktop has a 320 and a 160... very useful i have a music dir bigger than my hard drive. the server is running ubuntu feisty and the laptop is running hardy, my other desktop is running vista/hardy, and everything is running great, amarok grabs up my music and makes playlists no prob

Re: Easy-Peasy Ubuntu Linux NFS File Sharing

"Dave Dumaresq; are you still having trouble unmounting your cdrom?" I'm not really sure, but I think the answer is yes

you must install in the "other" pc nfs-common too....

...and it's dependencies

Tags