Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Last active January 30, 2018 18:13
Show Gist options
  • Save vegaasen/06d75cc19f108380a909d3b06a2aab7a to your computer and use it in GitHub Desktop.
Save vegaasen/06d75cc19f108380a909d3b06a2aab7a to your computer and use it in GitHub Desktop.
automount (autofs) and nfs playing nicely together

Automount (autofs)

Introduction

This is a simple and small guide on how to set up an Automount mapping and feature on RHEL 6.x. It basically covers:

  • Installing autofs
  • Configuring autofs to target the NFS defined mount point
  • Utilizing the defined mount point
  • Installing NFS
  • Configuring NFS
  • Defining a mount point

Resources

Explained

NFS

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984,[1] allowing a user on a client computer to access files over a computer network much like local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The NFS is an open standard defined in Request for Comments (RFC), allowing anyone to implement the protocol.

Read more on Wikipedia.

Automount

An automounter is any program or software facility which automatically mounts filesystems in response to access operations by user programs. An automounter system utility (daemon under Unix), when notified of file and directory access attempts under selectively monitored subdirectory trees, dynamically and transparently makes local or remote devices accessible.

Read more on Wikipedia.

Pre-requisites

Target-server (server hosting the folder to be mounted)

This example definition will use a defined user called mycooluser. Create the user on the targeted host:

sudo useradd -b /export/home -c "Mimics random cool user" -m -U mycooluser

When this is done, create the following folder structure as well in order to properly share a folder:

sudo mkdir /usr/cool
sudo mkdir /usr/cool/users
cd /usr
sudo chown -R mycooluser:mycooluser cool
ls -la 
# ensure correct ownership

Installation (server)

In order to enable sharing a specific folder, some kind of software must be installed locally on the server, and this is typically some NFS based utilities.

yum install nfs-utils nfs-utils-lib

After this is done, just start the service:

sudo service nfs start
sudo chkconfig --level 35 nfs on

Configure NFS shares

Now the service related to the NFS stuff should be started and running. Next up is to actually configure NFS to share the folder(s) that should be marked for sharing. Edit the file named /etc/exports and insert something similar to this configuration:

sudo vi /etc/exports
/usr/cool/users *(rw,sync,no_root_squash)
/usr/cool/users 10.10.10.16(rw,sync,no_root_squash)
# see man for export for more features (rw = readwrite, ro = readonly, sync = duh..)

After this is done, just restart the NFS server:

sudo service nfs restart

Remove hosts.deny configuration

Remove the configuration that is defined in the hosts.deny file for mountd. Perform the following:

sudo vi /etc/hosts.deny
# (remove mountd blockades)

Remove hosts.allow configuration

Remove the configuration that is defined in the hosts.allow file for mountd. Perform the following:

sudo vi /etc/hosts.allow
# (remove mountd blockades OR mountd: 10.10.10./255.0.0.0)

Note: You can actually also allow the IPs that should be able to connect to the service itself (mountd). See above for example.

You are now ready to accept requests from a client - wihu! :-)

Installation (client)

Installing autofs

If you do not have autofs installed, run the following stuff below:

sudo yum install autofs

Verify shares is public by NFS

Run the following command in order to verify that some mounts is exposed/exported (through the use of e.g NFS):

sudo showmount -e 10.10.10.26
# Export list for 10.10.10.26:
# /usr/cool/users 10.10.10.16

Configure shared file share in auto.master

This is quite simple and includes changing the file called auto.master. Perform the following:

sudo vi /etc/auto.master
#  MOUNTPATH     		CONFIGURATION  		 PARAMETERS
/cooltransfer		/etc/auto.fs-cool		--timeout 60

Now, copy the existing file "auto.misc"-file (you're just as lazy as me, so just do it :-)) and modify the contents to conform with the remote server / fileshare

sudo cp /etc/auto.misc /etc/auto.fs-cool
sudo vi /etc/auto.fs-cool
# add the following stuff the last line
user            -fstype=nfs     10.10.10.26:/usr/cool/users

Now restart automount/autofs to reflect the mounting configuration. Issue the following commands:

sudo service autofs stop
sudo service autofs start

Verify that the mountpoint

Execute the following commands to verify that the mountpoint is properly defined:

ls -la /cooltransfer
# should output (nothing)
ls -la /cooltransfer/user
# should output whatever is defined in the mapped NFS directory (here: /usr/cool/users)

You can even change the ownership to the (other) local user on the directory that contains the NFS. Perform the following:

cd /cooltransfer/user
sudo mkdir whatever
sudo chown 501:504 whatever

CONGRATS! All should be working! :-) Unless..you've effed up. Then, try again :-P.

Typical errors

Client-server

rpc mount export: RPC: Authentication error; why = Failed (unspecified error)

This indicates that something is wrong with your permissions. It can be any of the following configurations:

Verify the following:

  • hosts can contain ALL - verify that this should be the case
  • exports may contain either wrong dns-entry/alias or wrong ip/sub - verify this :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment