Autofs: Difference between revisions

From Leo's Notes
This page was last edited on 14 June 2020, at 22:00.
Created page with "The linux automounter. cat /etc/auto.home <syntaxhighlight lang="bash" line start="1" enclose="div"> #!/bin/sh # This can be a script.. with the username passed as the fir..."
 
mNo edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
The linux automounter.
{{code|autofs}} is the linux automounter. It's a daemon that automatically mounts filesystems as they are accessed on demand.


== Configuration ==
The primary configuration file used by automount is {{code|/etc/auto.master}} which defines what mounts automount is responsible for.
<syntaxhighlight lang="bash" line start="1" enclose="div">
#
# /etc/auto.master
#
+auto.master
/home  /etc/auto.home
</syntaxhighlight>
In the example above, automount is responsible for mounting directories under /home and the configuration for it is under {{code|/etc/auto.home}}. The configuration under {{code|/etc/auto.home}} will define directories in {{code|/home}} and their corresponding mount locations.
<syntaxhighlight lang="bash" line start="1" enclose="div">
#
# /etc/auto.home
#
leo    file1:/export/home/leo
</syntaxhighlight>
Anyone going to {{code|/home/leo}} will cause automount to mount {{code|/home/leo}} from {{code|file1:/export/home/leo}}.
You may specify mount options by placing them before the mount location:
<syntaxhighlight lang="bash" line start="1" enclose="div">
#
# /etc/auto.home
#
leo  -fstype=nfs4    file1:/export/home/leo
</syntaxhighlight>
== Dynamic Automount Rules ==
The automount configuration can be made as a script to make mounting more intelligent. automount will pass in the mounting point to your {{code|auto}} mount configuration.
For example, if home directories are stored on multiple file servers, we can make {{code|/home}} the mounting point for ''all'' users by doing something like so:


cat /etc/auto.home
<syntaxhighlight lang="bash" line start="1" enclose="div">
<syntaxhighlight lang="bash" line start="1" enclose="div">
# cat /etc/auto.home
#!/bin/sh
#!/bin/sh


# This can be a script.. with the username passed as the first parameter.
# Automount will pass in the username as the first parameter since we are
# mounting /home/<username>
Username=$1
Username=$1
Server="file2"
 
# The default fileserver is 'file1'
Server="file1"
 
# The path to the mount for this user
Path="/export/home/$Username"
Path="/export/home/$Username"


# Proof of concept.
# As a proof of concept, we can make a specific user use a different filesersver
# We can pull the file server from AD using a ldap search
# Eg: leo's home directory will be mounted from file2
# and have home directories placed in /home for all.
if [ "$Username" = "leo" ] ; then
# This is nice because home directories are now mounted as
     Server="file2"
# needed rather than mounting the entire file server.
if [ "$Username" = "leo3" ] ; then
     Server="file1"
fi
fi


# Echo out the configuration for automount
echo "-fstype=nfs4,sec=krb5,soft,rsize=8192,wsize=8192,rw  $Server:$Path"
echo "-fstype=nfs4,sec=krb5,soft,rsize=8192,wsize=8192,rw  $Server:$Path"
</syntaxhighlight>
</syntaxhighlight>


 
{{Navbox Linux}}[[Category:Linux]]
 
[[Category:LinuxUtilities]]
[[Category:Linux]]
[[Category:Todo]]

Latest revision as of 22:00, 14 June 2020

autofs is the linux automounter. It's a daemon that automatically mounts filesystems as they are accessed on demand.

Configuration

The primary configuration file used by automount is /etc/auto.master which defines what mounts automount is responsible for.

#
# /etc/auto.master
#
+auto.master
/home   /etc/auto.home

In the example above, automount is responsible for mounting directories under /home and the configuration for it is under /etc/auto.home. The configuration under /etc/auto.home will define directories in /home and their corresponding mount locations.

#
# /etc/auto.home
#
leo    file1:/export/home/leo

Anyone going to /home/leo will cause automount to mount /home/leo from file1:/export/home/leo.

You may specify mount options by placing them before the mount location:

#
# /etc/auto.home
#
leo   -fstype=nfs4    file1:/export/home/leo

Dynamic Automount Rules

The automount configuration can be made as a script to make mounting more intelligent. automount will pass in the mounting point to your auto mount configuration.

For example, if home directories are stored on multiple file servers, we can make /home the mounting point for all users by doing something like so:

# cat /etc/auto.home
#!/bin/sh

# Automount will pass in the username as the first parameter since we are
# mounting /home/<username>
Username=$1

# The default fileserver is 'file1'
Server="file1"

# The path to the mount for this user
Path="/export/home/$Username"

# As a proof of concept, we can make a specific user use a different filesersver
# Eg: leo's home directory will be mounted from file2
if [ "$Username" = "leo" ] ; then
    Server="file2"
fi

# Echo out the configuration for automount
echo "-fstype=nfs4,sec=krb5,soft,rsize=8192,wsize=8192,rw   $Server:$Path"