挂载文件系统
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.博主推荐阅读
硬盘结构类型概述: https://www.cnblogs.com/yinzhengjie/p/12340062.html 分区表概述: https://www.cnblogs.com/yinzhengjie/p/12347792.html 文件系统概述: https://www.cnblogs.com/yinzhengjie/p/12369809.html
二.用mount命令临时挂载文件系统案例
1>.mount命令概述
mount常用命令选项如下: -t vsftype: 指定要挂载的设备上的文件系统类型,通常情况下无需指定,因为mount命令会自适应您所挂载分区对应的文件系统类型。 -r,readonly: 以只读方式挂载。 -w,read and write: 以读写方式挂载,默认就用该参数。 -n: 表示不更新/etc/mtab文件,即使用mount命令不可见,起到了隐藏挂载的作用,可以通过查看"/proc/mounts"该文件追踪内核挂载情况。
注意:该选项在CentOS 6.x支持良好,但在CentOS7.x支持的并不友好。我在CentOS 7.6版本测试时发现基于UUID方式挂载,依旧会修改"/etc/mtab"文件。 -a: 自动挂载所有支持自动挂载的设备(定义在了/etc/fstab文件中,且挂载选项中有auto功能) -L,'LABEL': 以卷标指定挂载设备,这种方式在RedHat 5.x系列使用相对较多,目前生产环境中不推荐大家使用基于卷标的方式挂载,因为卷标无法唯一确定一个设备。 -U 'UUID': 以UUID指定要挂载的设备,生产环境中强烈推荐基于UUID的方式进行挂载,因为UUID可以唯一标识一块设备。 -B, --bind: 绑定一个目录到另一个目录上,本质上挂载到后者所对应的分区,但使用df命令并不会显示,我们查看"/etc/mtab"或者"mount"命令均可以看到。 -o options:
指定挂载文件系统的选项,多个选项使用逗号分隔,常见选项如下所示: async:
异步模式,效率更快,数据会先放在buffer中,得带buffer内存达到指定阈值(比如按时间,或者内存使用百分比)时会溢写到磁盘,但存在数据丢失的风险。
sync同步模式:
内存更改时,同时写磁盘,效率较低,但安全性更强。因为内存要远远大于磁盘I/O速度。 atime/noatime:
包含目录和文件的访问(读)时间,对于访问Web文件没有必要记录访问时间,虽然数据不大,但随着QPS的增大频繁进行I/O操作也是一笔不小的开销,因此建议使用noatime参数进行挂载。 diratime/nodiratime:
目录的访问时间戳,同上,对于访问呢Web文件建议使用nodiratime。我在部署大数据集群时通常会将这两个参数不记录访问时间。 auto/noauto:
是否支持自动挂载,是否支持-a选项 exec/noexec:
是否支持在文件系统上运行应用程序,使用"noexec"参数进行挂载的文件系统,尽管文件有执行权限也无法执行。 dev/nodev:
是否支持在此文件系统上使用设备文件 suid/nosuid:
是否支持suid和sgid权限 remount:
重新挂载,基本上大部分目录都是可以卸载再重新挂载的,但是对于根目录是无法卸载的,此时我们就可以使用remount来重新挂载相关参数。 ro:
只读功能
rw:
读写功能 user/nouser:
是否允许普通用户挂载此设备,与"/etc/fstab"文件配合使用。 acl:
启用此文件系统上的acl功能,在CentOS 6.x的下默认是启用acl功能的,因此需要手动添加acl功能,而在CentOS 7.x则无需考虑,因为默认挂载就支持acl哟~ loop:
使用loop设备。即使用普通文件作为文件系统。在CentOS 6.x版本是需要加该参数的,但是在CentOS 7.x中就无需加该参数了,因为CentOS7.x版本相对智能。
CentOS 6.x默认有8个loop设备,如果想要使用更多的loop设备需要修改内核参数("/boot/grub/grub.conf"),在kernel那一行行中添加"max_loop=100"你要初始化的loop设备数量。
在CentOS 7.x我们挂载loop设备也无需指定"-loop"选项,CentOS 7.x会自动生成loop设备。 defaults:
如果不使用"-o"选项,则会使用默认选项,相当于rw, suid, dev, exec, auto, nouser, async。
[root@yinzhengjie.com ~]# mount -help Usage: mount [-lhV] mount -a [options] mount [options] [--source] <source> | [--target] <directory> mount [options] <source> <directory> mount <operation> <mountpoint> [<target>] Options: -a, --all mount all filesystems mentioned in fstab -c, --no-canonicalize don't canonicalize paths -f, --fake dry run; skip the mount(2) syscall -F, --fork fork off for each device (use with -a) -T, --fstab <path> alternative file to /etc/fstab -h, --help display this help text and exit -i, --internal-only don't call the mount.<type> helpers -l, --show-labels lists all mounts with LABELs -n, --no-mtab don't write to /etc/mtab -o, --options <list> comma-separated list of mount options -O, --test-opts <list> limit the set of filesystems (use with -a) -r, --read-only mount the filesystem read-only (same as -o ro) -t, --types <list> limit the set of filesystem types --source <src> explicitly specifies source (path, label, uuid) --target <target> explicitly specifies mountpoint -v, --verbose say what is being done -V, --version display version information and exit -w, --rw, --read-write mount the filesystem read-write (default) -h, --help display this help and exit -V, --version output version information and exit Source: -L, --label <label> synonym for LABEL=<label> -U, --uuid <uuid> synonym for UUID=<uuid> LABEL=<label> specifies device by filesystem label UUID=<uuid> specifies device by filesystem UUID PARTLABEL=<label> specifies device by partition label PARTUUID=<uuid> specifies device by partition UUID <device> specifies device by path <directory> mountpoint for bind mounts (see --bind/rbind) <file> regular file for loopdev setup Operations: -B, --bind mount a subtree somewhere else (same as -o bind) -M, --move move a subtree to some other place -R, --rbind mount a subtree and all submounts somewhere else --make-shared mark a subtree as shared --make-slave mark a subtree as slave --make-private mark a subtree as private --make-unbindable mark a subtree as unbindable --make-rshared recursively mark a whole subtree as shared --make-rslave recursively mark a whole subtree as slave --make-rprivate recursively mark a whole subtree as private --make-runbindable recursively mark a whole subtree as unbindable For more details see mount(8). [root@yinzhengjie.com ~]#