Automounter – how I didn’t miss you

I really haven’t touched automount on Linux since my RHCE exam, but decided to refresh some of my outdated abilities & set up automounting home directories.

I used 2 VMs with CentOS 5.6 with the latest updates.

CentOS1:
CentOS1 needed NFS enabled & running, along with portmap and autofs.

Additionally, since we aren’t using NIS, each user account has to be present on both machines, and have the same UID & GIDs. If not, you’ll get into permission hell like this later on:

# su - test2
su: warning: cannot change directory to /home/test2: Permission denied
-bash: /home/test2/.bash_profile: Permission denied

Now — NFS needed some config, where I exported a “home” directory (which was the system’s home directory):

# cat /etc/exports
/home *(rw,sync)

Then, I ran exportfs -a to update the exported directory & tested that it was available locally by doing:
#showmount -e localhost …. which got me:

Export list for localhost:
/home *

Once it was available, I had to add in IPTables rules to allow the other VM the ability to mount from it. But before I could do that, I needed to know the ports required.
I ran rpcinfo -p localhost & filtered out the tcp/udp ports for autofs, nfs & portmap (edited for content):

# rpcinfo -p localhost

program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100003 2 udp 2049 nfs
100003 2 tcp 2049 nfs
100005 1 udp 976 mountd
100005 1 tcp 979 mountd

Then, I added in the IPTables rules & restarted iptables:


-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 976 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 979 -j ACCEPT

CentOS2:
Now that the ports are open, I needed to be sure that everything truly was open.
From CentOS2, I ran:
#rpcinfo -p centos1 … which got me (edited for content):

program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100003 2 udp 2049 nfs
100003 2 tcp 2049 nfs
100005 1 udp 976 mountd
100005 1 tcp 979 mountd

BOOM, I was on my way to configuring automount on CentOS2 now.

On CentOS2, I needed nfs, portmap and autofs enabled & running as well.

** NOTE** If you want the mount to be /home – you’ll need to move the original /home to a new name & create a new /home directory.

Edit /etc/auto.master & include the following:
/home /etc/auto.home --timeout 600

Edit /etc/auto.home & include the following:
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp
centos1:/home/&

Restart autofs & su – to a user that exists, with a home directory in /home – and you’ll have a shared home directory via automount & NFS.

If you want to be sure — run df -h & check out the mount points.