Autofs
1. Introduction
autofs is a program for automatically mounting directories on an as-needed basis. Auto-mounts are mounted only as they are accessed, and are unmounted after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab.
1.1. Quick note on terms
To avoid confusion, the following terminologies will be used:
automount is the program used to configure a mount point for autofs. When autofs is started, an automount daemon is spawned for each map.
- Auto-mount or auto-mounting refers to the process of automatically mounting filesystems.
autofs is the program that controls the operation of the automount daemons.
2. Installation
Install the autofs package either by clicking here or entering the following in a terminal window:
$ sudo apt-get install autofs
3. Configuration
autofs can be configured by editing configuration files. There are other ways to configure autofs on a network (see AutofsLDAP), but config files provide the simplest setup.
3.1. The Master Map File
The master configuration file for autofs is /etc/auto.master by default. Unless you have a good reason for changing this, leave it as the default.
Here is the sample file provided by Ubuntu:
#
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc /etc/auto.misc --timeout=60
#/smb /etc/auto.smb
#/misc /etc/auto.misc
#/net /etc/auto.net
By default, all lines are commented out by using the # character.
Each of the lines in auto.master describes a mount and the location of its map. These lines have the following format:
mount-point [map-type[,format]:] map [options]
3.1.1. Direct and Indirect Maps
automount maps can be direct or indirect. Indirect maps, such as those in the auto.master file shown above, create-mount points as subdirectories inside the main mount-point. For example, consider the following master map entry:
/smb /etc/auto.smb
This entry in auto.master tells autofs to look in /etc/auto.smb and create mount-points in the /smb directory.
Direct maps create a mount-point at the path specified in the relevant map file. The mount-point entry in auto.master is always /-. For example, the following line instructs autofs to create a mount-point at the place specified in auto.data:
/- /etc/auto.data
- If the map file is not specified using a full local or network path, the Name Service Switch configuration will be used to locate the map, e.g.:
/- auto.data
3.2. Map Files
As indicated above, each autofs mount has its own map file. These files are usually named using the convention auto.<X>, where <X> can be anything as long as it matches an entry in auto.master and is valid for a file-name.
Map files take the following format:
key [-options] location
4. EXAMPLE: Auto-mounting an NFS share
In this howto, we will configure autofs to auto-mount an NFS share, using a set of configuration files. This howto assumes that you are already familiar with NFS exports, and that you already have a properly-functioning NFS share on your network. Go to the NFS Setup Page to learn how to set up such a server.
4.1. Edit /etc/auto.master
The following step creates a mount point at /nfs and configures it according to the settings specified in /etc/auto.nfs (which we will create in the next step).
- Type the following into a terminal:
$ sudo nano /etc/auto.master
Add the following line at the end of /etc/auto.master:
/nfs /etc/auto.nfs
4.2. Create /etc/auto.nfs
Now we will create the file which contains our automounter map:
$ sudo nano /etc/auto.nfs
This file should contain a separate line for each NFS share. The format for a line is {mount point} [{mount options}] {location}. If you have previously configured static mounts in /etc/fstab, it may be helpful to refer to those. Remember, the mount points specified here will be relative to the mount point given in /etc/auto.master.
The following line is for shares using older versions of NFS (prior to version 4):
server server:/
This creates a new mount point at /nfs/server/ and mounts the NFS root directory exported by the machine whose host-name is server.
4.2.1. NFSv4
If your NFS shares use NFSv4, you need to tell autofs about that. In such a case, the above line would appear as follows:
server -fstype=nfs4 server:/
The client needs the same changes to /etc/default/nfs-common to connect to an NFSv4 server.
In /etc/default/nfs-common we set:
NEED_IDMAPD=yes
NEED_GSSD=no # no is default
4.3. Unmount static mounts and edit /etc/fstab
If you have previously configured the NFS shares as static mounts, now is the time to unmount them.
$ sudo umount /server
Next, remove (or comment out) their respective entries in /etc/fstab.
#server:/ /server/ nfs defaults 0 0
4.4. Reload /etc/init.d/autofs
After entering your changes, run the following command to reload autofs:
$ sudo reload autofs
If working on an older ubuntu version, and that does not work try:
$ sudo /etc/init.d/autofs reload
If working in Natty, and that does not work try:
$ sudo /etc/init.d/autofs restart
4.5. Make sure it works
In order to access the share and verify that it is working properly, enter the following into a shell:
$ ls /nfs/server
If you see your NFS share listed, congratulations! You have a functioning NFS mount via autofs! If you want to learn some more advanced information, keep reading.
5. Advanced Information
Following the example directory structure above, if you were to enter ls /nfs into a shell, you might be surprised to see nothing listed. But remember that you need to access a directory before it is auto-mounted. To access the share, enter ls /nfs/server. Once it has been accessed, your share will be listed only until it times out. This is good to keep in mind, as it could save you time diagnosing an autofs problem that isn't really there.
5.1. Note on /net and /smb
These two default configurations may be useful for your set-up. If you have a lot of NFS or Samba shares, you may want to uncomment these lines. /net enables auto-mounting of file systems elsewhere on the network which are exported by NFS. For example, if you have a server named fileserver with an NFS export directory called /export, you can mount it by typing in a shell command line cd /net/fileserver/export. In an environment with NFS file servers, such a configuration can be useful. /smb functions the same way but is for Samba file systems. However, if you need to authenticate before accessing the Samba share, automount will not function.
5.2. Wildcard characters
Let's say you have a directory with a number of subdirectories which you want to have auto-mounted individually. An example of this is the /home directory, in which case /etc/auto.master might contain the following line:
/home /etc/auto.home
If user1 is logged in, you will want to auto-mount his home directory. However, if you create a mount point for the whole /home directory, you will also mount the home directories of every other user at the same time, thus wasting bandwidth. One solution to this would be to create separate entries for each directory, as follows:
# /etc/auto.home
user1 server:/home/user1
user2 server:/home/user2
user3 server:/home/user3
This works, but is cumbersome. Instead, you can use wild-card characters, as follows:
* server:/home/&
The asterisk (*) is used in place of the mount point and the ampersand (&) in place of the directory to be mounted. For more detail on the use of wild-cards see Using Wild-card Characters as Short-cuts in AutoFS Maps.
You can also use variables (see autofs(5) man page) to substitute users and other parameters to be able to create generic file for multiple users. Example below is smb map that maps based on user which asks for the share using $USER variable.
* -fstype=cifs,rw,credentials=/home/$USER/.smbcredentials,iocharset=utf8,uid=$USER,gid=users,file_mode=0700,dir_mode=0700 ://server/$USER
share1 -fstype=cifs,rw,credentials=/home/$USER/.smbcredentials,iocharset=utf8,uid=$USER,gid=users ://server/share1
share2 -fstype=cifs,rw,credentials=/home/$USER/.smbcredentials,iocharset=utf8,uid=$USER,gid=users ://server/share2
6. Mounting Other Types of Files Systems
6.1. CIFS
When specifying a CIFS share in a map file, specify -fstype=cifs and precede the share location with a colon (:).
Example:
mntpoint -fstype=cifs ://example.com/shrname
Example: Mount read-write, specifying a user and group to own the files:
mntpoint -fstype=cifs,rw,uid=myuserid,gid=mygrpid ://example.com/shrname
Example: Mount read-write, specifying a username and password to use to connect to the share:
mntpoint -fstype=cifs,rw,username=myuser,password=mypass ://example.com/shrname
6.2. FUSE based file systems
FUSE based file systems are mounted by specifying -fstype=fuse. The file-system location specifies the user-space binary used to mount the file system, followed by a hash (#), followed by the location.
When specifying a FUSE file system location in map file, certain characters, notably the hash (#) and the colon (:), must be escaped by a backslash (\). The entire location must be preceded by a colon (:).
Since automount performs the mount as root it is usually necessary to specify allow_other on the mount options to allow your non-root userid to access the share.
6.2.1. SSHFS file system
SSHFS is a FUSE based file-system. In an autofs mount, the colon (:) following the server name must be escaped by a backslash (\).
You should have already set-up password-less authentication via public key encryption. Be sure that you understand the security implications of this before proceeding.
Remember, automount will mount your SSHFS file-system as root, so you need to:
Copy your private key to the /root/.ssh directory. Be sure that you understand the security implications of this before proceeding.
Add the necessary host keys to /root/.ssh/known_hosts.
- Specify the user-name used to connect
To test mounting your SSHFS file system as root issued the following:
sudo sshfs user@example.com:/ mountpoint
If the mount succeeds without prompting you for a password, you are ready to mount the file-system via autofs
Example:
mntpoint -fstype=fuse,allow_other :sshfs\#user@example.com\:/path/to/mount
Example: Mount read-write, specifying a user and group to own the files:
mntpoint -fstype=fuse,rw,uid=1000,gid=1000,allow_other :sshfs\#user@example.com\:/path/to/mount
Note that for FUSE mounts, uid and gid must be numeric ids.
7. Debugging Auto Mount Problems
If you are having trouble automounting your file systems, it may be useful to run automount in the foreground.
Stop the autofs daemon
sudo service autofs stop
Run automount in the foreground with verbose information
sudo automount -f -v
- From another terminal, try to mount your file-systems by changing directories into the mountpoint.
- Check the output from the first terminal for clues as to why the mount failed or was not attempted.
8. See Also
Mount - Information about the mounting process and its configuration in Ubuntu.
9. External Links
The mount man page - hosted on the official Ubuntu website.
Autofs的更多相关文章
- autofs自动挂载
autofs是根据需要自动挂载,默认5分钟不使用自动卸载挂载点!nfs,smb,iso,sd*的挂载 环境:RHEL6.5/Centos6.5 172.24.0.25 01.安装autofs y ...
- autofs实现nfs自动挂载
apt-get install autofs 主配置文件/etc/auto.master 副配置文件可以在之配置文件中自定义 能生效的配置文件如下例: 将/usr/local/nginx/html挂载 ...
- Nis+Nfs+Autofs
Nis: NIS服务的应用结构中分为NIS服务器和NIS客户机两种角色 NIS服务器集中维护用户的帐号信息(数据库)供NIS客户机进行查询 用户登录任何一台NIS客户机都会从NIS服务器进行登录认证, ...
- Linux nfs+autofs 环境搭建
两台服务器环境为centos 6.6 1.安装配置nfs 安装portmap 和 nfs [root@node0 ~]# yum install portmap [root@node0 ~]# yu ...
- RHCE之配置autofs远程挂载远程服务器的家目录
[root@server0 ~]# yum -y install autofs 安装包 [root@server0 ~]# vim /etc/auto.master ...
- Autofs自动挂载探讨
Autofs介绍: mount是用来挂载文件系统的,可以在系统启动的时候挂载也可以在系统启动后挂载.对于本地固定设 备,如硬盘可以使用mount挂载:而光盘.软盘.NFS.SMB等文件系统具有动态性, ...
- 绑定到外部验证服务LDAP、配置 autofs
题1:您的系统需要按照以下要求绑定到这个服务上:验证服务器的基本 DN 是: dc=xxxx,dc=xxxx,dc=xxxx. 帐户信息和验证信息都是由 LDAP 提供的.连 接 需 要 使 用 证 ...
- NFS使用autofs自动挂载
NFS自动挂载设置在/etc/fstab和/etc/rc.local可能挂载不成功,假如是服务端NFS宕机还可能导致客户端无法启动,可以使用autofs实现自动挂载 安装autofs yum -y i ...
- 004.Autofs自动挂载
一 安装autofs [root@imxhy data]# yum -y install autofs 二 编辑自动挂载相关配置 2.1 修改master [root@imxhy ~]# vi /et ...
随机推荐
- K-means算法的实现
K-MEANS算法是一种经典的聚类算法,在模式识别得到了广泛的应用.算法中有两个关键问题需要考虑:一是如何评价对象的相似性,通常用距离来度量,距离越近越相似:另外一个是如何评价聚类的效果,通常采用误差 ...
- Push API
[Push API] The Push API gives web applications the ability to receive messages pushed to them from a ...
- SQLMAP自动注入(三):参数介绍
--delay延时扫描 --scope 从burpsuit日志中过滤日志内容,通过正则表达式筛选扫描目标,19开头,尾数为1.11.121.221的目标 --level=3 会检查user-agent ...
- 【翻译】View Frustum Culling --2 Geometric Approach – Extracting the Planes
在上一篇中,我们知道了视锥体的形状,并且也确定了我们进行裁剪时的步骤.那我们接下来要走的就是确定视锥体的六个平面: near, far, top, bottom, left and right 2.计 ...
- Codeforces Beta Round #59 (Div. 2)
Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A #include<bits/stdc++.h> ...
- python指针
class ListNode: def __init__(self, x): self.val = x self.next = None就两个属性 value 和 next,因为单节点默认next是没 ...
- [剑指Offer]25-合并两个排序链表
题目链接 https://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337?tpId=13&tqId=11169&t ...
- f5源站获取http/https访问的真实源IP解决方案
1.背景 F5负载均衡设备,很多场景下需要采用旁挂的方式部署.为了保证访问到源站的数据流的request和response的TCP路径一致,f5采用了snat机制.但是这样导致源站上看到的来源IP都是 ...
- 官方教程:Apache Kylin和Superset集成,使用开源组件,完美打造OLAP系统
本文转自Apache Kylin公众号apachekylin. Superset 是一个数据探索和可视化平台,设计用来提供直观的,可视化的,交互式的分析体验. Superset 提供了两种分析数据源的 ...
- 【linux C】C语言中常用的几个函数的总结【一】
1.memset函数 定义变量时一定要进行初始化,尤其是数组和结构体这种占用内存大的数据结构.在使用数组的时候经常因为没有初始化而产生“烫烫烫烫烫烫”这样的野值,俗称“乱码”.每种类型的变量都有各自的 ...