> 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-24-zhang-zfs-wen-jian-xi-tong/di-24.8-jie-geng-xin-openzfs.md).

# 24.8 更新 OpenZFS

在实现多版本 FreeBSD 共存时，一个重要的考虑因素是 ZFS 池版本的兼容性问题。通常，在 FreeBSD 大版本之间，ZFS 池版本和特性都会发生变化，例如大版本更新时 zpool 通常有所变动，这可能导致无法互相访问存储池。

可通过 Ports 中的 OpenZFS 实现 13、14、15 等多个系统版本的共存。

## 查看内置的 OpenZFS 版本

首先查看当前系统内置的 ZFS 版本信息，以便确认待替换的版本。

显示当前 ZFS 工具和内核模块的版本信息：

```sh
# zfs version
zfs-2.2.7-FreeBSD_ge269af1b3
zfs-kmod-2.2.7-FreeBSD_ge269af1b3
```

目前 FreeBSD 基本系统内置的是 OpenZFS 2.2.7（即来自 <https://github.com/openzfs/zfs/commit/e269af1b3>）。

## 安装 filesystems/openzfs

Ports 中的 OpenZFS 提供了比基本系统更灵活的版本选择。可以使用 pkg 或 Ports 两种方式来安装它。

* 使用 pkg 安装

```sh
# pkg install openzfs
```

* 使用 Ports 安装：

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

## 编辑 **/boot/loader.conf** 文件

安装完成后，需要配置系统启动时加载哪个 ZFS 模块。默认情况下，系统会加载基本系统内置的 ZFS 模块，需要修改这个行为。

为了防止系统加载基本系统内置的 ZFS 版本，需要在 `zfs_load=YES` 前加上注释 `#`，取消其开机自动加载。

形如：

```ini
# zfs_load=YES 	# 不加载内置 ZFS 内核模块
```

再新增下列数行：

```ini
zfs_load=NO        # 显式禁用内置 ZFS 内核模块加载
openzfs_load=YES   # 启用 OpenZFS 模块加载
```

完成后重启系统。

## 检查 ZFS 版本

配置完成并重启后，需要验证系统是否正确加载了 Ports 版本的 OpenZFS。

在重启后，检查 ZFS 版本：

```sh
# zfs version
zfs-2.2.7-FreeBSD_ge269af1b3
zfs-kmod-2.3.5-1
```

随后即可更新其他存储池或启用新的特性。

> **警告**
>
> 考虑到基本系统中的 OpenZFS 版本不一定是最新的，建议所有版本均使用 Ports 中的 OpenZFS 以保持版本统一，包括 15.0-RELEASE 也应按照相同方法替换 ZFS。


---

# 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-24-zhang-zfs-wen-jian-xi-tong/di-24.8-jie-geng-xin-openzfs.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.
