本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/175
一天一個 Linux 命令(32):umount命令
Linux下的umount命令用於卸除文件系統。umount可卸除目前掛在Linux目錄中的文件系統。mount是掛載,整好相反。
二、格式說明
umount [-hV]
umount -a [options]
umount [options] <source> | <directory>
umount [參數] [文件系統]
Usage:
umount [-hV]
umount -a [options]
umount [options] <source> | <directory>
Options:
-a, --all unmount all filesystems
-A, --all-targets unmount all mountpoins for the given device
in the current namespace
-c, --no-canonicalize don't canonicalize paths
-d, --detach-loop if mounted loop device, also free this loop device
--fake dry run; skip the umount(2) syscall
-f, --force force unmount (in case of an unreachable NFS system)
-i, --internal-only don't call the umount.<type> helpers
-n, --no-mtab don't write to /etc/mtab
-l, --lazy detach the filesystem now, and cleanup all later
-O, --test-opts <list> limit the set of filesystems (use with -a)
-R, --recursive recursively unmount a target with all its children
-r, --read-only In case unmounting fails, try to remount read-only
-t, --types <list> limit the set of filesystem types
-v, --verbose say what is being done
-h, --help display this help and exit
-V, --version output version information and exit
三、選項說明
-a 卸載/etc/mtab中記錄的所有文件系統
-f 強制卸載(比如在無法訪問NFS系統的情況下)
-h 顯示幫助
-n 卸載時不要將信息存入/etc/mtab文件中
-l 分離文件系統,稍后進行清除
-r 若無法成功卸載,則嘗試以只讀的方式重新掛入文件系統
-t 文件系統類型:僅卸載選項中所指定的文件系統
-v 執行時顯示詳細的信息
-V 顯示版本信息
四、命令功能
卸除目前掛在Linux目錄中的文件系統。
五、常見用法
5.1 分別通過設備名和掛載點卸載文件系統,同時輸出詳細信息
#通過設備名卸載
# umount -v /dev/vda1
/dev/vda1 umounted
#通過掛載點卸載
# umount -v /data
/data umounted
#如果設備正忙,卸載即告失敗。卸載失敗的常見原因是,某個打開的shell當前目錄為掛載點里的某個目錄
#umount -v /data
#umount: /data: device is busy
#當有別的程序正在訪問掛載的文件時,也會提示卸載失敗,通過 lsof /data 查看是哪個進程占用了/data,使用kill -9 $pid,然后再卸載
5.2 卸載前檢查占用該掛載文件的程序並迅速kill掉
#umount -l /data
說明:-l : 卸載前檢查占用該掛載文件的程序並迅速kill掉,以達到快速卸載的目的
5.3 強制卸載
umount -lf /data
本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/175