本文為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