AutoFS

From Gentoo Wiki
Jump to: navigation, search

AutoFS uses the Linux kernel Automounter to automatically mount several types of media like memory sticks, network shares, CD-Rom/DVD/BR etc. on demand.

Installation

Kernel

Activate the following kernel options:

KERNEL
File systems --->
    <*> Kernel automounter version 4 support (also supports v3)

USE flags

Optiona USE flags for net-fs/autofs:
USE flag (what is that?) Default Recommended Description
dmalloc No Enable debugging with the dmalloc library
hesiod No Install hesiod module
ldap No Install LDAP module
libtirpc No Use libtirpc lib support
sasl No Enable SASL support in the LDAP module
mount-locking No Enable locking to prevent corruption of /etc/mtab in the presence of concurrent auto-mounting. If enabled, recursive auto-mounting (eg. using autofs to bind or loop mount a filesystem which is itself auto-mounted) is not possible.

Emerge

Install net-fs/autofs:

root #emerge --ask net-fs/autofs

Configuration

Service

OpenRC

Start and add AutoFS to the default runlevel:

root #/etc/init.d/autofs start
root #rc-update add autofs default

Files

The configuration files are found in the following locations:

  • /etc/conf.d/autofs
  • /etc/autofs/auto.master
  • /etc/autofs/auto.misc

Usage

General configuration files for AutoFS.

Important
You probably need to install additional software and modules to mount DVD, NFS, CIFS etc. The mount helpers need to be available for each file system you configure.

autofs configuration

The default options for autofs can be changed by setting the proper configuration variables located in /etc/conf.d/autofs. The default location for the master map is (/etc/autofs/auto.master). It can be changed by setting the MASTER_MAP_NAME configuration variable in /etc/conf.d/autofs.

Note
The following examples of configuration files take into account the default location for auto.master.

auto.master

In this configuration file is defined what other configuration files should be included as root mount-point. Here is one example with one additional mount-point on /mnt/auto:

FILE /etc/autofs/auto.master
+auto.master # extry needed for NIS mapping
# Here are the files listed, that should be included
# mount-point | config file | options
/mnt/auto   /etc/autofs/auto.misc    --timeout=15 --ghost
Note
/mnt/auto is the root mount-point for all file systems defined in auto.misc. --timeout defines how many seconds to wait before the file system is unmounted. --ghost creates empty folders for each mount-point in auto.misc, this prevents timeouts if a network share cannot be contacted.

auto.misc

Here is our example for the file auto.misc. The folders for the mount-points are automatically created:

FILE /etc/autofs/auto.misc
# mount-point below /mnt/auto | mount options | device, network share etc.
 
# CD-Rom on /mnt/auto/cd
cd              -fstype=iso9660,ro,nosuid,nodev              :/dev/cdrom
# nework share mounted via NFSv3 on /mnt/auto/data
data            -rw,vers=3,soft,async                        192.168.0.254:/tank1/data
# nework share mounted via CIFS on /mnt/auto/data1
data1           -fstype=cifs,credentials=/root/smb.txt       ://192.168.0.254/data1
# memory stick used regulary with known UUID, for example a kindle
kindle          -fstype=vfat,rw,uid=1000                     :UUID="4CBF-23A2"
Note
There are several more examples in the auto.misc that comes with the package

Simple Windows-like SMB shares usage

If you want to use network SMB shares easily you can try the following configuration. You will be able to automount, for example, by issuing "cd /net/10.50.40.32/share" command in shell or "/net/10.50.40.32/share" in a browser or commander and work with the files inside as they were located on local machine. Make the following modifications:

FILE /etc/autofs/auto.master
#+auto.master
/net file:/etc/autofs/auto.smbm --ghost --nonstrict
FILE /etc/autofs/auto.smbm
* -fstype=autofs,-Dhost=& file://etc/autofs/auto.share
FILE /etc/autofs/auto.share
* -fstype=cifs,username=guest,password=,file_mode=0664,dir_mode=0775,uid=netmount,gid=netmount,port=139 ://${host}/&

Restart autofs daemon and you are ready to use simple automount.

External resources