Accessing Network Shares

From SingletonMillerWiki
Revision as of 03:36, 2 June 2013 by Martin (Talk | contribs) (added LDAP autofs example)

Jump to: navigation, search

Network shares some in two main forms. NFS[en.wikipedia.org/wiki/Network_File_System] and CIFS[www.samba.org/cifs/].

AutoFS

AutoFS is a simple means of mounting an external network share automatically when its required.

This method means that hard mounting in the fstab can be avoided such that if a share is not availalble at boot no errors are thrown.

Installing autoFS

sudo apt-get install autofs

Configure autoFS

Installation will create a configuration file /etc/auto.master. Edit this file and add a link to a seperate file.

sudo nano /etc/auto.master

add the following at the end of the file.

/media/nfsshares /etc/auto.<fileservername> --ghost

where <fileservername> is then name of your fileshare server. make sure there's a return at the end of the line.

Create /etc/auto.<fileservername>

sudo nano /etc/auto.<fileservername>

add the local share folder name and the remote server address and location in the form

<localfolder> <server address>:/<server folder>

if you have numerous shares in the same tree, you can add something like this * 192.168.0.8:/myshareroot/&

Test autoFS

first we need to restart the service

sudo service autofs restart

You should see

Stopping automount: done.
Starting automount: done.

Navigate to the local share location, for example cd /media/nfsshares/music

List the contents of the directory to check its mounted, a brief delay as the folder is mounted may be expected depending on you network configuration.

cd /media/nfsshares/music
ls

You should see a list of all the remote files.

If you get errors like 'directory not found', check your auto.master config.

Raspbian / Raspbmc

Problem

After installation and setup autofs doesn't work and access to an NFS directory results in

No such file or directory

this can be fixed by starting rpcbind . To start rpcbind manually.

sudo service rpcbind start
[sudo] password for jack: 
[ ok ] Starting rpcbind daemon....

The preferred methid is to run rpcbind at startup.

sudo update-rc.d rpcbind defaults
sudo update-rc.d rpcbind enable

Re-boot the RPi and test.

Autofs for LDAP

The following method allow auto mounting of any CIFS shares and retains the users permissions.

$tail /etc/auto.master
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
#+auto.master
/media /etc/auto.ldapcifs --ghost

$cat /etc/auto.ldapcifs
/nfsshares/* -fstype=cifs,credentials=${HOME}/cifs.cred,uid=${UID},gid=${UID} ://<cifs server>/&

$cat ~/cifs.cred
username=jack
password=<jacks cifs password>