SUSE Support

Here When You Need Us

Using the Linux automounter to access all exports on any remote host.

This document (3667760) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 10
SUSE Linux Enterprise Desktop 10
SUSE Linux Enterprise Server 9 SP3
 

Situation

Using the Linux automounter to access all exports on any remote host.

Resolution

The method described in this document configures the automounter so that when someone changes directory into /net/%anyhost (where %anyhost is replaced with any host name), all exports on the specified host will be mounted underneath that directory. For example, if the remote host is exporting /share1 and /share2, two mount points will be created and the remote exports mounted, when someone enters /net/hostname: /net/hostname/share1 and /net/hostname/share2.

This method very closely approximates the -hosts functionality which is available in some other automounters, for example, the Solaris automounter. The difference is that on Solaris, when you cd to /net/hostname, you haven't actually mounted anything yet, but it will show you all potential paths if you 'ls' at that point. With the method described in this document, the Linux automounter will actually mount everything.

 
To accomplish this on SLES 10 or SLED 10:
 
1. The autofs 4.x package must be installed. It typically is installed already, but this can be verified with:
rpm -qa | grep autofs
 
2. Set autofs to launch automatically in run levels 3 and 5. This can be done with:
chkconfig autofs 35
 
3. Edit the /etc/auto.master file and remove the # from the /net line:
/net /etc/auto.net
 
4. There is already a /etc/auto.net file supplied from autofs 4.x containing the script which accomplishes the logic to detect and mount the available exports on whatever server is specified when someone tries to cd into /net/server_name. Make sure this file is owned by root and is executable (755). No modifications should be needed to the file contents. For reference purposes, here's a copy:
 
#!/bin/bash
# $Id: auto.net,v 1.8 2005/04/05 13:02:09 raven Exp $
# This file must be executable to work! chmod 755!
# Look at what a host is exporting to determine what we can mount.
# This is very simple, but it appears to work surprisingly well
key="$1"
# add "nosymlink" here if you want to suppress symlinking local filesystems
# add "nonstrict" to make it OK for some filesystems to not mount
opts="-fstype=nfs,hard,intr,nodev,nosuid"
# Showmount comes in a number of names and varieties. "showmount" is
# typically an older version which accepts the '--no-headers' flag
# but ignores it. "kshowmount" is the newer version installed with knfsd,
# which both accepts and acts on the '--no-headers' flag.
#SHOWMOUNT="kshowmount --no-headers -e $key"
#SHOWMOUNT="showmount -e $key | tail -n +2"
for P in /bin /sbin /usr/bin /usr/sbin
do
for M in showmount kshowmount
do
if [ -x $P/$M ]
then
SMNT=$P/$M
break
fi
done
done
[ -x $SMNT ] || exit 1
# Newer distributions get this right
SHOWMOUNT="$SMNT --no-headers -e $key"
$SHOWMOUNT | LC_ALL=C sort +0 | \
awk -v key="$key" -v opts="$opts" -- '
BEGIN { ORS=""; first=1 }
{ if (first) { print opts; first=0 }; print " \\\n\t" $1, key ":" $1 }
END { if (!first) print "\n"; else exit 1 }
'
 
5. To start autofs on the fly (rather than having to reboot) give the command: rcautofs start
 

 
To accomplish this on SLES 9 SP3:
 

1. Remove autofs 3.x and add autofs4. Both packages are available in SLES 9 SP2 and SP3, but autofs 3.x is the one installed by default. Check the version of the installed autofs package to verifiy whether it is a 3.x version or already a 4.x version (rpm -qa | grep autofs).

2. As root, execute: chkconfig autofs 35
this will make sure autofs is scheduled to come up in run levels 3 and 5

3. Edit the /etc/auto.master file and make sure the following line exists and is not remarked out:
/net /etc/auto.net
 
4. /etc/auto.net should contain a script. It is likely that this auto.net will be supplied when autofs4 is installed, but it is shown here for convenience: Also make sure this file is owned by root, and chmod it to 755 so it can be executed (since it is a script whose purpose is to dynamically build the necessary multi-mount map).

#!/bin/sh
# $Id: auto.net,v 1.5 2003/09/29 08:22:35 raven Exp $
# Look at what a host is exporting to determine what we can mount.
# This is very simple, but it appears to work surprisingly well

key="$1"

# add "nosymlink" here if you want to suppress symlinking local filesystems
# add "nonstrict" to make it OK for some filesystems to not mount
opts="-fstype=nfs,hard,intr,nodev,nosuid"

# Showmount comes in a number of names and varieties. "showmount" is
# typically an older version which accepts the'--no-headers' flag
# but ignores it. "kshowmount" is the newer version installed with knfsd,
# which both accepts and acts on the '--no-headers' flag.
#SHOWMOUNT="kshowmount --no-headers -e $key"
#SHOWMOUNT="showmount -e $key | tail +2"

# Newer distributions get this right
SHOWMOUNT="/usr/sbin/showmount --no-headers -e $key"

$SHOWMOUNT | sort +0 | \
awk -v key="$key" -v opts="$opts" -- '
BEGIN { ORS=""; first=1 }
{ if (first) { print opts; first=0 }; print " \\\n\t" $1, key ":" $1 }
END { if (!first) print "\n"; else exit 1 }
'

5. To test the script and see it's output, execute: /etc/auto.net %nfshost
where %nfshost is replaced by the name of a remote host that is exporting nfs shares. Examples of the command and the output follow:

/etc/auto.net dp65

-fstype=nfs,hard,intr,nodev,nosuid \
/data dp65:/data \
/nss2 dp65:/nss2 \
/sys/ftp dp65:/sys/ftp

6. Edit /etc/modprobe.conf. Normally, a few lines down, there is a remarked line that shows"#alias autofs autofs4". Remove the # so it is no longer just a comment. (Note: In future distributions, if autofs4 has become autofs, this step should be skipped).

7. Reboot. (Alternative: If you want to test this without rebooting, see the NOTE below.)

8. After reboot, to verify the right autofs module is really loaded into the kernel, execute: lsmod | grep auto
and you should see autofs4 (not autofs) present. (Again, if future distributes rename autofs4 to autofs, you will just see autofs in the list, not autofs4.)

NOTE: If you want to test the functionality without rebooting (step #7) then do the following. However, this won't prove that the service will be running properly after a reboot. You should do step 7 and then step 8 to prove that.

rcautofs stop
rmmod autofs
modprobe autofs4
rcautofs start

Additional Information


Formerly known as TID# 10100455

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:3667760
  • Creation Date: 28-Feb-2007
  • Modified Date:23-Mar-2021
    • SUSE Linux Enterprise Desktop
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

tick icon

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

tick icon

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

tick icon

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.