前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >一天一个 Linux 命令(31):mount 命令

一天一个 Linux 命令(31):mount 命令

作者头像
joshua317
发布2021-10-25 11:05:56
9040
发布2021-10-25 11:05:56
举报
文章被收录于专栏:技术博文技术博文技术博文

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/174

一、简介

Linux下的mount命令用于加载文件系统到指定的加载点。

二、格式说明

mount [-lhV]
mount -a [options]
mount [options] [--source] <source> | [--target] <directory>
mount [options] <source> <directory>
mount <operation> <mountpoint> [<target>]

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

三、选项说明

-a:加载文件"/etc/fstab"中描述的所有文件系统
-f:通常用在除错的用途。它会使 mount 并不执行实际挂上的动作,而是模拟整个挂上的过程。通常会和 -v 一起使用
-F:这个命令通常和 -a 一起使用,它会为每一个 mount 的动作产生一个行程负责执行。在系统需要挂上大量 NFS 文件系统时可以加快挂上的动作
-t:指定文件系统的类型,通常不必指定。mount 会自动选择正确的类型
-T:/etc/fstab的替代文件
-h:显示辅助讯息
-l: 列出所有带有labels的挂载
-L:将含有特定标签的硬盘分割挂上。
-n:一般而言,mount 在挂上后会在 /etc/mtab 中写入一笔资料。但在系统中没有可写入文件系统存在的情况下可以用这个选项取消这个动作。
-s-r:等于 -o ro
-w:等于 -o rw
-U:将文件分割序号为 的文件系统挂下。-L 和 -U 必须在/proc/partition 这种文件存在时才有意义。
-o async:打开非同步模式,所有的文件读写动作都会用非同步模式执行。
-o sync:在同步模式下执行。
-o atime、-o noatime:当 atime 打开时,系统会在每次读取文件时更新文件的『上一次调用时间』。当我们使用 flash 文件系统时可能会选项把这个选项关闭以减少写入的次数。
-o auto、-o noauto:打开/关闭自动挂上模式。
-o defaults:使用预设的选项 rw, suid, dev, exec, auto, nouser, and async.
-o dev、-o nodev-o exec、-o noexec允许执行档被执行。
-o suid、-o nosuid:
允许执行档在 root 权限下执行。
-o user、-o nouser:使用者可以执行 mount/umount 的动作。
-o remount:将一个已经挂下的文件系统重新用不同的方式挂上。例如原先是唯读的系统,现在用可读写的模式重新挂上。
-o ro:用唯读模式挂上。
-o rw:用可读写模式挂上。
-o loop=:使用 loop 模式用来将一个文件当成硬盘分割挂上系统。
-v:显示较讯息,通常和 -f 用来除错
-V:显示程序版本

四、命令功能

用于挂载Linux系统外的文件系统。

五、常见用法

5.1 启动所有挂载
# mount -a
5.2 挂载分区 /dev/vdb1 到 /data:
#建立挂载点目录
#mkdir /data

#挂载分区
#mount /dev/vdb1 /data

#查看挂载结果
#df -h
5.3 将 /dev/vdb1用只读模式挂在 /data之下
#mount -o ro /dev/vdb1 /data
5.4 挂载nfs类型的文件系统
#mount -t nfs /data/share /data

#挂载服务器的共享目录到本地目录,把远程目录/home/data挂载到本地目录 /data
mount -t nfs 192.168.1.101(服务器地址):/home/data /data(共享到该目录)

注意:/data/share是分享目录,/data是直接操作目录,这样操作/data的这个目录就相当于直接/data/share分享的目录了,当然,操作/data/share的分享的目录,这个/data里的内容也会跟着变

5.5 挂载第一块盘的第一个分区到/etc目录
# mount -t ext4 -o loop,default /dev/vda1 /etc

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/174

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-10-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、简介
  • 二、格式说明
  • 三、选项说明
  • 四、命令功能
  • 五、常见用法
    • 5.1 启动所有挂载
      • 5.2 挂载分区 /dev/vdb1 到 /data:
        • 5.3 将 /dev/vdb1用只读模式挂在 /data之下
          • 5.4 挂载nfs类型的文件系统
            • 5.5 挂载第一块盘的第一个分区到/etc目录
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档