File Sharing

NFS

01. Install the following packages using apt-get

 # apt-get -y install nfs-kernel-server nfs-common portmap

02. Modify the /etc/exports - The configuration file

  • Exported directories are defined in /etc/exports
  • Each entry specifies the hosts to which the file system is exported plus associated permissions and options

An entry in /etc/exports will typically look like this:

 directory machine1(option11,option12) machine2(option21,option22)

The following options can be used:

  • ro: The directory is shared read only; the client machine will not be able to write to it. This is the default
  • rw: The client machine will have read and write access to the directory
  • no_root_squash: By default, any file request made by user root on the client machine is treated as if it is made by user nobody on the server. If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server. This can have serious security implications, although it may be necessary if you want to perform any administrative work on the client machine that involves the exported directories.
  • no_subtree_check: If only part of a volume is exported, a routine called subtree checking verifies that a file that is requested from the client is in the appropriate part of the volume. If the entire volume is exported, disabling this check will speed up transfers.
  • sync: By default, all but the most recent version (version 1.11) of the exportfs command will use async behavior, telling a client machine that a file write is complete - that is, has been written to stable storage - when NFS has finished handing the write over to the filesysytem. This behavior may cause data corruption if the server reboots, and the sync option prevents this.

Examples:

 /home  192.168.0.1(rw) 192.168.0.2(ro)  # Gives rw or ro permissions to systems
 /home  192.168.0.0/255.255.255.0(rw)    # Gives read/write to all systems in 192.168.0 network
 /home  *.test.com(rw)                   # Gives read/write permission to all systems in test.com
 /home  *(rw)                            # To export to all the systems
 /home  *(sync,insecure)                 # To avoid the mounting problems in some clients
 /export 192.168.123.0/255.255.255.0(rw,sync,insecure,no_root_squash,no_subtree_check)

03. Make sure portmap deamon is running. If not, start it

 ps -ef | grep portmap
 rpc       3508     1  0 16:09 ?        00:00:00 portmap

04. Export the filesystem using exportfs command

 # exportfs -a

05. Veryfy the filesystems are exported using exportfs command

 #  exportfs
 /home           <world>

06. In the NFS client system, install the nfs client packages if not already installed

 # apt-get -y install portmap nfs-common

07. Mount the filesystem in the client systems

 # mount nfs_server_name:/home /mnt

The latest nfs-utils introduced /etc/exports.d; the files under the directory are loaded as if they are part of /etc/exports. Added/removing a new export point to the system becomes easier; just put or remove a file under the directory.

Autofs

Automount is the modern way to mount directories over a network. It is far much easier to manage and are more economic in bandwith.

The advantage of using automount are:

  • Reduces the administration tasks of /etc/fstab
  • Not necessary to have empty mount point directories
  • No pre-mounting of directories not currently needed thus reducing the possibility of client hung

There are two types of automount maps

Direct map:

  • It is used for high level directories such as /usr, that can not be used as automounter indirect mount point
  • Used for unique mount point
  • Full path name is required

Indirect map

  • Indirect map file will have only the relative paths

01. Install the autofs package

 apt-get install autofs

02. Edit the master map file /etc/auto.master

 cat /etc/auto.master
 /home /etc/auto.home    # indirect map 
 /-    /etc/auto.direct  # direct map

03. Create the mapfile auto.home

This file will have two fields. The key field and the location filed. A * in the key field of indirect maps matches all keys. Key Substitution. An & character in the location is expanded to the value of the key field that matched the line

 test1   server1:/home/test1
 test2   server1:/home/test2
 test3   server1:/home/test3

We can replace the all the three lines with the single line like

 *       server1:/home/&

04. Start the automount daemon

 # /etc/init.d/autofs start 
            (or)
 # /etc/iinit.d/autofs reload

Samba

01. Install the samba packages on Ubuntu server

 # apt-get install samba samba-doc

02. Install the inetd and SWAT packages if you want to administer the samba using SWAT. Swat services run as part of inetd deamon

 # apt-get install inetd swat

03. Make sure swat service is enabled in /etc/inetd.conf and start the inetd daemon if not already started.

 # /etc/init.d/inetutils-inetd start

04. To configure and administer samba, in any web browser, type the IPaddress_of_the_Samba_server:901