> 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/release/freebsd-15.1-release/15.1-upgrading.md).

# FreeBSD 15.1-RELEASE 升级说明

## 摘要

本说明详述将现有安装升级到 FreeBSD 15.1-RELEASE 的过程。

## 引言

本文档说明将现有 14.4-RELEASE 或 15.0-RELEASE 安装升级到 15.1-RELEASE 的过程。运行更旧版本的系统必须先增量升级到其中之一，才能执行本次升级。

升级操作系统前，请备份 *所有* 文件系统，阅读 [最新勘误](/release/freebsd-15.1-release/15.1-errata.md) 了解已知问题与变通方案，并阅读 [发行说明](/release/freebsd-15.1-release/15.1.md) 了解主要变更与不兼容性。

二进制升级的过程取决于操作系统的管理方式。要确定管理方式，请运行以下命令：

```sh
pkg which /usr/bin/uname
```

若显示 `/usr/bin/uname was not installed by a package`，请参阅下文的 [通过发行版升级](#通过发行版升级)。

若显示包名（如 `FreeBSD-runtime-15.0`），请参阅下文的 [通过 pkgbase 升级](#通过-pkgbase-升级)。

若通过源码升级，请参阅 [FreeBSD Handbook 的“从源码更新 FreeBSD”章节](https://docs.freebsd.org/en/books/handbook/cutting-edge/#makeworld)。

## 通过发行版升级

通过发行版部署的系统使用 [freebsd-update(8)](https://man.freebsd.org/cgi/man.cgi?query=freebsd-update\&sektion=8\&format=html) 升级。运行 14.4-RELEASE 或 15.0-RELEASE 的系统可按以下步骤升级：

1. **应用所有待处理补丁**

   升级前，始终先获取并应用当前系统的所有待处理补丁：

   ```sh
   freebsd-update fetch
   freebsd-update install
   ```
2. **升级内核**

   获取并安装新内核：

   ```sh
   freebsd-update upgrade -r 15.1-RELEASE
   freebsd-update install
   ```

   此过程中 [freebsd-update(8)](https://man.freebsd.org/cgi/man.cgi?query=freebsd-update\&sektion=8\&format=html) 可能会请求协助合并配置文件。
3. **重启进入新内核**

   安装新用户态前，先重启进入新内核：

   ```sh
   shutdown -r +10min "Rebooting for a kernel upgrade"
   ```
4. **升级用户态**

   重启后，再次运行 [freebsd-update(8)](https://man.freebsd.org/cgi/man.cgi?query=freebsd-update\&sektion=8\&format=html) 安装新用户态组件：

   ```sh
   freebsd-update install
   ```

   因系统库变更，[freebsd-update(8)](https://man.freebsd.org/cgi/man.cgi?query=freebsd-update\&sektion=8\&format=html) 可能会提示重新编译或重新安装所有第三方软件。请按提示操作。

   > **提示**：若从 14.4-RELEASE 升级且无法重新安装所有第三方软件，可安装 [misc/compat14x](https://www.freshports.org/misc/compat14x) 软件包。
5. **删除旧文件**

   再次运行 [freebsd-update(8)](https://man.freebsd.org/cgi/man.cgi?query=freebsd-update\&sektion=8\&format=html) 删除过时的基本系统文件：

   ```sh
   freebsd-update install
   ```
6. **升级引导加载程序**

   要确定系统上需更新的引导加载程序，请运行以下命令：

   ```sh
   sysctl machdep.bootmethod
   ```

   继续参阅下文的 [升级 UEFI 引导加载程序](#升级-uefi-引导加载程序) 或 [升级 BIOS 引导加载程序](#升级-bios-引导加载程序)。

## 通过 pkgbase 升级

通过 pkgbase 部署的系统使用 [pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 升级。运行 15.0-RELEASE 的系统可按以下步骤升级：

1. **为当前安装创建快照**

   若从 ZFS 启动，对正常运行的系统创建以当前日期命名的递归快照：

   ```sh
   bectl create -r pre-15.1
   ```

   引导加载程序会提供菜单，用于在需要回滚升级时从该快照启动。
2. **升级已安装系统**

   升级到新版本前，确保已安装系统为最新：

   ```sh
   pkg upgrade -r FreeBSD-base
   ```
3. **升级基本系统**

   ```sh
   pkg -oABI=FreeBSD:15:$(uname -p) -oOSVERSION=1501000 upgrade -r FreeBSD-base
   ```

   升级后，查看 **pkg(8)** 打印的任何消息。部分软件包可能需要额外的配置步骤，如运行 `service <name> setup`。请按提示操作。
4. **升级第三方内核模块**

   若安装了第三方内核模块，也必须随基本系统一起升级：

   ```sh
   pkg upgrade -r FreeBSD-ports-kmods
   ```

   若未安装此类模块，[pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 会相应回复。
5. **检查失败的配置更新**

   若 [pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 无法合并配置文件更新，会将新配置安装为 `.pkgnew` 文件。使用以下命令检查这些文件：

   ```sh
   find /etc /usr/local/etc -name '*.pkgnew' -ls
   ```

   若存在，与已部署版本比较（如 `diff /etc/rc.conf /etc/rc.conf.pkgnew`），合并必要变更。
6. **升级引导加载程序**

   要确定系统上需更新的引导加载程序，请运行以下命令：

   ```sh
   sysctl machdep.bootmethod
   ```

   继续参阅下文的 [升级 UEFI 引导加载程序](#升级-uefi-引导加载程序) 或 [升级 BIOS 引导加载程序](#升级-bios-引导加载程序)。

## 升级 UEFI 引导加载程序

7. **识别 ESP**

   执行以下命令，识别引导加载程序所在的 EFI 系统分区（ESP）：

   ```sh
   efibootmgr -v
   ```

   输出应类似如下：

   ```sh
    +Boot0000* FreeBSD HD(1,GPT,f859c46d-19ee-4e40-8975-3ad1ab00ac09,0x800,0x82000)/File(\EFI\freebsd\loader.efi)
                          nda0p1:/EFI/freebsd/loader.efi (null)
   ```

   活动的引导加载程序条目以加号（`+`）字符开头。注意引导加载程序的位置，本例中为 `nda0p1` 上的 `EFI/freebsd/loader.efi`，但不同系统会有所差异。
8. **挂载 ESP**

   若 ESP 尚未挂载到 **/boot/efi**，挂载 `efibootmgr` 输出中列出的分区：

   ```sh
   mount_msdosfs /dev/nda0p1 /boot/efi
   ```
9. **安装引导加载程序**

   在 AMD64 系统上，执行以下命令升级配置位置和默认位置中的引导加载程序：

   ```sh
   cp /boot/loader.efi /boot/efi/efi/freebsd/loader.efi
   cp /boot/loader.efi /boot/efi/efi/boot/bootx64.efi
   ```

   注意，部分安装可能大小写相反（如 `EFI/BOOT/BOOTX64.EFI`），或可能没有 `freebsd/loader.efi`。

   在 AArch64 系统上，执行以下命令：

   ```sh
   cp /boot/loader.efi /boot/efi/efi/freebsd/loader.efi
   cp /boot/loader.efi /boot/efi/efi/boot/bootaa64.efi
   ```

   其他架构相应有所不同；必要时请参阅 [loader.efi(8)](https://man.freebsd.org/cgi/man.cgi?query=loader.efi\&sektion=8\&format=html)。
10. **完成**

    完成升级到 FreeBSD 15.1-RELEASE 后重启：

    ```sh
    shutdown -r +10min "Rebooting for a system upgrade"
    ```

## 升级 BIOS 引导加载程序

对于通过 BIOS 或 UEFI CSM 启动并使用 GPT 分区方案的系统，除非 ZFS 根池升级（不建议），否则引导加载程序升级是可选的。仅当 `freebsd-boot` 分区至少为 180K 时才能升级；512K 现已成为标准。

7. **识别 freebsd-boot 分区**

   执行以下命令，识别 `freebsd-boot` 设备名和分区索引：

   ```sh
   gpart show
   ```

   输出应类似如下：

   ```sh
    =>       34  246162605  ada0  GPT  (224G)
             34       1024     1  freebsd-boot  (512K)
   ```

   注意 `freebsd-boot` 分区的名称（`ada`）和索引（`1`）。
8. **升级引导加载程序**

   在 BIOS 上使用 ZFS 时，运行以下命令升级引导代码：

   ```sh
   gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
   ```

   其中 `1` 为 `freebsd-boot` 分区的索引。

   若从存储阵列启动，对池中所有磁盘重复此步骤。

   在 BIOS 上使用 UFS 时，执行以下命令：

   ```sh
   gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
   ```
9. **完成**

   完成升级到 FreeBSD 15.1-RELEASE 后重启：

   ```sh
   shutdown -r now
   ```


---

# 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/release/freebsd-15.1-release/15.1-upgrading.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.
