要想实现自动挂载分区,大家都知道可以在/etc/fstab文件中添加即可,还有没有其他方法呢。有时我们会发现当把光盘放入主机驱动器后,光盘的内容能自动挂载在/media或/etc/cdrom/cd等目录下。这为我们提供了一个思路。
实现光盘自动挂载主要是由linux中/etc/init.d/autofs服务来负责的。一般来说这个进程都是开启的,也可以通过/etc/init.d/autofs status命令等方式查看当前该服务状态。该服务主要是通过执行/etc/auto.master和/etc/auto.misc 两文件来实现效果的。下面重点分析这两文件:
/etc/auto.master文件
以linux5.5系统为例,默认情况下该文件内容为:
[root@ENMOEDU ~]# cat /etc/auto.master
#
# $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
#
# 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 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
[root@ENMOEDU ~]#
由该文件看出,其实接下来最关键的动作是执行文件/etc/auto.misc。默认情况下,该文件内容如下:
[root@ENMOEDU ~]# 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/sdc1
#removable -fstype=ext2 :/dev/hdd
很明显,默认情况下linux会把/dev/cdrom挂接在/auto/cd中,并且给出了其他类似挂载样例。
综上所述,只要autofs服务启动,就能及时加载配置在/etc/auto.misc文件中的挂载信息。所以针对类如光盘、软盘动态性文件系统来讲,并不是时时刻时刻需要它,甚至用的极少。所以针对这类文件系统,我们可以使用autofs服务动态对实现对其挂载进行控制。而其他文件系统可以使用mount工具。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29620680/viewspace-1152671/
,如需转载,请注明出处,否则将追究法律责任。