摘要
文章内容
FreeBSD 14.2 到 14.3 源码升级的完整指南,涵盖预检查、ZFS 快照与 Boot Environment 创建、源码树切换、编译安装内核与世界、etcupdate 配置合并,以及使用 poudriere 重建软件包。
升级流程
- 升级前必须创建 Boot Environment 和 ZFS 快照以便回滚
- 源码编译安装分为内核和世界两个阶段,中间需要重启
- etcupdate 用于处理配置文件的三方合并
软件包处理
- 含内核模块的包必须使用新版本 jail 重新构建
- 升级后需切换 pkg 仓库到新构建的包并强制升级
- 清理旧文件前应确保所有包已完成重建
回滚方案
出现问题时可通过 bectl 激活旧的 Boot Environment 快速回滚。
升级流程总览
0. 预检查
freebsd-version -kru
uname -a
zpool list; zpool status -x
zfs list -r zroot | head -50
df -h / /usr/src /usr/obj /var
sysctl hw.ncpu
git -C /usr/src remote -v
git -C /usr/ports remote -v
升级前务必阅读:
1. ZFS 备份与 Boot Environment
查看现有 BE:
bectl list
创建回滚用 BE:
bectl create 14.2-p2-pre143
创建递归快照:
POOL=zroot
ROOTDS=${POOL}/ROOT
zfs snapshot -r ${ROOTDS}@pre-14.3-$(date +%F)
回滚方法:
bectl activate -t 14.2-p2-pre143 && reboot
参考:bectl(8)
2. 更新源码树
切换到 releng/14.3 分支:
git -C /usr/src fetch --all --tags
git -C /usr/src checkout releng/14.3
git -C /usr/src pull --ff-only
若首次使用 etcupdate,先初始化:
etcupdate extract
etcupdate diff
参考:etcupdate(8)
3. 编译并安装内核与世界
编译
cd /usr/src
J=$(sysctl -n hw.ncpu)
make -j${J} buildworld
make -j${J} buildkernel KERNCONF=GENERIC
安装内核
make installkernel KERNCONF=GENERIC
shutdown -r now
安装世界
重启后执行:
etcupdate -p
cd /usr/src
make installworld
etcupdate -B
pwd_mkdb -p /etc/master.passwd
shutdown -r now
建议在单用户模式下执行 installworld。
4. poudriere 构建新包
创建 ports 树
生产环境推荐季度分支:
poudriere ports -c -p 2025Q4 -m git+https -B 2025Q4
更新已有树:
poudriere ports -u -p 2025Q4
参考:Ports 季度分支说明
创建 14.3 jail
poudriere jail -c -j 143amd64 -v 14.3-RELEASE -a amd64
后续更新:
poudriere jail -u -j 143amd64
参考:poudriere-jail(8)
批量构建
poudriere bulk -j 143amd64 -p 2025Q4 -f /usr/local/etc/poudriere.d/pkglist
参考:poudriere-bulk(8)
注意:含内核模块的包(如 drm-kmod)必须用 14.3 jail 重新构建。
切换 pkg 仓库
mkdir -p /usr/local/etc/pkg/repos
cat >/usr/local/etc/pkg/repos/FreeBSD.conf <<'EOF'
FreeBSD: { enabled: no }
EOF
cat >/usr/local/etc/pkg/repos/poudriere.conf <<'EOF'
poudriere: {
url: "file:///usr/local/poudriere/data/packages/143amd64-2025Q4",
enabled: yes,
mirror_type: "none"
}
EOF
pkg update -f
pkg upgrade -f
参考:Custom Poudriere Packages in Your Own Repository
5. 清理
make -C /usr/src delete-old
make -C /usr/src delete-old-libs
freebsd-version -kru
pkg -vv | egrep 'ABI|Repository'
注意:确保所有包已切换到新构建后再执行 delete-old-libs。
6. 回滚
若出现问题:
bectl activate -t 14.2-p2-pre143
reboot
或对特定数据集回滚:
zfs rollback ${ROOTDS}@pre-14.3-YYYY-MM-DD
快速参考
| 步骤 |
命令 |
| 创建 BE |
bectl create 14.2-p2-pre143 |
| 切换分支 |
git checkout releng/14.3 |
| 编译 |
make buildworld buildkernel |
| 安装内核 |
make installkernel && reboot |
| 安装世界 |
etcupdate -p && make installworld && etcupdate -B |
| 构建包 |
poudriere bulk -j 143amd64 -p 2025Q4 -f pkglist |
| 升级包 |
pkg upgrade -f |
| 清理 |
make delete-old && make delete-old-libs |
| 回滚 |
bectl activate -t 14.2-p2-pre143 |