/home? /export/home? AutoFS?

/home? /export/home? AutoFS?

History

The ever recurring question to me at customer sites relatively new to Solaris is: "Okay, on Linux I had my home directories at /home. Why are they at /export/home on Solaris?" This is old hat for seasoned admins, but I get this question quite often. Well, the answer is relatively simple and it comes from the time when we started to use NIS and NFS and it had something to do with our slogan "The network is the computer", because it involves directories distributed in the network. Okay, we have to go back 20 years in the past.

There was a time, long, long ago, when you worked at your workstation. The harddisk in your workstation was big and it was a time when you didn’t need 200 megabytes for your office package alone. So you and your working group used workstations for storing their data, but there were several workstations and even some big servers for big computational tasks. The users wanted to share the data, so Sun invented NFS to share the files between the systems. As it was a tedious task to distribute all of the user accounts on all of the systems, Sun invented NIS (later NIS+, but this is another story).

But the users didn’t want to mount their home directories manually on every system. They wanted to log in to a system and work with their home directory on every system. They didn’t want to search in separate places depending on whether they were using their own machine or a different one.

So Sun invented the automounter - it found its way into SunOS 4.0 in 1988. The automounter mounts directories on a system based upon a ruleset. In Solaris 2.0 and later the automounter was implemented as a pseudo filesystem called autofs. autofs was developed to mount directories based on rules defined in so-called maps.

There are two of them provided by default. At first there is the /etc/auto_master. To cite the manual:

The auto_master map associates a directory with a map. The map is a master list that specifies all the maps that autofs should check

On a freshly installed system the file looks like this:

[root@gandalf:/net/theoden/tools/solaris]$ cat /etc/auto_master 
+auto_master
/net            -hosts          -nosuid,nobrowse
/home           auto_home       -nobrowse

The file /etc/auto_home is such a map referenced by the master map. To cite the manual again:

An indirect map uses a substitution value of a key to establish the association between a mount point on the client and a directory on the server. Indirect maps are useful for accessing specific file systems, such as home directories. The auto_home map is an example of an indirect map.

We will use this map later in this article.

The use case

Okay, an example. gandalf is the workstation of Waldorf and Statler. theoden is the workstation of Gonzo and Scooter. They each have their home directories on their own workstation. Sometimes a team uses the workstations of the other teams and they have a gentleman’s agreement allowing each other to do so. But they want to use their home directories on the system of the other team.

Prerequisites

At first we have to export the directories which store the real home directories on both hosts via NFS.

At first on gandalf:

[root@gandalf:/etc]$ echo "share -F nfs -d \"Home Directories\" /export/home" >> /etc/dfs/dfstab 
[root@gandalf:/etc]$ shareall
[root@gandalf:/etc]$ exportfs 
-               /export/home   rw   "Home Directories"

Now we repeat these steps on theoden:

[root@theoden:/export/home]$ echo "share -F nfs -d \"Home Directories\" /export/home" >> /etc/dfs/dfstab
[root@theoden:/export/home]$ shareall
[root@theoden:/export/home]$ exportfs   
-               /export/home   rw   "Home Directories"

Okay, it’s important that both hosts can resolve the hostname of the other system. I’ve added some lines to <code>/etc/hosts</code> in my test installation:

10.211.55.201 gandalf
10.211.55.200 theoden

Creating users and home directories

Normally you wouldn’t create the users this way. You would use a centralised user repository with LDAP. But that is another very long tutorial.

The userids and user names of the users have to be the same on both systems. At first I create the local users. I use the -m switch for creating the home directory at the same time as the user.

[root@gandalf:~]$ useradd -u 2000 -m -d /export/home/waldorf waldorf
64 blocks
[root@gandalf:~]$ useradd -u 2001 -m -d /export/home/statler statler
64 blocks

Now I set the home directory of both users to the /home under the control of autofs:

[root@gandalf:~]$ usermod -d /home/statler statler
[root@gandalf:~]$ usermod -d /home/waldorf waldorf

Now I create the users for the other team, without the -m switch and directly with the correct home directory. The home directories come from the other system, so we don’t have to create them:

[root@gandalf:~]$ useradd -u 2002 -d /home/gonzo gonzo
[root@gandalf:~]$ useradd -u 2003 -d /home/scooter scooter

Now we switch to Theoden. We do almost the same on this system. We create the accounts for Waldorf and Statler without creating a home directory. After this we create the local users together with their home directories, which we then set to be autofs controlled:

[root@theoden:~]$ useradd -u 2001 -d /home/statler statler
[root@theoden:~]$ useradd -u 2000 -d /home/waldorf waldorf
[root@theoden:~]$ useradd -u 2002 -d /export/home/gonzo -m gonzo 
64 blocks
[root@theoden:~]$ useradd -u 2003 -d /export/home/gonzo -m scooter 
64 blocks
[root@theoden:~]$ usermod -d /home/gonzo gonzo 
[root@theoden:~]$ usermod -d /home/scooter scooter

Configuring the automounter

Execute the following four commands on both hosts:

echo "statler gandalf:/export/home/&" >> /etc/auto_home
echo "waldorf gandalf:/export/home/&" >> /etc/auto_home
echo "scooter theoden:/export/home/&" >> /etc/auto_home
echo "gonzo theoden:/export/home/&" >> /etc/auto_home

Here, the ampersand is a variable. It stands for the key in the table. So gonzo theoden:/export/home/& translates to theoden:/export/home/gonzo. Now start the autofs on both hosts:

[root@theoden:~]$svcadm enable autofs

and

[root@gandalf:~]$svcadm enable autofs

Testing the configuration

Okay, let’s log in to theoden as user gonzo. Gonzo is a user with a home directory local to theoden:

$ ssh gonzo@10.211.55.200
Password: 
Last login: Sun Feb 17 14:16:41 2008 from 10.211.55.2
Sun Microsystems Inc.   SunOS 5.11      snv_78  October 2007
$ /usr/sbin/mount
[...]
/home/gonzo on /export/home/gonzo read/write/setuid/devices/dev=1980000 on Sun Feb 17 14:13:35 2008

Now we try waldorf on theoden. Waldorf doesn’t have its home directory on theoden, it’s on gandalf.

$ ssh waldorf@10.211.55.200
Password: 
Last login: Sun Feb 17 14:17:47 2008 from 10.211.55.2
Sun Microsystems Inc.   SunOS 5.11      snv_78  October 2007
$ /usr/sbin/mount
[...]
/home/waldorf on gandalf:/export/home/waldorf remote/read/write/setuid/devices/xattr/dev=4dc0001 on Sun Feb 17 14:17:48 2008

autofs has mounted the /export/home/waldorf automatically to /home/waldorf, the directory we used when we created the user.

Let’s crosscheck. We log into gandalf with the user waldorf. Now this user has a local home directory. It’s a local mount again.

$ ssh waldorf@10.211.55.201
Password: 
Last login: Sat Feb 16 09:12:47 2008 from 10.211.55.2
Sun Microsystems Inc.   SunOS 5.11      snv_78  October 2007
$ /usr/sbin/mount
[...]
/home/waldorf on /export/home/waldorf read/write/setuid/devices/dev=1980000 on Sat Feb 16 09:12:47 2008

Explanation for the seperated /home and /export/home

The explanation for the existence of /home and /export/home is really simple. I think you got it already. export/home is the directory where all the local directories are located./home is the playground for autofs to unify all home directories at a central place, whereever they are located.

The /net directory

Did you ever wonder about the /net in the root directory and its job? It’s an autofs controlled directory, too. Let’s assume you have an /tools/solaris directory at theoden:

[root@theoden:/tools/solaris]$ ls -l /tools/solaris
total 0
-rw-r--r--   1 root     root           0 Feb 17 15:21 tool1
-rw-r--r--   1 root     root           0 Feb 17 15:21 tool2
-rw-r--r--   1 root     root           0 Feb 17 15:21 tool3

Share it via NFS

[root@theoden:/tools/solaris]$ share -F nfs -d "Tools" /tools/solaris
[root@theoden:/tools/solaris]$ share -F nfs 
-               /export/home   rw   "Home Directories"  
-               /tools/solaris   rw   "Tools"  
[root@theoden:/tools/solaris]$

Now change to the other workstation. Look into the directory /net/theoden:

[root@gandalf:/]$ cd /net/theoden
[root@gandalf:/net/theoden]$ ls
export  tools

You will notice all of the directories shared by theoden. Change into the tools/solaris directory:

[root@gandalf:/net/theoden]$ cd tools
[root@gandalf:/net/theoden/tools]$ ls
solaris
[root@gandalf:/net/theoden/tools]$ cd solaris
[root@gandalf:/net/theoden/tools/solaris]$ ls -l
total 0\
-rw-r--r--   1 root     root           0 Feb 17  2008 tool1
-rw-r--r--   1 root     root           0 Feb 17  2008 tool2
-rw-r--r--   1 root     root           0 Feb 17  2008 tool3
[root@gandalf:/net/theoden/tools/solaris]$
[root@gandalf:/net/theoden/tools/solaris]$ mount                
[..]
/net/theoden/tools/solaris on theoden:/tools/solaris remote/read/write/nosetuid/nodevices/xattr/dev=4dc0002 on Sat Feb 16 10:23:01 2008

Neat isn’t it... it’s configured by default, when you start the autofs.

Do you want to learn more?

Manuals

How Autofs Works

Task Overview for Autofs Administration