linux怎么自动挂载,Linux之自动挂载

博客详细介绍了如何使用Autofs进行自动挂载和卸载操作,包括安装autofs软件包,配置主配置文件(/etc/auto.master)和映射文件,以及如何管理本地设备和远程NFS。通过编辑映射文件,可以实现对NFS共享目录的自动挂载。此外,还提到了通过查看系统日志解决autofs挂载问题的方法,并展示了挂载Windows网络邻居目录的SMBFS配置。
摘要由CSDN通过智能技术生成

程序名automounter,安装autofs软件包

起到自动挂载访问的分区的作用

它提供一个autofs的守护进程,在系统启动的时候自动运行,守护着系统的某个目录,判断是否有对某个设备的访问,有就挂载,没有就卸载,不仅能管理本地的设备,还可以管理nfs

编辑两个配置文件:主配置文件和映射文件

主配置文件默认为/etc/auto.master,格式:

/misc    /etc/auto.misc --timeout=60

挂载目录 映射文件          参数

挂载目录就是autofs的工作目录,aufs启动时会自动进入挂载目录,监视这个目录中的每个访问点

映射文件就是一张具体的表,里面包含要监视的设备和目录名也就是关键字,映射文件默认是auto.misc也可以不使用它,自己指定.主配置文件指定了哪个映射文件,后面就再编辑哪个文件就行了

这个参数是超时60秒不使用就自动卸载

挂载是由访问产生的,卸载是由超时时间产生的

映射文件格式:

关键字   挂载选项        设备

cd -fstype=iso9660,ro   :/dev/cdrom

fd -fstype=auto       冒号 :/dev/fd0

关键字:是外设的一个具体的挂载目录autofs守护进程就是根据它来判断要访问哪个设备

挂载选项可有可无

设备: 当要访问一个关键字的时候,会自动把设备挂载到关键字所对应的目录中去

注意:如果挂载的是本地的设备前必须要加:

主配置文件的挂载目录+映射文件的关键字

ls misc/cd

这样系统会在/misc中自动创建一个cd目录,而不是早就手动建立的.

修改完配置文件后要重启autofs让它重新读取配置文件

service autofs restart

[root@rhel ~]# rpm -q autofs

autofs-4.1.3-67

[root@rhel ~]# rpm -ql autofs |more

vi /etc/auto.master

# $Id: auto.master,v 1.3 2003/09/29 08:22:35 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

/yliang /etc/yliang.auto --timeout=30

#/net   /etc/auto.net

[root@rhel ~]# more /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

#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

service autofs restart

ls /misc/cd

ok !!!!!!!!!!!

手动挂载NFS

mount 1.1.1.1:/var/ftp/pub /mnt   冒号两边不能有空格

使用autofs在映射文件里这样写

pub   -fstype=nfs,ro 1.1.1.1:/var/ftp/pub

ls /misc/pub

ok!!!!!!!!!!

如果出现autofs挂载不了的情况,查看autofs的日志

tail /var/log/messages

[root@rhel ~]# tail /var/log/messages

Apr 12 10:13:27 rhel fstab-sync[2891]: added mount point /media/cdrom for /dev/hdc

Apr 12 10:13:28 rhel fstab-sync[2913]: added mount point /media/floppy for /dev/fd0

Apr 12 10:18:08 rhel sshd(pam_unix)[3006]: session opened for user root by root(uid=0)

Apr 12 10:28:55 rhel autofs: automount shutdown succeeded

Apr 12 10:28:56 rhel autofs: automount startup succeeded

用autofs挂载win网上邻居中的目录 SMBFS

也是通过编辑映射文件来实现的

vi /etc/auto.misc

win -fstype=smbfs,username=yliang%password ://winxp/e

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值