1. 技术背景
挂载
挂载是将一个存储设备(或文件)连接到 Linux 系统根目录下的某个空文件夹,使之成为系统可访问的一部分的过程。想象一棵倒挂的大树,根目录 / 是树根,所有其他目录都是树枝。挂载就是把一个独立的存储设备(如 U 盘、硬盘分区、Windows 共享文件夹)作为一个新的"树枝",无缝地接在这棵树的某个节点上。
其他的可man mount查看文档。
CIFS
CIFS 是 Common Internet File System 的缩写,中文意为通用互联网文件系统。简单来说,你可以把它理解为一种语言或协议。它主要解决了"让不同操作系统(如 Linux 和 Windows)之间能够像访问本地文件一样,通过网络互相读写文件"的问题。
Windows 系统之间分享文件,默认使用的协议叫 SMB(Server Message Block,服务器消息块协议)。CIFS 是 SMB 协议的一个早期版本(具体来说是 SMB 1.0 的一个特定实现)。虽然现代 Windows 主要使用更新的 SMB 2.0、3.0 等版本,但大家仍习惯用 SMB/CIFS 来统称这套文件共享协议。
为了让 Linux 能听懂 Windows 的"语言",就需要一个"翻译官"或"驱动程序"。这个角色正是由 cifs-utils 工具包和 Linux 内核中的 CIFS 模块来扮演的。当你运行 mount -t cifs ... 命令时,就告诉Linuxe用CIFS协议去通信。 如果没有 CIFS 协议支持,Linux 会尝试用 NFS(Network File System, Linux 原生的网络文件系统)去连接 Windows,但 Windows 默认不支持 NFS,所以就会失败。
2.实践操作
-
- 操作过程记录(临时挂载,重启就会失效)
将//192.168.0.22用cifs的协议挂载到/home/username/win_share_43目录下:
bashsudo mount -tcifs //192.168.0.43 /home/username/win_share_43提示错误:
bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program.
安装下cifs-utils工具包
bashsudo apt install cifs-utils安装完成后,继续运行

需要输入密码,但用的是root账户,说明没指定用户名时,用的是root账户。
接着带上用户名(格式可参看文档 man 8 mount.cifs),如下:
bashsudo mount -tcifs //192.168.0.43 /home/username/win_share_43 -o username=Administrator执行后,提示无效参数
man mount.cifs查看原因:是共享地址语法出错,应该要这样://server/sharebashMOUNT.CIFS(8) MOUNT.CIFS(8) NAME mount.cifs - mount using the Common Internet File System (CIFS) SYNOPSIS mount.cifs {service} {mount-point} [-o options] This tool is part of the cifs-utils suite. mount.cifs mounts a Linux CIFS filesystem. It is usually invoked indirectly by the mount(8) command when using the "-t cifs" option. This command only works in Linux, and the kernel must support the cifs filesystem. The CIFS protocol is the successor to the SMB protocol and is supported by most Windows servers and many other commercial servers and Network Attached Storage appliances as well as by the popular Open Source server Samba. The mount.cifs utility attaches the UNC name (exported network resource) specified as service (using //server/share syntax, where "server" is the server name or IP address and "share" is the name of the share) to the local directory mount-point. Options to mount.cifs are specified as a comma-separated list of key=value pairs. It is possible to send options other than those listed here, assuming that the cifs filesystem kernel module (cifs.ko) supports them. Unrecognized cifs mount options passed to the cifs vfs kernel code will be logged to the kernel log. mount.cifs causes the cifs vfs to launch a thread named cifsd. After mounting it keeps running until the mounted resource is unmounted (usually via the umount utility). mount.cifs -V command displays the version of cifs mount helper. modinfo cifs command displays the version of cifs module.修正错误后,重新运行,挂载成功!
bashsudo mount -tcifs //192.168.0.43/project /home/username/win_share_43 -o username=Administrator -
- 总结(临时挂载,重启就会失效)
确保安转改了cifs-utils包,Debian系的可以通过命令 dpkg -l cifs 查看

执行挂载命令,按cifs的协议,命令如下:
bashsudo mount -tcifs //192.168.0.43/project /home/username/win_share_43 -o username=Administrator -
- 卸载
umount 命令,参看man umount
-
- 永久挂载
在/etc/fstab文件中加挂载记录
fstab表示file system table。具体参看man fstab