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
Situation
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 is very simple, but it appears to work surprisingly well
# add "nonstrict" to make it OK for some filesystems to not mount
opts="-fstype=nfs,hard,intr,nodev,nosuid"
# 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"
do
for M in showmount kshowmount
do
if [ -x $P/$M ]
then
SMNT=$P/$M
break
fi
done
done
SHOWMOUNT="$SMNT --no-headers -e $key"
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 }
'
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
#!/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.
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
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com