🌐 🇵🇱 Polski · 🇬🇧 EN
To make an administrator's life easier, they can use a tool called AutoFS, which is an automatic file system. The benefit of this is that remote resources can be mounted automatically without the need for root privileges. This is achieved by using a special configuration file called a map. To configure and work with AutoFS, you need to know two files.
/etc/sysconfig/autofs - Main service configuration file
/etc/auto.master - Main mapping file
In /etc/sysconfig/autofs, you can define default values for the service, including timeout, map file name, logging, and much more. Let's see how to use it:
# cat /etc/sysconfig/autofs | grep -v ^#
TIMEOUT=300
BROWSE_MODE=”no”
MOUNT_NFS_DEFAULT_PROTOCOL=4
USE_MISC_DEVICE=”yes”
The values above are suitable for a default configuration, along with the comments and other options contained in the file. If you need a basic service, these settings are sufficient. However, if you want to better utilize the capabilities of AutoFS, there are 4 different types of mapping files available:
- master - The default mapping file containing other types of mapping files
- special - A mapping file that allows for group mappings contained in a single file
- direct - A mapping file that requires a manual restart before changes take effect
- indirect - A mapping file used to mount sources under a parent directory
Here is what the /etc/auto.master file looks like:
# cat auto.master | grep -v ^#
/misc /etc/auto.misc
/net -hosts
+auto.master
The first entry is an indirect mapping. The first part of the entry, "/misc", defines the common parent directory under which resources will be mounted. Next, we specify the file that stores the actual resources, including their location, permissions, and name. The /etc/auto.misc file is already created and contains sample entries:
# cat /etc/auto.misc
#
# $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/hdc1
#removable -fstype=ext2 :/dev/hdd
The file uses the following syntax:
[relative pathname] [mount options] [location]
We can see how the CD-ROM is defined.
Preparing RHEL01
To test the capabilities of "autofs", you need to share a directory on the RHEL01 machine that will be automatically mounted on Client01. To do this, we add an entry to the /etc/exports file on the RHEL01 machine:
[root@RHEL01 opt]# cat /etc/exports
/opt/company_data1 *(rw,sync)
/opt/company_data2 *(rw,sync)
/opt/company_data *(rw,sync)
Then we restart the services:
/etc/init.d/nfs restart
/etc/init.d/nfslock restart
To verify the share, we can run the command:
# showmount -e localhost
Export list for localhost:
/opt/company_data *
Preparing RHEL01
To test the capabilities of "autofs", you need to share a directory on the RHEL01 machine that will be automatically mounted on Client01. To do this, we add an entry to the /etc/exports file on the RHEL01 machine:
[root@RHEL01 opt]# cat /etc/exports
/opt/company_data1 *(rw,sync)
/opt/company_data2 *(rw,sync)
/opt/company_data *(rw,sync)
/etc/init.d/nfs restart
/etc/init.d/nfslock restart
To verify the share, we can run the command:
# showmount -e localhost
Export list for localhost:
/opt/company_data *
Step 1 - On the previously created "Client01" machine, we will create an entry in the /etc/auto.misc file:
company_data -rw,sync rhel01:/opt/company_data
Step 2 - Save the file and refresh the autofs service:
# service autofs reload
Reloading maps
Now, by browsing /misc, you can see another location referring to "company_data". If this resource is available, it will be mounted from the RHEL01 machine to /misc/company_data. This is a very convenient option that provides access to multiple resources from a single client.
You only need to remember one thing when using indirect mapping. It is possible to use two symbols. If you want to mount a user's home directory in this way, you need to create the following entry in the mapping file:
* -rw,sync &:/home/&
The system automatically verifies the username and automatically searches for all available remote resources. This allows for easier centralized management of home directories. Configuration of the /etc/auto.master file is performed in a similar way.
Step 3 - In the /etc/auto.master file, we add the entry:
/- /etc/auto.direct_maps
This entry informs /etc/auto.master that the mappings are located in /etc/auto.direct_maps. When we create an "indirect" mapping, we must provide a relative path for each mapping, but for direct mappings, we simply provide an absolute path for each one. For example, we want to mount the remote resource /opt/company_data from the RHEL01 machine to the local directory /usr on the "Client01" machine instead of /misc.
Step 4 - We must create the /etc/auto.direct_maps file and add the entry:
/usr/data -rw,sync rhel01:/opt/company_data
Step 5 - Save the file and reload the autofs service.
# service autofs reload
Reloading maps
Now, the local path /usr/data on the "Client01" machine will be automatically mounted from /opt/company_data on the RHEL01 machine. It is important to understand the difference between a local directory and a mapping file when working with autoFS.
Let's return to /etc/auto.master, where the second entry concerned group mapping. This entry causes a search for all available remote resources that exist on the network and mounts the available resources under defined local directories. This feature becomes useful when you want to mount many resources on a single client without having to create individual mappings for each one. However, it is not a good idea if you have many resources on different machines. Using autoFS is not difficult. It just requires a bit of practice to fully understand the concept.
Useful links:
http://blog.grzeszy.net/automontowanie-systemow-plikow-w-systemie-linux
http://www.adminlinux.org/2009/06/how-to-autofs-nfs-automount.html
http://banita.pl/konf/smbmapunix.html
Useful links:
http://blog.grzeszy.net/automontowanie-systemow-plikow-w-systemie-linux
http://www.adminlinux.org/2009/06/how-to-autofs-nfs-automount.html
http://banita.pl/konf/smbmapunix.html
Comments