> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-26-zhang-qi-ta-wen-jian-xi-tong/di-26.1-jie-windows-wen-jian-xi-tong.md).

# 26.1 Windows 文件系统

FreeBSD 当前读写 NTFS 需借助用户态驱动 ntfs-3g，读写 exFAT 需借助用户态驱动 fusefs-exfat；FAT32 则由内核原生支持读写。

| 文件系统  | 支持方式   | 驱动/软件包        |
| ----- | ------ | ------------- |
| NTFS  | 用户态驱动  | fusefs-ntfs   |
| exFAT | 用户态驱动  | fusefs-exfat  |
| FAT32 | 内核原生支持 | msdosfs（内核模块） |

## NTFS 文件系统

NTFS 是微软开发的文件系统，常用于 Windows 操作系统。FreeBSD 通过 **fusefs-ntfs** 软件包（对应 Port **filesystems/ntfs**）提供对 NTFS 的完整读写支持，便于访问和修改 NTFS 格式的存储设备。

### 安装 ntfs-3g

使用 pkg 安装：

```sh
# pkg install fusefs-ntfs
```

还可以通过 Ports 系统构建：

```sh
# cd /usr/ports/filesystems/ntfs
# make BATCH=yes install clean
```

### 配置 ntfs-3g

将 NTFS 格式的设备，如 U 盘插入计算机。此时可看到其设备名称，例如 `da0`（对应设备文件为 **/dev/da0p1**）。

编辑 **/etc/rc.conf** 配置文件，将 fusefs 内核模块添加至系统启动加载列表：

```sh
# sysrc kld_list+="fusefs"
```

上述命令使配置永久生效，若要立即生效，执行：

```sh
# kldload fusefs
```

### 手动挂载

手动挂载 NTFS 分区的方式如下：

使用 ntfs-3g 将 **/dev/da0p1** 挂载至 **/mnt**，设置读写权限，并为文件指定适合的属主和权限掩码：

```sh
# ntfs-3g /dev/da0p1 /mnt -o rw,uid=1000,gid=1000,umask=0
```

进行若干读写操作：

```sh
# ls /mnt
System Volume Information		di-17.2-jie-linux-wen-jian-xi-tong.md
di-17.1-jie-windows-wen-jian-xi-tong.md	di-17.3-jie-macos-wen-jian-xi-tong.md
# rm /mnt/di-17.3-jie-macos-wen-jian-xi-tong.md
# touch /mnt/test1
```

### 自动挂载

可配置开机自动挂载 NTFS 分区。

编辑 **/etc/fstab** 文件，加入以下挂载信息：

```sh
/dev/da0p1      /mnt          	ntfs	mountprog=/usr/local/bin/ntfs-3g,rw,uid=1000,gid=1000,umask=0,late	0	0
```

验证挂载状态：

```sh
# df -h
/dev/da0p1             58G     88M     58G     0%    /mnt
```

再查看文件内容：

```sh
# ls /mnt/
System Volume Information		di-17.2-jie-linux-wen-jian-xi-tong.md
di-17.1-jie-windows-wen-jian-xi-tong.md	test1
```

### 附录：将新设备格式化为 NTFS

首先需要创建分区表：可为设备设置 MBR 或 GPT 分区表。

MBR 分区表较为陈旧，因此后续使用 GPT 方案演示。

#### 创建 MBR 分区表

```sh
# gpart create -s mbr da0
# gpart add -t ntfs da0
```

#### 创建 GPT 分区表

```sh
# gpart create -s gpt da0
# gpart add -t ms-basic-data da0
```

### 格式化 NTFS 分区

> **警告**
>
> `mkntfs` 将对指定分区执行格式化，分区上所有数据将永久丢失。请确认设备路径正确无误。

在 **/dev/da0p1** 分区上创建 NTFS 文件系统：

```sh
# NTFS_USE_UBLIO=0 mkntfs -vf /dev/da0p1
```

参数说明：

* `-f`：表示快速格式化
* `-v`：表示显示详细输出信息
* `NTFS_USE_UBLIO=0`：UBLIO（User space Block I/O）是一个用户空间块 I/O 库，用于提升 FUSE 文件系统的性能。但在 FreeBSD 环境下，UBLIO 与 ntfs-3g 协同工作时可能引发文件系统损坏及数据丢失风险。本例中，若不使用该参数禁用 UBLIO，命令将无响应。

#### 参考文献

* [Bug 206978](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=206978)
* [Bug 194526](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194526)。

## FAT32 文件系统

FAT 文件系统简单可靠。尽管在性能、可靠性和可扩展性方面不如现代方案，但由于在多种操作系统上均可用，仍是设备间数据交换的常见选择。

使用 `gpart show` 命令时，FAT32 文件系统通常显示为 `ms-basic-data` 类型。

以下命令显示 `nda1` 磁盘及其分区的详细信息，包括起始位置、大小和类型：

```sh
# gpart show -p nda1
=>      34  41942973    nda1  GPT  (20G)
  29360128   4194304  nda1p3  ms-basic-data  (2.0G) # 即为 FAT32

……已忽略其他无关输出信息……
```

> **注意**
>
> 必须显式声明文件系统类型才能挂载。

将 **/dev/nda1p3** 分区挂载为 msdosfs 文件系统：

```sh
# mount -v -t msdosfs  /dev/nda1p3  /mnt
/dev/nda1p3 on /mnt (msdosfs, local, writes: sync 1 async 0, reads: sync 512 async 0, fsid 7d00000032000000, vnodes: count 1 )
```

* `-v` 参数用于显示详细信息（Verbose）；
* `-t` 参数用于指定文件系统类型。

列出挂载目录下的内容：

```sh
# ls /mnt/
me	test1	test2
```

不再需要时，卸载文件系统：

```sh
# umount /mnt
```

## exFAT 文件系统

exFAT（扩展文件分配表）是专为闪存设备（如 USB 驱动器和 SD 卡）优化的轻量级文件系统。它支持大容量文件，在多个平台上广泛使用，适合外部存储设备。

要在 FreeBSD 上使用 exFAT，需安装 filesystems/exfat 软件包，加载 FUSE 内核模块，并按如下方式挂载文件系统：

### 安装 exFAT 软件包

使用 pkg 安装 exFAT 软件包：

```sh
# pkg install fusefs-exfat
```

使用 Ports 安装：

```sh
# cd /usr/ports/filesystems/exfat/
# make install clean
```

### 加载 fusefs(4) 内核模块

在使用 FUSE 文件系统前，需加载 fusefs(4) 内核模块：

```sh
# kldload fusefs
```

使用 sysrc(8) 设置开机自动加载该模块：

```sh
# sysrc kld_list+=fusefs
```

### 格式化磁盘为 exFAT 文件系统

需要自行安装 Port **filesystems/exfat-utils**，其提供了工具 `mkexfatfs` 用于格式化磁盘为 exFAT 格式。

* 创建 GPT 分区表

```sh
# gpart create -s gpt ada1
```

* 创建一个包含所有剩余空间的分区

```sh
# gpart add -t ms-basic-data ada1
```

* 格式化为 exFAT

```sh
# mkexfatfs -n "Mytest" /dev/ada1p1
```

选项 `-n` 可以指定卷标 `Mytest`。

* 验证 **/dev/ada1p1** 分区使用的文件系统：

```sh
# fstyp /dev/ada1p1
exfat
```

### 测试挂载 exFAT 卷

通过指定其 FreeBSD 分区名和一个已存在的挂载点来挂载 exFAT 卷。以下示例将 **/dev/ada1p1** 挂载到 **/mnt**：

```sh
# mount.exfat /dev/ada1p1 /mnt
```

验证 exFAT 卷挂载情况：

```sh
# df -hl
Filesystem            Size    Used   Avail Capacity  Mounted on
/dev/ada1p1            20G    2.7M     20G     0%    /mnt

……省略无关输出……
```

尝试读写一些文件：

```sh
# cd /mnt
# touch test
# mkdir -p test2/test2
# ls -al
total 73
drwxrwxrwx   1 root wheel 32768 May 29 17:39 .
drwxr-xr-x  20 root wheel    22 May 29 17:04 ..
-rwxrwxrwx   1 root wheel     0 May 29 17:39 test
drwxrwxrwx   1 root wheel 32768 May 29 17:39 test2
```

## 参考文献

* FreeBSD Project. ntfs-3g manpage\[EB/OL]. \[2026-03-25]. <https://man.freebsd.org/cgi/man.cgi?query=ntfs-3g&sektion=8>. ntfs-3g 官方技术文档，说明各项参数配置与使用方法。
* Stephen Sherratt. NTFS on FreeBSD\[EB/OL]. \[2026-03-25]. <https://www.gridbugs.org/ntfs-on-freebsd/>. 系统阐述了 NTFS 文件系统在 FreeBSD 上的挂载技术实现方案。
* FreeBSD Forums. Why fstab file does not recognize NTFS commands?\[EB/OL]. \[2026-04-19]. <https://forums.freebsd.org/threads/why-file-fstab-file-does-not-recognize-ntfs-commands.91972/>. 讨论 NTFS 在 fstab 文件中的参数。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-26-zhang-qi-ta-wen-jian-xi-tong/di-26.1-jie-windows-wen-jian-xi-tong.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
