Lesson 6

Date: 2/22/2017
Network File System (NFS)
Linux System Administration

Exercise: NFS client configuration
  • Install the NFS related packages by using apt-get on n01 VM:
    apt-get install rpcbind nfs-common 

  • Run command rpcinfo pointing at the server
    rpcinfo -p master 
    If you see the same output as on the NFS server, it means the server allows you to access the rpcbind and the rpc services. Check what directories are exported to you from the server:
    /sbin/showmount -e master 
    It should show
    /NFS/home n01
    Now you are ready to mount its directory on n01. Create a new mounting point and mount the exported directory onto it via NFSv3:
    mkdir -p /NFS/home
    mount -t nfs -o vers=3 master:/NFS/home /NFS/home 
    To make sure the directory has been mounted, run command
    Run also
    df -h 
    The mounted directory shows up in the bottom of the file systems list:
    master:/NFS/home   494M   78M  390M  17% /NFS/home
    To see who is the owner of the files in the directory, run command
    ls -l /NFS/home/edward
    Since there is no user with UID=666 and GID=666 on the node, the mounted directory would belong to a non-existent user:
    ls -l /NFS/home/edward
    total 5
    -rw-r--r--    1 666      666           104 Feb 10 19:32 hosts
    -rw-r--r--    1 666      666          1750 Feb 10 19:32 nsswitch.conf
    -rw-------    1 root     root          114 Feb 10  2003 securetty
    Create user edward with UID=GID=667:
    /usr/sbin/groupadd -g 667 edward
    /usr/sbin/useradd -m -s /bin/bash -u 667 -g 667 -d /NFS/home/edward edward
    Assign password to the user:
    passwd edward
    Now try to change the ownership of the directory on the node:
    chown edward:edward /NFS/home/edward
    It doesn't work:
    chown: changing ownership of `/NFS/home/edward': Operation not permitted

    Change the UID and GID of edward to be consistent with those on the NFS server:
    /usr/sbin/groupmod -g 666 edward
    /usr/sbin/usermod -u 666 -g 666 edward
    Become user edward then step into directory /NFS/home:
    su edward
    cd /NFS/home/edward 
    and see if you can create files in this directory:
    touch  newfile.txt

    Exit from user edward account:
    Unmount the directory,
    umount /NFS/home
    Mount the directory as NFSv4:
    mount -t nfs -o vers=4 master:/NFS/home /NFS/home
    Run command below to verify that the directory has been mounted:

  • Reboot n01 by executing command reboot and check if the NFS directory is no longer mounted after reboot:
    df -h
    Modify file /etc/fstab by including a new entry with /NFS/home:
    master:/NFS/home  /NFS/home   nfs     rw,vers=4      0    0
    Then run
    mount -a
    Check if it is mounted
    df -h

  • Unmounting busy directories.
    Open another terminal on your desktop and ssh to n01 as user edward. You can figure out the IP address of n01 by running command ifconfig in the 'root' console of n01. For example, if n01 has IP address, the ssh command on the desktop looks as follows:
    ssh edward@
    Note, in your KVM environment the IP address of n01 may be different.

    In the 'root' console of n01 try to unmount the directory:
    umount /NFS/home
    If the directory can not get unmounted and you receive error message "device is busy", check what processes hold the directory by executing command lsof +D on the file system. Specifically, in our case:
    lsof +D  /NFS/home
    Kill the process, for example with PID 1367, and try to unmount the directory again.
    kill -9 1367
    umount /NFS/home

    Remove the NFS entry from /etc/fstab
    Try to avoid NFS mounting through /etc/fstab. Use either manual mount or automount.

  • Take me to the Course Website