首页
/ rclone nfsmount 完全指南:通过 NFS/FUSE 把任意云存储挂载为本地文件系统

rclone nfsmount 完全指南:通过 NFS/FUSE 把任意云存储挂载为本地文件系统

2026-09-07 19:38:46作者:鲍丁臣Ursa

对应命令文档:rclone_nfsmount 命令文档,源码实现:cmd/nfsmount/nfsmount.go

rclone nfsmount 是 rclone 在 v1.65 引入的实验性(Experimental)挂载命令,其定位与 rclone mount 不同:它不再依赖本机 FUSE 内核模块直接对接 rclone 的 VFS,而是先在进程内启动一个 NFSv3 服务端(复用 rclone serve nfs),再由系统自带的 NFS 客户端将其挂载到本地目录。这使得 Linux、FreeBSD、macOS、Windows 以及 OpenBSD 都能把 Google Drive、S3、Dropbox、OneDrive 等任意 rclone 远程存储当作一个本地文件系统使用,尤其适合 macOS 安装 FUSE 困难以及 OpenBSD 根本没有 FUSE 驱动的场景。读完本文,你将掌握 nfsmount 的完整用法:前台/后台挂载、Windows 固定盘与网络盘两种模式、macOS/OpenBSD 的差异化处理、作为 systemd 与 Unix mount helper 集成,以及撑起整个挂载体验的 VFS 层缓存、分块读取、符号链接与大小写敏感性等选项体系。

nfsmount 是什么:从源码看它的工作方式

nfsmount 的核心并不是一个新的文件系统实现,而是「进程内 NFS 服务端 + 系统 NFS 客户端」的组合。在 cmd/nfsmount/nfsmount.gomount 函数(第 40 行起)中可以看到清晰的调用链:

  1. nfs.NewServer() 创建 NFSv3 服务端,并传入由 rclone 构建好的 VFS(Virtual File System)实例;
  2. 服务端在 localhost 上随机监听一个 TCP 端口(源码注释明确说明:端口是在 NFS server 启动后随机选取的,必须向服务端查询,见 nfsmount.go 第 49-55 行);
  3. 用系统命令 mountlocalhost:<port>:<mountPath> 挂到指定的 mountpoint。

命令注册逻辑在 nfsmount.go 的 init 函数中:

cmd := mountlib.NewMountCommand(name, false, mount)
cmd.Annotations["versionIntroduced"] = "v1.65"
cmd.Annotations["status"] = "Experimental"
mountlib.AddRc(name, mount)
flags.BoolVarP(cmdFlags, &sudo, "sudo", "", sudo, "Use sudo to run the mount/umount commands as root.", "")
flags.StringVarP(cmdFlags, &mountPath, "nfs-mount-path", "", mountPath, "Subpath of the remote to mount via NFS (must be an existing directory).", "")
nfs.AddFlags(cmdFlags)

这段代码同时揭示了几点重要信息:

  • --sudo 标志:用 sudo 执行系统 mount/umount,普通用户挂载 NFS 通常需要它;
  • --nfs-mount-path 标志:默认值 /,指定要挂载的远程子路径(必须是已存在的目录),源码中它被拼进挂载目标 localhost:<path>
  • 挂载与卸载使用的系统命令因平台而异,见下文各平台章节;mount 函数中 Linux/FreeBSD 走通用 mount(携带 -o port=... -o mountport=... -o tcp),而 OpenBSD 直接调用 mount_nfs 并携带 -T(强制 TCP)。

平台支持

  • Linux / FreeBSD / macOS / Windows:文档标注 "Only supported on Linux, FreeBSD, OS X and Windows at the moment.";
  • OpenBSD:没有基于 FUSE 的挂载方案,nfsmount 是那里唯一能把 rclone remote 挂成本地文件系统的方式(详见后文 OpenBSD 章节);
  • 非 Unix 平台由 cmd/nfsmount/nfsmount_unsupported.go 提供空实现占位。

值得强调的是,nfsmount 本身依然是 rclone 的挂载命令,其挂载体验与 [rclone mount](https://gitcode.com/GitHub_Trending/rc/rclone/blob/66761670daf8a8780a8b1afd8584e972f2307058/docs/content/commands/rclone_mount.md?utm_source=gitcode_repo_files) 共用同一套 VFS 层参数体系;Windows 上的 FUSE 语义则由 rclone mount 文档 同源的 mountlib 机制承接。

快速开始:前台与后台挂载

首先用 rclone config 配置好 remote,并用 rclone ls 等命令验证可用。

Linux / macOS / FreeBSD 下的挂载命令格式一致,其中 /path/to/local/mount 必须是空的、已存在的目录:

rclone nfsmount remote:path/to/files /path/to/local/mount

前台 / 后台模式:默认前台运行;加 --daemon 即进入后台(daemon)模式。Windows 只支持前台,该 flag 会被忽略。前台模式下程序退出(Ctrl+C 或收到 SIGINT/SIGTERM)会自动停止挂载;后台模式下,rclone 表现为一个通用 Unix mount 程序:主进程启动并派生子进程来建立和维护挂载,等待成功或超时后以相应退出码退出(失败时会杀掉子进程)。后台模式需要用户手动卸载:

# Linux
fusermount -u /path/to/local/mount
# ... 部分系统
fusermount3 -u /path/to/local/mount
# OS X / Linux(使用 nfsmount 时)
umount /path/to/local/mount

注意:umount 可能失败(例如 mountpoint 正忙),此时需要用户自行处理停止挂载。这也是 --sudo 与 daemon 超时参数存在的意义。

挂载后文件系统容量:与 [rclone about](https://gitcode.com/GitHub_Trending/rc/rclone/blob/66761670daf8a8780a8b1afd8584e972f2307058/docs/content/commands/rclone_about.md?utm_source=gitcode_repo_files) 命令返回的信息一致。远程为无限存储时可能只上报已用大小,此时假设额外 1 PiB 可用空间;若远程根本不支持 about 特性,则总大小与可用大小均设为 1 PiB。df 看到的容量由此而来,也可用下文 VFS 磁盘选项手工覆盖。

daemon 模式与平台差异

--daemon-wait(默认 1m0s)控制主程序等待后台挂载就绪的时间。在 Linux 上可通过 ProcFS 检查挂载状态,因此该值实为最长等待时间,可能提前返回;在 macOS / BSD 上等待时间是固定的,仅在结束时检查一次,文档建议在 macOS 上合理设置等待时间。

Windows 的挂载入门

Windows 上若从前台控制台交互挂载,rclone 会占用该控制台,需要另开窗口去访问挂载点,直到按 Ctrl-C 中断 rclone。Windows 可以这样挂载:* 表示自动分配盘符(从 Z: 开始向前回溯找第一个可用盘符)、指定盘符 X:、指定路径 C:\path\parent\mount(父目录或驱动器必须存在,mount 目录必须不存在,且此方式不支持网络盘挂载模式)、或直接指定网络共享路径 \\cloud\remote

rclone nfsmount remote:path/to/files *
rclone nfsmount remote:path/to/files X:
rclone nfsmount remote:path/to/files C:\path\parent\mount
rclone nfsmount remote:path/to/files \\cloud\remote

在 Windows 上安装与配置

要在 Windows 运行 rclone nfsmount,需要先安装 WinFsp。WinFsp 是开源的 Windows 文件系统代理(Windows File System Proxy),提供 FUSE 模拟层,rclone 通过 cgofuse 与它配合。两者都由 Bill Zissimopoulos 开发,他在 rclone 的 Windows nfsmount 实现过程中提供了很大帮助。

Windows 挂载模式:固定盘驱动器 vs 网络驱动器

Windows 与其它操作系统不同,对「网络驱动器」和「固定(本地)磁盘」使用不同的文件系统类型。Windows 假设固定磁盘快速且可靠,而网络驱动器延迟高、可靠性低;二者还可差异化配置(例如资源管理器在网络驱动器上只显示图标、不生成图片视频缩略图预览)。

默认固定盘模式:多数情况下 rclone 会把 remote 挂成普通固定盘。若在固定盘模式下遇到莫名程序错误、卡死等问题,可以改挂网络驱动器试试。固定盘模式可挂到未使用的盘符,或挂到已存在父目录/驱动器下不存在的子目录路径。特殊值 * 让 rclone 自动分配下一个可用盘符(从 Z: 开始向前)。

网络盘模式:加 --network-mode 即按网络驱动器(网络共享)挂载。此模式下不能挂到目录路径——这是 Windows 对 junction 的限制,remote 必须挂到盘符:

rclone nfsmount remote:path/to/files X: --network-mode

卷名与 UNC 路径规则--volname 自定义卷名,默认取 remote 名与路径。

  • 网络盘模式下,--volname 指定的完整 UNC 路径(如 \\cloud\remote,可选带子路径 \\cloud\remote\madeup\path)会原样使用;其它任意字符串会作为共享名拼在默认前缀 \\server\ 之后;若未指定卷名,默认用 \\server\share。挂载多个盘时卷名必须唯一,否则挂载失败。共享名会成为映射盘的卷标(资源管理器中可见),而完整 \\server\share 会像普通网络盘映射一样被 net use 等工具上报为远程 UNC 路径。
  • --volname 传完整 UNC 路径会隐式启用 --network-mode,以下两条命令等价:
rclone nfsmount remote:path/to/files X: --network-mode
rclone nfsmount remote:path/to/files X: --volname \\server\share
  • 把网络共享 UNC 路径当作 mountpoint 本身也会自动分配盘符(同 *),并把该 UNC 路径作为卷名,同样隐式启用网络模式。以下两条命令等价:
rclone nfsmount remote:path/to/files \\cloud\remote
rclone nfsmount remote:path/to/files * --volname \\cloud\remote
  • 另一种开启网络模式并设置共享路径的「原生」办法:直接把 libfuse/WinFsp 参数透传过去——--fuse-flag --VolumePrefix=\server\share。注意这里路径前缀只能有一个反斜杠。在旧版本 rclone 中这是唯一支持的方法。

Windows 文件系统权限

Windows 的 FUSE 模拟层需要把 FUSE 的 POSIX 权限模型转换为 Windows 基于访问控制列表(ACL)的权限模型。挂载出的文件系统 ACL 通常含三个条目,对应 POSIX 的 owner、group、others 三类作用域:默认 owner/group 取当前用户,others 用内建组 "Everyone" 表示;可用 FUSE 选项定制 -o UserName=user123 -o GroupName="Authenticated Users"。各条目权限由 --dir-perms--file-perms 决定,取值用传统 Unix 数字记法。

默认权限对应 --file-perms 0666 --dir-perms 0777,即对所有人可读写——这会导致无法从挂载点启动任何程序;要启动程序需加执行位,例如 --file-perms 0777 --dir-perms 0777。若程序还要写文件,很可能还要启用 VFS File Caching。默认写权限对 owner 之外的账户有限制:缺少 "write extended attributes"(详见下文)。

权限映射并不总是直观,资源管理器里的显示可能与预期不一致,例如:group/others 范围含写权限时,会映射为 "write attributes"、"write data"、"append data",但不含 "write extended attributes",Windows 会显示为基础权限 "Special" 而非 "Write"(因为 "Write" 还涵盖 write extended attributes)。而当 group/others 权限位设为 0(无权限)时,它们仍会得到 "read attributes"、"read extended attributes"、"read permissions",这是兼容性设计——让无额外权限的用户也能像 Unix 那样读取文件的基本元数据。

FileSecurity(SDDL)精细控制:WinFsp 2021(版本 1.9)起引入 FUSE 选项 FileSecurity,支持用 SDDL 完整描述安全描述符,比 POSIX 权限粒度细得多,且不会自动附加兼容性权限。实用示例:

  • 仅 owner 可访问(--file-perms 0600 --dir-perms 0700 时,user 组与 Everyone 仍会拿到上文提到的特殊权限,某些程序会误判文件人人可读——例如 SSH 客户端警告 "unprotected private key file")。用下面的参数只给 owner 完全访问(FA): -o FileSecurity="D:P(A;;FA;;;OW)"
  • 给 Everyone 设置可工作的写权限(默认写法上加 write extended attributes):-o FileSecurity="D:P(A;;FRFW;;;WD)";还需要执行则 -o FileSecurity="D:P(A;;FRFWFX;;;WD)";要完全访问(含删除)则 -o FileSecurity="D:P(A;;FA;;;WD)"

Windows 注意点(caveats)

  • 管理员创建的盘其它账户不可见:即使账户通过 UAC 提权到 Administrator 也一样。例如在「以管理员身份运行」的命令提示符里挂到某盘符,再用(非管理员的)资源管理器访问会看不到该盘。如果不需要从管理员权限的应用程序访问,最简单的方式是始终在非提权的命令提示符中挂载。
  • linked connections:Windows 有一个特殊设置,可使映射盘对创建它的用户账户在提权/非提权时都可用(即 EnableLinkedConnections 注册表项方案)。
  • 让全系统所有账户可见:以内建 SYSTEM 账户运行创建挂载的进程,途径有:Sysinternals PsExec 的 -s 选项、以 SYSTEM 运行的 Windows 计划任务或服务、WinFsp.Launcher 基础设施。注意:以其它用户身份运行 rclone 时,不会自动使用你个人资料中的配置文件,需要 --config 显式指定;此时 SYSTEM 账户拥有 owner 权限,其它账户按 group/others 范围授权,同样缺少 "write extended attributes",写文件可能被拒,可用上文 FileSecurity 解决。
  • 挂到目录路径(而非盘符)不受到上述权限/可见性限制的困扰。

在 macOS 上挂载

macOS 有三种途径:内置 NFS(serve nfs)、macFUSE(又名 osxfuse)、FUSE-T。macFUSE 是传统 FUSE 驱动,基于 macOS 内核扩展(kext);FUSE-T 则通过本机 NFSv4 服务器实现「挂载」。

Unicode 规范化

强烈建议在 macOS 上保持默认值 --no-unicode-normalization=false(所有 mount 与 serve 命令均如此),macOS 偏好 NFD 形式而多数平台用 NFC,相关细节可参见 rclone mount 文档中的 VFS Case Sensitivity

NFS 挂载方式

此方式用 [serve nfs](https://gitcode.com/GitHub_Trending/rc/rclone/blob/66761670daf8a8780a8b1afd8584e972f2307058/docs/content/commands/rclone_serve_nfs.md?utm_source=gitcode_repo_files) 命令在进程内拉起 NFS 服务器并挂载到指定 mountpoint。后台(--daemon)模式下需要用 kill 发送 SIGTERM 停止。注意 --nfs-cache-handle-limit 控制 nfsmount 缓存 handler 保存的最大文件句柄数(默认 1000000),不要设得太低,否则访问文件时可能报错;若服务端系统资源占用过高可考虑降低。

macFUSE 安装注意

从官网下载 dmg 安装包安装 macFUSE,rclone 无需干预即可定位库文件;但若用 macports 安装,需要额外步骤:

sudo mkdir /usr/local/lib
cd /usr/local/lib
sudo ln -s /opt/local/lib/libfuse.2.dylib

FUSE-T 限制与注意事项(截至 FUSE-T 1.0.14)

  • 读时更新 ModTime:按 FUSE-T 官方 wiki,文件访问时间与修改时间无法分别设置——NFS 客户端总是同时修改两者(可用 touch -mtouch -a 复现)。后果是 Finder 等工具查看文件会触发 rclone 更新修改时间,可能导致整个文件重新上传。
  • 只读挂载--read-only 时写入会静默失败,不像 macFUSE 那样给出明确警告。

在 Linux 上挂载

新版 Ubuntu 上运行 rclone mount 可能遇到:

NOTICE: mount helper error: fusermount3: mount failed: Permission denied CRITICAL: Fatal error: failed to mount FUSE fs: fusermount: exit status 1

这多半是新版 AppArmor 限制所致,可先 sudo apt install apparmor-utilssudo aa-disable /usr/bin/fusermount3 禁用。

在 OpenBSD 上挂载

OpenBSD 上 rclone nfsmount 通过拉起 [serve nfs](https://gitcode.com/GitHub_Trending/rc/rclone/blob/66761670daf8a8780a8b1afd8584e972f2307058/docs/content/commands/rclone_serve_nfs.md?utm_source=gitcode_repo_files) 服务器并用系统 mount_nfs(8) 挂载(与 macOS 的 NFS 方式同思路)。OpenBSD 没有基于 FUSE 的挂载选项,nfsmount 是唯一途径。这与源码中 OpenBSD 分支完全一致(cmd/nfsmount/nfsmount.go):OpenBSD 使用 mount_nfs 直接携带 -T,而其它平台走通用 mount 并传 -o port= -o mountport= -o tcp

portmap 注册

OpenBSD 内核 NFS 客户端通过系统 portmapper 定位 mountd,而不是连接固定端口,因此 rclone 的进程内 NFS 服务器必须先注册到 portmap 才能被挂载。做法:先让 serve nfs 监听固定端口,停掉系统 NFS 服务避免冲突,再把该端口注册给 nfsmountd 两个 RPC 程序:

rclone serve nfs --addr localhost:<PORT> remote:path

doas rcctl stop nfsd portmap
doas pkill -9 mountd   # mountd 无法用 rcctl(8) 停止
doas rcctl -f start portmap
doas rpcinfo -s nfs 3 <PORT>
doas rpcinfo -s mountd 3 <PORT>

<PORT> 换成 --addr 指定的端口。用 2049 也可以,但需要 root 运行或调整 sysctl(8)(securelevel 0),所以测试期用非特权端口更简单。

mount_nfs -T 而不是 mount

手工挂载 serve nfs 导出的共享时,直接用 mount_nfs(8)-T 强制 TCP——OpenBSD 的 mount(8) 不认识 -T,会报 unknown option -- T

mount_nfs -T localhost:/ /path/to/local/mount

rclone nfsmount 在 OpenBSD 上会自动这样做(直接调用 mount_nfs 并带 -T),所以这条只对手工挂载 serve nfs 导出时必要。

AUTH_UNIX 与既有限制

OpenBSD(及其它 BSD)内核 NFS 客户端要求服务器在 MOUNT RPC 握手中提供 AUTH_UNIX 认证类型;只提供 AUTH_NULL 的服务器会被拒,报 mount_nfs: can't access /: Authentication error。rclone 的 NFS 服务器为此通告 AUTH_UNIX,但并未在其上实现按用户的访问控制。

限制(Limitations)

  • 不使用 --vfs-cache-mode 时只能顺序写、只能读时 seek。这意味着很多应用无法直接配合 rclone 挂载使用文件,需要 --vfs-cache-mode writes--vfs-cache-mode full。macOS 用 NFS 挂载时,若不指定 --vfs-cache-mode,挂载点将是只读的(这一约束同样见于 cmd/serve/nfs/server.go:NFS 写没有缓存就无法工作)。
  • 基于 bucket 的远程(Azure Blob、Swift、S3、Google Cloud Storage、B2)无法存放空目录;其中只有 Azure Blob、Google Cloud Storage、S3 可在加 --xxx-directory_markers 后保留空目录,否则空目录会在一旦掉出目录缓存后消失。
  • Unix 下 --daemon 与等待机制细节见前文。
  • 当前仅支持 Linux、FreeBSD、OS X、Windows(OpenBSD 经 NFS 路径亦可用)。

rclone nfsmount 与 rclone sync/copy 的比较

文件系统期望 100% 可靠,而云存储远非如此。sync/copy 命令靠大量重试来应对;nfsmount 无法在不做本地副本的前提下同样地重试。要提高挂载可靠性,请使用 VFS File Caching 方案。

属性缓存(Attribute Caching)

--attr-timeout 设置内核缓存目录项属性(大小、修改时间等)的时长,默认 1s——刚好足以避免内核向 rclone 发起过多回调。理论上 0s 才对「内核控制之外可被改动的文件系统」正确,但会引发诸多问题:rclone 内存占用过高、无法向 samba 提供文件、列目录耗时过长等。

内核在 --attr-timeout 窗口内缓存文件信息。若远程文件在此期间改变长度,可能出现截断文件或尾部垃圾数据(corruption)。--attr-timeout 1s 下概率很低但非零;设得越高越可能出问题。1s 是能缓解上述问题的最低推荐值。设高(如 10s1m)时内核回调更少、更高效,但 corruption 概率更大。若远程文件不会在 rclone 控制之外改变,则不存在 corruption 风险。这与 mount.fuse 的 attr_timeout 选项一致。

过滤器(Filters)

所有 rclone 过滤器都可用来筛选挂载中可见的文件子集。相关 flag 见文末「Filter Options」一节,配置思路同 rclone ls/sync 的 include/exclude 体系。

systemd 集成

rclone nfsmount 作为 systemd 服务运行时可用 Type=notify:服务会在 mountpoint 成功建立后才进入 started 状态,依赖它的单元此时立刻能看到全部文件。

注意:systemd 运行 mount 单元时不带任何环境变量(包括 PATHHOME),因此波浪号 ~ 展开不可用,需要通过 rclone 参数显式给出 --config--cache-dir 绝对路径。由于挂载需要 fusermount/fusermount3,此场景下 rclone 会使用回退 PATH /bin:/usr/bin,请确保这两个程序存在于该 PATH。

把 rclone 用作 Unix mount helper

Unix 核心程序 /bin/mount 收到 -t FSTYPE 后会执行 /sbin/mount.FSTYPE helper,并把挂载选项作为 -o key=val,...--opt=... 传入。Automount(经典版或 systemd 版)行为类似。rclone 默认要 GNU 风格 flag(--key val),把它做成 mount helper 需建立符号链接:

ln -s /usr/bin/rclone /sbin/mount.rclone

rclone 检测到后会自动转换命令行参数。之后即可:

经典 mount 调用:

mount sftp1:subdir /mnt/data -t rclone -o vfs_cache_mode=writes,sftp_key_file=/path/to/pem

systemd mount 单元(可选配合 automount 单元):

# /etc/systemd/system/mnt-data.mount
[Unit]
Description=Mount for /mnt/data
[Mount]
Type=rclone
What=sftp1:subdir
Where=/mnt/data
Options=rw,_netdev,allow_other,args2env,vfs-cache-mode=writes,config=/etc/rclone.conf,cache-dir=/var/rclone
# /etc/systemd/system/mnt-data.automount
[Unit]
Description=AutoMount for /mnt/data
[Automount]
Where=/mnt/data
TimeoutIdleSec=600
[Install]
WantedBy=multi-user.target

/etc/fstab:

sftp1:subdir /mnt/data rclone rw,noauto,nofail,_netdev,x-systemd.automount,args2env,vfs_cache_mode=writes,config=/etc/rclone.conf,cache_dir=/var/cache/rclone 0 0

或用经典 Automountd。记得显式给出 config=...,cache-dir=... 来绕过 mount 单元没有 HOME 的问题。

mount helper 模式的选项转换规则:rclone 会把 -o 参数按逗号切分、把 _ 替换成 - 并前置 --,从而得到命令行 flag。含逗号或空格的值可用单/双引号包裹;同一引号类型内部如需再嵌套引号则写双份。另有几个特殊选项:

  • env.NAME=VALUE:为挂载进程设置环境变量。对不允许给 mount helper 设自定义环境的 Automountd 与 Systemd.mount 很有用,典型如 env.HTTPS_PROXY=proxy.host:3128env.HOME=/root
  • command=cmount:让 rclone 运行 cmount 或其它任意 rclone 命令,而非默认的 mount
  • args2env:把挂载选项经环境变量传给后台运行的 mount helper,而非命令行参数,从而对 pspgrep 隐藏密钥等敏感信息;
  • vv...:被转换为相应的 --verbose=N
  • 标准 mount 选项(x-systemd.automount_netdevnosuid 等)只面向 Automountd,会被 rclone 忽略。

VFS:虚拟文件系统层

本命令使用 VFS 层。它把 rclone 的云存储对象适配成更像磁盘文件系统的东西。云对象与磁盘文件差异巨大——不能追加、不能写中间——因此 VFS 必须做适配;由于没有唯一正确方案,于是有了下文各种选项。VFS 层还实现了目录缓存:在内存中缓存文件与目录的信息(不含数据)。

相关 flag 一览(来自命令选项表):

    --dir-cache-time duration   Time to cache directory entries for (default 5m0s)
    --poll-interval duration    Time to wait between polling for changes. Must be smaller than dir-cache-time. Only on supported remotes. Set to 0 to disable (default 1m0s)

VFS 目录缓存(Directory Cache)

--dir-cache-time 控制目录被视为最新、无需从后端刷新的时长;经 VFS 做的更改会立即生效或使缓存失效。经网页界面或另一份 rclone 在云存储侧直接做的更改,若后端不支持变化轮询,则只能在目录缓存过期后被感知;支持轮询的后端则在轮询间隔内被感知。

手动刷新:发送 SIGHUP 让 rclone 清空所有目录缓存(与新旧无关),单实例时:

kill -SIGHUP $(pidof rclone)

配置了远程控制(rc)后可整体清空:

rclone rc vfs/forget

或只清个别文件/目录:

rclone rc vfs/forget file=path/to/file dir=path/to/dir

rc 能力由 [rclone serve rc](https://gitcode.com/GitHub_Trending/rc/rclone/blob/66761670daf8a8780a8b1afd8584e972f2307058/docs/content/commands/rclone_serve_nfs.md?utm_source=gitcode_repo_files) 系同一套 rc 框架提供,接口说明见 rc 文档

VFS 文件缓冲(File Buffering)

--buffer-size 决定用于预先缓冲数据的内存大小。每个打开的文件都会尽量在内存中维持指定量的数据,缓冲绑定单个打开文件、不共享。它是每个打开文件的内存上限,只在「已下载但未读取」时占用内存;缓冲为空时只耗少量内存。rclone 的缓冲总内存最高约为 --buffer-size × 打开文件数

VFS 文件缓存(File Caching)

文件缓存让 VFS 层看起来兼容普通文件系统;禁用则损失部分兼容性。例如想要同时读写同一文件就必须启用 VFS 缓存。注意 VFS 缓存与 cache backend 是两回事,可能需要其一或两者兼用。

    --cache-dir string                     Directory rclone will use for caching.
    --vfs-cache-mode CacheMode             Cache mode off|minimal|writes|full (default off)
    --vfs-cache-max-age duration           Max time since last access of objects in the cache (default 1h0m0s)
    --vfs-cache-max-size SizeSuffix        Max total size of objects in the cache (default off)
    --vfs-cache-min-free-space SizeSuffix  Target minimum free space on the disk containing the cache (default off)
    --vfs-cache-poll-interval duration     Interval to poll the cache for stale objects (default 1m0s)
    --vfs-write-back duration              Time to writeback files after last use when using cache (default 5s)

-vv 运行时 rclone 会打印文件缓存位置。缓存文件存放在用户缓存区(依 OS 而定),可用 --cache-dir 或相应环境变量控制。

四种模式--vfs-cache-mode),模式越高兼容性越好、磁盘占用越大。文件只在关闭后且距最后访问超过 --vfs-write-back(默认 5s)时才回写远程。rclone 退出或崩溃时未上传的文件,下次以相同 flag 运行时会继续上传。

--vfs-cache-max-size / --vfs-cache-min-free-space 可能超配额:其一,配额只在每个 --vfs-cache-poll-interval(默认 1m)检查一次;其二,打开中的文件无法从缓存驱逐。超限时 rclone 优先驱逐最久未访问的文件——该策略高效且让更相关的文件更可能留在缓存。--vfs-cache-max-age 在距最后访问超过设定时间后驱逐文件(默认 1 小时),访问会把计时归零;时长用标准记法 s、m、h、d、w。

⚠️ 使用 --vfs-cache-mode > off 时,不应运行两份 rclone 使用同一 VFS 缓存及相同/重叠 remote,否则可能数据损坏。可用 --cache-dir 给每份 rclone 独立的缓存层级;若使用的 remote 不重叠则无需担心。

--vfs-cache-mode off(默认)

直接从远程读、直接写远程,磁盘零缓存。部分操作不可用:文件不能同时打开读与写;写打开的文件不能 seek;写打开已存在文件必须 O_TRUNC;O_APPEND/O_TRUNC 被忽略;上传失败无法重试。

--vfs-cache-mode minimal

与 off 类似,但读写同时打开的文件会缓冲到磁盘,写兼容性大幅提升且磁盘占用最小。仍不可用:只写打开的文件不能 seek;已存在文件写打开必须 O_TRUNC;只写文件忽略 O_APPEND/O_TRUNC;上传失败无法重试。

--vfs-cache-mode writes

只读文件仍直接从远程读;只写与读写文件先缓冲到磁盘。此模式支持所有常规文件系统操作;上传失败会以指数退避重试,最长间隔 1 分钟。

--vfs-cache-mode full

所有读写都经磁盘缓冲,从远程读的数据也先落盘。缓存文件是稀疏文件,rclone 跟踪已下载的位段——应用只读文件开头就只缓冲开头;文件在缓存中显示全尺寸但实际只含已下载部分。除此外与 writes 模式相同。读取时 rclone 会预读 --buffer-size--vfs-read-ahead 字节,前者走内存、后者落盘;建议此时 --buffer-size 别太大、需要时把 --vfs-read-ahead 设大。

⚠️ 并非所有文件系统都支持稀疏文件,尤其 FAT/exFAT 不支持。缓存目录在不支持稀疏文件的文件系统上会导致 rclone 性能极差,检测到时会记录 ERROR。

指纹(Fingerprinting)

VFS 用指纹判断本地缓存副本相对远程是否变化。指纹由 size、modification time、hash 组成(对象可用时)。某些后端的部分属性读取很慢(每个对象多一次 API 调用或额外工作):例如 localsftp 后端的 hash 慢(需读全文件再哈希),s3swiftftpqingstor 后端的 modtime 慢(需额外 API 调用)。--vfs-fast-fingerprint 让 rclone 在指纹中排除这些慢操作——准确度降低但快得多,能改善缓存文件打开耗时。在 locals3swift 后端上跑 VFS 缓存时推荐启用。注意:改动该 flag 后缓存中文件的指纹可能失效,需要重新下载。

VFS 分块读取(Chunked Reading)

rclone 从远程读文件时分块进行:只请求实际读到的分块,可降低部分远程的下载配额消耗,代价是请求数增加。

    --vfs-read-chunk-size SizeSuffix        Read the source objects in chunks (default 128M)
    --vfs-read-chunk-size-limit SizeSuffix  Max chunk doubling size (default off)
    --vfs-read-chunk-streams int            The number of parallel streams to read at once

--vfs-read-chunk-streams == 0(默认)

先读 --vfs-read-chunk-size 大小的块,之后每读一次尺寸翻倍;--vfs-read-chunk-size-limit 大于初始块尺寸时,翻倍只到该上限为止;默认 "off" 表示不限、持续增长。例如 --vfs-read-chunk-size 100M + 不限:依次下载 0-100M、100M-200M、200M-300M……;设 --vfs-read-chunk-size-limit 500M 则变为 0-100M、100M-300M、300M-700M、700M-1200M……。--vfs-read-chunk-size 设 0 或 "off" 即禁用分块读取。块不进内存缓冲。

--vfs-read-chunk-streams > 0

rclone 并发读取 --vfs-read-chunk-streams--vfs-read-chunk-size 大小的块,每块尺寸恒定。这对高延迟链路或到高性能对象存储的超高带宽链路提升巨大。最佳取值依赖后端与延迟,需实验:高性能对象存储(如 AWS S3)可从 --vfs-read-chunk-streams 16 + --vfs-read-chunk-size 4M 起步;高延迟链路可能需更多流数才能获得足够吞吐。

VFS 性能相关选项

    --no-checksum     Don't compare checksums on up/download.
    --no-modtime      Don't read/write the modification time (can speed things up).
    --no-seek         Don't allow seeking in files.
    --read-only       Only allow read-only access.

S3 与 Swift 特别受益于 --no-modtime(或 --use-server-modtime,效果略有不同)——读取一次修改时间就是一次事务。当 rclone 收到乱序的读/写时,与其 seek,不如等一会儿让顺序读/写到来;以下 flag 仅在未使用磁盘缓存文件时生效:

    --vfs-read-wait duration   Time to wait for in-sequence read before seeking (default 20ms)
    --vfs-write-wait duration  Time to wait for in-sequence write before giving error (default 1s)

使用 VFS 写缓存(writes/full)时,全局 --transfers 可调整缓存中已修改文件的上传并发数(相关全局 flag --checkers 对 VFS 无效):

    --transfers int  Number of file transfers to run in parallel (default 4)

符号链接(Symlinks)

默认 VFS 不支持符号链接,可用下面任一 flag 开启:

    --links      Translate symlinks to/from regular files with a '.rclonelink' extension.
    --vfs-links  Translate symlinks to/from regular files with a '.rclonelink' extension for the VFS

多数云存储不直接支持符号链接,rclone 因而把符号链接存成特殊扩展名的普通文件:看起来是符号链接的 link-to-file.txt,在云上实际存为 link-to-file.txt.rclonelink,内容是链接目标路径。--links 在 rclone 全局开启符号链接转换(包括 local 等支持该概念的后端);--vfs-links 只在 VFS 层开启。该方案与 local 后端 --local-links 兼容。--vfs-links 专为 rclone mountrclone nfsmountrclone serve nfs 设计,尚未与其它 serve 命令一起测试。

当前实现限制:期望调用方自行解析子符号链接。例如目录树中 linked-dir -> dir,VFS 能正确解析 linked-dir,但不能解析 linked-dir/file.txt。另有已知问题(issue #8245):把符号链接移入存在同名文件的目录时可能产生重复文件。

VFS 大小写敏感性(Case Sensitivity)

Linux 文件系统区分大小写;现代 Windows 文件系统不区分但保留大小写(不允许同目录存在仅大小写不同的两个文件);macOS 默认不区分大小写。

--vfs-case-insensitive 控制处理方式:为 "false" 时原名直传远程;为 "true"(或命令行裸出现)时执行下述 "fixup"。用户以与远程存储不同的大小写请求打开/删除/重命名文件时:若存在精确同名文件,用磁盘上现有文件的大小写;若精确同名不存在但存在仅大小写不同的名字,rclone 会透明地修正。fixup 只在请求已存在文件时发生;新建文件的大小写敏感性由底层 remote 决定。该 flag 未提供时默认值依运行 OS:Windows/macOS 为 "true",其它为 "false";提供了但不带值则为 "true"。

--no-unicode-normalization 对「规范等价」但不同的文件名执行类似 fixup。Unicode 规范化对 macOS 用户尤其有用(其偏好 NFD 而非多数平台用的 NFC),因此 macOS 上强烈建议保持默认 false

万一某目录在大小写与 Unicode 规范化后出现多个重复文件名,--vfs-block-norm-dupes 可隐藏重复项——代价是列目录时需全目录扫描查重,故无必要应保持关闭。macOS 用户可考虑开启:否则当远程目录同时含 NFC 与 NFD 版本同名文件时,挂载里两个版本都可见、都"可编辑",但实际编辑的始终只有 NFD 版本;该 flag 能检测此场景、隐藏重复并记录错误(与 rclone sync 的处理一致)。

VFS 磁盘选项(Disk Options)

    --vfs-disk-space-total-size    Manually set the total disk space size (example: 256G, default: -1)

当自动读取的容量统计不正确时,可手工设置文件系统容量。

已用字节的替代报告方式(Used Bytes)

部分后端(最典型 S3)不上报已用字节数。若需要 df 时该信息可用,加 --vfs-used-is-size:rclone 不再依赖后端上报,而是类似 rclone size 扫描整个远程自己计算总量。

⚠️ WARNING:与 rclone size 不同,该 flag 忽略过滤器以保证结果准确,代价是极低效、大量 API 调用可能产生额外费用。仅作最后手段使用,且配合缓存。

VFS Metadata 暴露

--vfs-metadata-extension 让 VFS 暴露包含 metadata 的 JSON 文件。这些文件不出现在目录列表里,但可以被 stat 和打开;一旦被打开过,它们就出现在目录列表中,直到目录缓存过期。注意部分后端不传 --metadata flag 不会生成 metadata。示例(--metadata --vfs-metadata-extension .metadata):

$ ls -l /mnt/
total 1048577
-rw-rw-r-- 1 user user 1073741824 Mar  3 16:03 1G

$ cat /mnt/1G.metadata
{
        "atime": "2025-03-04T17:34:22.317069787Z",
        "btime": "2025-03-03T16:03:37.708253808Z",
        "gid": "1000",
        "mode": "100664",
        "mtime": "2025-03-03T16:03:39.640238323Z",
        "uid": "1000"
}

$ ls -l /mnt/
total 1048578
-rw-rw-r-- 1 user user 1073741824 Mar  3 16:03 1G
-rw-rw-r-- 1 user user        185 Mar  3 16:03 1G.metadata

文件无 metadata 时返回 {};读取 metadata 出错时返回 {"error":"error string"}

命令用法与完整选项表

rclone nfsmount remote:path /path/to/mountpoint [flags]

NFS / 挂载 / 平台相关选项

      --addr string                            IPaddress:Port or :Port to bind server to
      --allow-idmap                            Allow id-mapped mounts (Linux 6.12+, mount2 only)
      --allow-non-empty                        Allow mounting over a non-empty directory (not supported on Windows)
      --allow-other                            Allow access to other users (not supported on Windows)
      --allow-root                             Allow access to root user (not supported on Windows)
      --async-read                             Use asynchronous reads (not supported on Windows) (default true)
      --attr-timeout Duration                  Time for which file/directory attributes are cached (default 1s)
      --daemon                                 Run mount in background and exit parent process (as background output is suppressed, use --log-file with --log-format=pid,... to monitor) (not supported on Windows)
      --daemon-timeout Duration                Time limit for rclone to respond to kernel (not supported on Windows) (default 0s)
      --daemon-wait Duration                   Time to wait for ready mount from daemon (maximum time on Linux, constant sleep time on OSX/BSD) (not supported on Windows) (default 1m0s)
      --debug-fuse                             Debug the FUSE internals - needs -v
      --default-permissions                    Makes kernel enforce access control based on the file mode (not supported on Windows)
      --devname string                         Set the device name - default is remote:path
      --dir-cache-time Duration                Time to cache directory entries for (default 5m0s)
      --dir-perms FileMode                     Directory permissions (default 777)
      --direct-io                              Use Direct IO, disables caching of data
      --file-perms FileMode                    File permissions (default 666)
      --fuse-flag stringArray                  Flags or arguments to be passed direct to libfuse/WinFsp (repeat if required)
      --gid uint32                             Override the gid field set by the filesystem (not supported on Windows) (default 1000)
  -h, --help                                   help for nfsmount
      --link-perms FileMode                    Link permissions (default 666)
      --max-read-ahead SizeSuffix              The number of bytes that can be prefetched for sequential reads (not supported on Windows) (default 128Ki)
      --mount-case-insensitive Tristate        Tell the OS the mount is case insensitive (true) or sensitive (false) regardless of the backend (auto) (default unset)
      --network-mode                           Mount as remote network drive, instead of fixed disk drive (supported on Windows only)
      --nfs-cache-dir string                   The directory the NFS handle cache will use if set
      --nfs-cache-handle-limit int             max file handles cached simultaneously (min 5) (default 1000000)
      --nfs-cache-type memory|disk|symlink     Type of NFS handle cache to use (default memory)
      --nfs-mount-path string                  Subpath of the remote to mount via NFS (must be an existing directory). (default "/")
      --no-checksum                            Don't compare checksums on up/download
      --no-modtime                             Don't read/write the modification time (can speed things up)
      --no-seek                                Don't allow seeking in files
      --noappledouble                          Ignore Apple Double (._) and .DS_Store files (supported on OSX only) (default true)
      --noapplexattr                           Ignore all "com.apple.*" extended attributes (supported on OSX only)
  -o, --option stringArray                     Option for libfuse/WinFsp (repeat if required)
      --poll-interval Duration                 Time to wait between polling for changes, must be smaller than dir-cache-time and only on supported remotes (set 0 to disable) (default 1m0s)
      --read-only                              Only allow read-only access
      --sudo                                   Use sudo to run the mount/umount commands as root.
      --uid uint32                             Override the uid field set by the filesystem (not supported on Windows) (default 1000)
      --umask FileMode                         Override the permission bits set by the filesystem (not supported on Windows) (default 002)
      --volname string                         Set the volume name (supported on Windows and OSX only)
      --write-back-cache                       Makes kernel buffer writes before sending them to rclone (without this, writethrough caching is used) (not supported on Windows)

VFS 相关选项

      --vfs-block-norm-dupes                   If duplicate filenames exist in the same directory (after normalization), log an error and hide the duplicates (may have a performance cost)
      --vfs-cache-max-age Duration             Max time since last access of objects in the cache (default 1h0m0s)
      --vfs-cache-max-size SizeSuffix          Max total size of objects in the cache (default off)
      --vfs-cache-min-free-space SizeSuffix    Target minimum free space on the disk containing the cache (default off)
      --vfs-cache-mode CacheMode               Cache mode off|minimal|writes|full (default off)
      --vfs-cache-poll-interval Duration       Interval to poll the cache for stale objects (default 1m0s)
      --vfs-case-insensitive                   If a file name not found, find a case insensitive match
      --vfs-disk-space-total-size SizeSuffix   Specify the total space of disk (default off)
      --vfs-fast-fingerprint                   Use fast (less accurate) fingerprints for change detection
      --vfs-handle-caching Duration            Time to keep file handle and downloaders alive after last close (default 5s)
      --vfs-links                              Translate symlinks to/from regular files with a '.rclonelink' extension for the VFS
      --vfs-metadata-extension string          Set the extension to read metadata from
      --vfs-read-ahead SizeSuffix              Extra read ahead over --buffer-size when using cache-mode full
      --vfs-read-chunk-size SizeSuffix         Read the source objects in chunks (default 128Mi)
      --vfs-read-chunk-size-limit SizeSuffix   If greater than --vfs-read-chunk-size, double the chunk size after each chunk read, until the limit is reached ('off' is unlimited) (default off)
      --vfs-read-chunk-streams int             The number of parallel streams to read at once
      --vfs-read-wait Duration                 Time to wait for in-sequence read before seeking (default 20ms)
      --vfs-refresh                            Refreshes the directory cache recursively in the background on start
      --vfs-used-is-size rclone size           Use the rclone size algorithm for Used size
      --vfs-write-back Duration                Time to writeback files after last use when using cache (default 5s)
      --vfs-write-wait Duration                Time to wait for in-sequence write before giving error (default 1s)

Filter 选项(过滤挂载中可见文件)

      --delete-excluded                     Delete files on dest excluded from sync
      --exclude stringArray                 Exclude files matching pattern
      --exclude-from stringArray            Read file exclude patterns from file (use - to read from stdin)
      --exclude-if-present stringArray      Exclude directories if filename is present
      --files-from stringArray              Read list of source-file names from file (use - to read from stdin)
      --files-from-raw stringArray          Read list of source-file names from file without any processing of lines (use - to read from stdin)
      --files-from0 stringArray             Read list of source-file names from file using NUL as separator (use - to read from stdin)
  -f, --filter stringArray                  Add a file filtering rule
      --filter-from stringArray             Read file filtering patterns from a file (use - to read from stdin)
      --hash-filter string                  Partition filenames by hash k/n or randomly @/n
      --ignore-case                         Ignore case in filters (case insensitive)
      --include stringArray                 Include files matching pattern
      --include-from stringArray            Read file include patterns from file (use - to read from stdin)
      --max-age Duration                    Only transfer files younger than this in s or suffix ms|s|m|h|d|w|M|y (default off)
      --max-depth int                       If set limits the recursion depth to this (default -1)
      --max-size SizeSuffix                 Only transfer files smaller than this in KiB or suffix B|K|M|G|T|P (default off)
      --metadata-exclude stringArray        Exclude metadatas matching pattern
      --metadata-exclude-from stringArray   Read metadata exclude patterns from file (use - to read from stdin)
      --metadata-filter stringArray         Add a metadata filtering rule
      --metadata-filter-from stringArray    Read metadata filtering patterns from a file (use - to read from stdin)
      --metadata-include stringArray        Include metadatas matching pattern
      --metadata-include-from stringArray   Read metadata include patterns from file (use - to read from stdin)
      --min-age Duration                    Only transfer files older than this in s or suffix ms|s|m|h|d|w|M|y (default off)
      --min-size SizeSuffix                 Only transfer files bigger than this in KiB or suffix B|K|M|G|T|P (default off)

源码级证据:NFS 句柄缓存与 OpenBSD/子路径专项测试

围绕 nfsmount 的核心,仓库中可交叉验证的源码与测试包括:

  • 随机端口与回环绑定cmd/serve/nfs/server.goListenAddr 为空时默认绑定 localhost:(无认证的 NFS 服务,只暴露给本机);nfsmount.go 在服务启动后通过 s.Addr() 反查随机端口用于拼装挂载参数。
  • NFS 服务端选项cmd/serve/nfs/nfs.go 定义 addrnfs_cache_handle_limitnfs_cache_typenfs_cache_dir 四个选项,handle 缓存类型枚举为 memory/disk/symlink(第 51-67 行),其完整语义(disk 用路径哈希落盘、symlink 缓存仅限 Linux 且需 root/CAP_DAC_READ_SEARCH 等)见同文件的服务端帮助文本。
  • OpenBSD 差异化挂载cmd/nfsmount/nfsmount.go 依据 runtime.GOOS == "openbsd" 选择 mount_nfs + -T 参数,否则走通用 mount 并携带 port/mountport/tcp 三项 -ocmd/nfsmount/nfsmount.go 的卸载回调在 darwin 上使用 diskutil umount force,其余平台用 umount -f
  • 端到端测试cmd/nfsmount/nfsmount_test.goTestMount 会遍历 memory/disk/symlink 三种缓存类型跑完整的 vfstest 套件;TestSubpathMount(第 65-113 行)验证 --nfs-mount-path /sub 下远程子目录中的文件可通过挂载点根目录读到,证明子路径导出在真实挂载链路中可用。

小结

rclone nfsmount 本质上是一个「自托管 NFSv3 服务端 + 系统挂载工具」的封装命令:它复用 serve nfs 的进程内服务器(无鉴权、默认回环 + 随机端口),把 rclone 的 VFS 以网络文件系统协议暴露给本机或局域网,再用系统 NFS 客户端挂载,从而绕开对 FUSE 内核模块的依赖。因此它天然适合:macOS 不想装 FUSE、OpenBSD 没有 FUSE、以及需要把任意 rclone 后端挂成本地目录统一访问的场景。真正决定挂载可用性的是 VFS 层——从目录缓存、--vfs-cache-mode 写缓存、分块读取到大小写/Unicode fixup、符号链接与 metadata 暴露——而这些选项与 rclone mount 一脉相承。使用前请牢记两条基本经验:写操作几乎总是需要 --vfs-cache-mode writes/full;Windows 下遇到程序异常可改用 --network-mode,多用户场景则需处理 ACL/FileSecurity 与账户可见性问题。

登录后查看全文
热门项目推荐
相关项目推荐

项目优选

收起
kernelkernel
deepin linux kernel
C
33
18
ops-transformerops-transformer
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
1.13 K
2.75 K
pytorchpytorch
作为 Ascend for PyTorch 社区的核心组件,TorchNPU 是昇腾专为 PyTorch 打造的深度学习适配插件,使 PyTorch 框架能够直接调用昇腾 NPU,为开发者提供昇腾 AI 处理器的超强算力。
Python
857
1.35 K
docsdocs
暂无描述
Markdown
897
5.8 K
kernelkernel
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
529
593
ops-nnops-nn
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
915
1.83 K
jiuwenswarmjiuwenswarm
JiuwenSwarm 是一款基于openJiuwen开发的智能AI Agent,它能够将大语言模型的强大能力,通过你日常使用的各类通讯应用,直接延伸至你的指尖。
Python
3.58 K
1.01 K
ops-mathops-math
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
1.35 K
1.46 K
cann-learning-hubcann-learning-hub
CANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。
Jupyter Notebook
1.01 K
515
AscendNPU-IRAscendNPU-IR
AscendNPU-IR是基于MLIR(Multi-Level Intermediate Representation)构建的,面向昇腾亲和算子编译时使用的中间表示,提供昇腾完备表达能力,通过编译优化提升昇腾AI处理器计算效率,支持通过生态框架使能昇腾AI处理器与深度调优
C++
547
388