Setting Up An NFS Server And Client On Mandriva 2010.1 Spring - Page 2

4 Mounting The NFS Shares On The Client

client:

First we create the directories where we want to mount the NFS shares, e.g.:

mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs

Afterwards, we can mount them as follows:

mount 192.168.0.100:/home /mnt/nfs/home
mount 192.168.0.100:/var/nfs /mnt/nfs/var/nfs

You should now see the two NFS shares in the outputs of

df -h

[[email protected] administrator]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              29G  1.8G   26G   7% /
/dev/sda1             168M   15M  145M  10% /boot
192.168.0.100:/home    29G  1.9G   26G   7% /mnt/nfs/home
192.168.0.100:/var/nfs
                       29G  1.9G   26G   7% /mnt/nfs/var/nfs
[[email protected] administrator]#

and

mount

[[email protected] administrator]# mount
/dev/sda6 on / type ext4 (rw,relatime,acl)
none on /proc type proc (rw)
/dev/sda1 on /boot type ext4 (rw,relatime,acl)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)
[[email protected] administrator]#

 

5 Testing

On the client, you can now try to create test files on the NFS shares:

client:

touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txt

Now go to the server and check if you can see both test files:

server:

ls -l /home/

[[email protected] administrator]# ls -l /home/
total 4
drwxr-xr-x 4 administrator administrator 4096 2010-07-14 02:01 administrator/
-rw-r--r-- 1 root          root             0 2010-09-24 18:20 test.txt
[[email protected] administrator]#

ls -l /var/nfs

[[email protected] administrator]# ls -l /var/nfs
total 0
-rw-r--r-- 1 nobody nogroup 0 2010-09-24 18:20 test.txt
[[email protected] administrator]#

(Please note the different ownerships of the test files: the /home NFS share gets accessed as root, therefore /home/test.txt is owned by root; the /var/nfs share gets accessed as nobody/65534, therefore /var/nfs/test.txt is owned by 65534.)

 

6 Mounting NFS Shares At Boot Time

Instead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.

client:

Open /etc/fstab and append the following lines:

vi /etc/fstab

[...]
192.168.0.100:/home  /mnt/nfs/home   nfs      rw,sync,hard,intr  0     0
192.168.0.100:/var/nfs  /mnt/nfs/var/nfs   nfs      rw,sync,hard,intr  0     0

Instead of rw,sync,hard,intr you can use different mount options. To learn more about available options, take a look at

man nfs

To test if your modified /etc/fstab is working, reboot the client:

reboot

After the reboot, you should find the two NFS shares in the outputs of

df -h

[[email protected] administrator]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              29G  1.8G   26G   7% /
/dev/sda1             168M   15M  145M  10% /boot
192.168.0.100:/home    29G  1.9G   26G   7% /mnt/nfs/home
192.168.0.100:/var/nfs
                       29G  1.9G   26G   7% /mnt/nfs/var/nfs
[[email protected] administrator]#

and

mount

[[email protected] administrator]# mount
/dev/sda6 on / type ext4 (rw,relatime,acl)
none on /proc type proc (rw)
/dev/sda1 on /boot type ext4 (rw,relatime,acl)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,sync,hard,intr,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)
[[email protected] administrator]#

 

Falko Timme

About Falko Timme

Falko Timme is an experienced Linux administrator and founder of Timme Hosting, a leading nginx business hosting company in Germany. He is one of the most active authors on HowtoForge since 2005 and one of the core developers of ISPConfig since 2000. He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: Boppie

Hopefully, this time, it actually stays connected instead of dropping the connection were you have go in and reconnect.