mount

命令说明:

mount是Linux下的一个命令,它可以将分区挂接到Linux的一个文件夹下,从而将分区和该目录联系起来,因此我们只要访问这个文件夹,就相当于访问该分区了。

Linux mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件。

命令语法:

mount [-hV]
    mount -a [-fFnrsvw] [-t vfstype]
    mount [-fnrsvw] [-o options [,...]] device | dir
    mount [-fnrsvw] [-t vfstype] [-o options] device dir

命令参数:

mount
    -V:显示程序版本
    -h:显示辅助讯息
    -v:显示较讯息,通常和 -f 用来除错。
    -a:将 /etc/fstab 中定义的所有档案系统挂上。
    -F:这个命令通常和 -a 一起使用,它会为每一个 mount 的动作产生一个行程负责执行。在系统需要挂上大量 NFS 档案系统时可以加快挂上的动作。
    -f:通常用在除错的用途。它会使 mount 并不执行实际挂上的动作,而是模拟整个挂上的过程。通常会和 -v 一起使用。
    -n:一般而言,mount 在挂上后会在 /etc/mtab 中写入一笔资料。但在系统中没有可写入档案系统存在的情况下可以用这个选项取消这个动作。
    -s-r:等于 -o ro
    -w:等于 -o rw
    -L:将含有特定标签的硬盘分割挂上。
    -U:将档案分割序号为 的档案系统挂下。-L 和 -U 必须在/proc/partition 这种档案存在时才有意义。
    -t:指定档案系统的型态,通常不必指定。mount 会自动选择正确的型态。
    -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 模式用来将一个档案当成硬盘分割挂上系统。

参数详解:

  1.-t vfstype 指定文件系统的类型,通常不必指定。mount 会自动选择正确的类型。常用类型有: 
  光盘或光盘镜像:iso9660 
  DOS fat16文件系统:msdos 
  Windows 9x fat32文件系统:vfat 
  Windows NT ntfs文件系统:ntfs 
  Mount Windows文件网络共享:smbfs 
  UNIX(LINUX) 文件网络共享:nfs 

  2.-o options 主要用来描述设备或档案的挂接方式。常用的参数有: 
  loop:用来把一个文件当成硬盘分区挂接上系统 
  ro:采用只读方式挂接设备 
  rw:采用读写方式挂接设备 
  iocharset:指定访问文件系统所用字符集 
  3.device 要挂接(mount)的设备。 
  4.dir设备在系统上的挂接点(mount point)。

使用实例:

挂载U盘:
mount -t vfat /dev/sdb1 /media/usb
注:/media/usb是自己创建的目录

挂载ntfs格式的移动硬盘:
mount -t ntfs /dev/sdb1 /media

挂载光驱:mount /dev/cdrom /media

挂载ios镜像:mount /path/to/iso /media

umount

譬如 /dev/hda5 已经挂载在/mnt/hda5上,用一下三条命令均可卸载挂载的文件系统

umount /dev/hda5
umount /mnt/hda5
umount /dev/hda5 /mnt/hda5

Linux挂载Windows共享文件系统:

yum install -y cifs-utils
apt-get install -y cifs-utils

# 多种写法
mount.cifs //192.168.237.128/123 r123
mount.cifs -o username=tom,password=Passw0rd! //192.168.237.128/123 r123
mount.cifs 192.168.237.128:123 r123
mount -t cifs 192.168.237.128:123 r123

mkdir -p /data
mount.cifs -o username=fjcqy,password=1 //192.168.237.1/Users/fjcqy/Desktop /data
mount.cifs -o username=fjcqy,password=1 //192.168.237.1/c$ /data

[root@RHEL ~]# mount
//192.168.237.128/123 on /root/r123 type cifs (rw)
192.168.237.128:123 on /root/r123 type cifs (rw)

[root@RHEL ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda1             20G  1.2G   18G   7% /
tmpfs                935M     0  935M   0% /dev/shm
/dev/sr0             3.6G  3.6G     0 100% /media
//192.168.237.128/123  200G   12G  189G   6% /root/r123
192.168.237.128:123  200G   12G  189G   6% /root/r123

SMB 挂载详细说明:

#空密码:
mount.cifs //192.168.237.1/share_e /data/ -o user=,pass=
mount -t cifs //192.168.237.1/share_e /data/ -o user=,pass=

#有密码:
mount.cifs //192.168.237.135/Shortcuts /data -o user=yoyo,pass=1
mount -t cifs //192.168.237.135/Shortcuts /data -o user=yoyo,pass=1

#权限控制
mount.cifs //192.168.237.1/share_e /data/ -o user=,pass=,dir_mode=0755,file_mode=0644

#挂载Windows默认共享,报错【mount error(121): Remote I/O error】,需要指定版本号vers=2.1
mount.cifs //192.168.237.1/e$ /data/ -o user=fjcqy,pass=1,vers=2.1

#CentOS8挂载CentOS6共享,报错【mount error(2): No such file or directory
#Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)】,需要指定版本号vers=1.0
mount.cifs //192.168.100.96/logbak /logbak -o user=logbak,pass=logbak,vers=1.0

SMB版本号说明

vers=arg
       SMB protocol version. Allowed values are:

       · 1.0 - The classic CIFS/SMBv1 protocol.

       · 2.0 - The SMBv2.002 protocol. This was initially introduced in Windows Vista Service Pack 1, and Windows Server 2008. Note  that  the  initial  release
         version of Windows Vista spoke a slightly different dialect (2.000) that is not supported.

       · 2.1 - The SMBv2.1 protocol that was introduced in Microsoft Windows 7 and Windows Server 2008R2.

       · 3.0 - The SMBv3.0 protocol that was introduced in Microsoft Windows 8 and Windows Server 2012.

       · 3.02 or 3.0.2 - The SMBv3.0.2 protocol that was introduced in Microsoft Windows 8.1 and Windows Server 2012R2.

       · 3.1.1 or 3.11 - The SMBv3.1.1 protocol that was introduced in Microsoft Windows 10 and Windows Server 2016.

       · 3 - The SMBv3.0 protocol version and above.

       · default - Tries to negotiate the highest SMB2+ version supported by both the client and server.

       If no dialect is specified on mount vers=default is used.  To check Dialect refer to /proc/fs/cifs/DebugData

       Note too that while this option governs the protocol version used, not all features of each version are available.

       The default since v4.13.5 is for the client and server to negotiate the highest possible version greater than or equal to 2.1. In kernels prior to v4.13,
       the default was 1.0. For kernels between v4.13 and v4.13.5 the default is 3.0.

umount: /home: device is busy.
原因是因为有程序在使用/home目录,我们可以使用fuser查看那些程序的进程,然后kill掉就可以了。

[root@localhost home]# fuser -m /home
/home: 10278c 10279c 10280c 10281c 10282c 10295 10365 18222c
命令:kill -9 pid