autofs 自动挂载

autofs 简介

    mount 是用来挂载文件系统的,可以在系统启动时挂载(/etc/fstab),也可以在系统启动后挂载(使用 mount 命令)。而光盘、软盘、NFS、SMB 等文件系统具有动态性,即需要的时候才有必要挂载。光驱和软盘一般知道什么时候需要挂载,但是 NFS 和 SMB 就不一定能确定挂载时间。而且 NFS 、 SMB 是基于网络的,不管使用或者不使用,都会造成资源浪费(多少情况下,不用到这些的时候,这些挂载其实是不需要一直存在的)。

    而autofs恰好提供了一种功能:如果你长时间(可定义这个timeout值)不用一个文件系统(本地、nfs、smbfs等等),autofs会把这个文件系统卸载;当你需要用到的时候,只需要cd到挂载点或者ls下挂载点,autofs会为你自动挂接。


autofs 配置

    autofs的主要配置文件有两个,分别是/etc下的auto.master和auto.misc。其中,auto.master 是起控制作用的,它定义了挂载点和automount动作的文件(映射文件)。其内容如下:

#
# 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
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
#
# Include /etc/auto.master.d/*.autofs
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/misc是定义的自动mount的挂载点,/etc/auto.misc里定义了mount的动作


/etc/auto.misc的内容如下:

#
# 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

#将/dev/cdrom自动挂载到/misc/cd/下
cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom    

# the following entries are samples to pique your imagination
#将ftp.example.org的共享目录 /pub/linux/ 自动挂载到 /misc/linux/ 下
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
#将本地磁盘分区 /dev/hda1 自动挂载到 /misc/boot 下
#boot           -fstype=ext2            :/dev/hda1
#将软盘设备 /dev/fd0 自动挂载到 /misc/floppy 下
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd
这些资源只有在试图访问的时候才会去自动挂载,而在一段时间之后,如果不再使用这些资源, autofs 会自动卸载这些资源。默认时间为5分钟(300秒),此选项由 /etc/sysconfig/autofs 定义,根据需要可以修改。 


    一般的操作步骤是,在 /etc/auto.master 文件中定义挂载点和映射文件,然后创建映射文件,并写入挂载的动作。还有一种方法是在 /etc/auto.master.d  下创建自动挂载的配置文件(必须以 .autofs 作为配置文件扩展名,语法同 auto.master ),然后再创建映射文件(映射文件需要和配置文件对应) 


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值