Ians Ramblings Ian's ramblings, daily, ish

25Feb/090

NFS mount with differing UID and GID

Geeky post alert! Just thought I would put this snippet of info here incase anyone else has the same problems I did when getting an NFS mount to be writable when you do not have automatically synchonsed user accounts on both the NFS server and the machine you are mounting on.


The following actions should be carried out on the "server" machine, i.e. the machine that actually has the directory(s) that are being shared.

Firstly you need to ensure that NFS as a service is running (execute these as root): -

rpcinfo -p

This should return something like the following if the service is running: -

100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs

If the service is not running you should run: -

/etc/init.d/nfs start
Create the user you want the client machine to authenticate as with the useradd command, once the user is added run the following command to get the UID and GID of the user
id boristheuser

Should return something like: -
uid=500(boristheuser) gid=500(boristheuser) groups=500(boristheuser)

You can then add the directory you want to share with read and write access to the given host.
The directory must then be listed in the exports file "/etc/exports" an example is: -
/opt/share Client(rw,sync)
In this example the machine I intend to mount the directory on is known as "Client" in my "/etc/hosts" file.
Once added the following command should be executed or I believe you can restart the whole NFS service and get the same result: -
exportfs -ra
The next set of instructions should be executed on the "client" machine.
Now you can add the NFS mount point to the "/etc/fstab" the entry in the fstab should be something like (all one line): -
Server:/opt/share /opt/nfs_share nfs rw 0 0
In this example the machine I intend to mount the directory from is known as "Server" in my "/etc/hosts" file.

You now need a corresponding user on the "Client" you should add the user using the "useradd" command, if the uid and gid differ on the two machines, you can either automatically keep both in sync with a tool such as RSync, or you can manually change both UID and GID's to an arbritary value, usually over 99.

You can change the UID and GID of a user with the "usermod" -u and "usermod -g" commands

Once the command "mount -a" is executed the directory should now be available and read / writable in /opt/nfs_share/
This can be checked by running "df -h"

If you need to make changes to config and re-mount you will need to run the umount command against your mount point first, for example: -

umount /opt/nfs_share/
mount -a

where the directory being umounted is the one mentioned in your fstab.

I used the following page for troubleshooting this procedure: http://tldp.org/HOWTO/NFS-HOWTO/troubleshooting.html

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

6 visitors online now
6 guests, 0 members
Max visitors today: 8 at 06:38 am UTC
This month: 8 at 03-09-2010 10:50 am UTC
This year: 21 at 02-25-2010 11:24 am UTC
All time: 21 at 02-25-2010 11:24 am UTC