使用Freebsd-update升级FreeBSD操作系统

・8 分钟阅读

在本文中,我们将使用freebsd-update升级FreeBSD操作系统,freebsd-update使用最新的修补程序更新你的实例,或者你也可以选择升级到次要版本或主要版本。

步骤1:更新实例前重点考虑

  • 备份实例,最简单的方法是快照,你还可以选择从/etc/中备份配置文件,
  • 保留维护期,以便在该时间范围内规划和测试升级;,与次要版本或补丁版本升级相比,应该为主版本升级预留更长的时间。
  • 如果要升级到主要版本,在测试或开发实例上测试freebsd-update更安全,你可以使用快照启动测试实例,然后测试升级,这样不会对你的生产实例产生任何影响,
  • 启动升级之前,建议关闭实例上的服务,例如:web服务器,数据库等,升级完成后,可以启用这些功能,
  • 请在开始升级之前,查看FreeBSD发行版的发行说明,
  • 你需要在/var分区中至少有500MB可用空间,特别是升级到新的次要或主要版本,

步骤2: 更新到最新补丁版本

下载更新

补丁版本包含对操作系统文件和二进制文件的修复,还可能包含内核的更改,使用freebsd-update获取更新,为了简洁,以下命令的输出已被编辑。


# freebsd-version
11.0-RELEASE-p1
# freebsd-update fetch
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from update4.freebsd.org... done.
Fetching metadata signature for 11.0-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 998 patches......... done.
Applying patches... done.
Fetching 6 files... done.
The following files will be removed as part of updating to 11.0-RELEASE-p11:
/boot/kernel/hv_ata_pci_disengage.ko
...
The following files will be added as part of updating to 11.0-RELEASE-p11:
/usr/share/zoneinfo/Asia/Barnaul
...
The following files will be updated as part of updating to 11.0-RELEASE-p11:
/bin/freebsd-version
...
WARNING: FreeBSD 11.0-RELEASE-p1 is approaching its End-of-Life date.
It is strongly recommended that you upgrade to a newer
release within the next 2 months.

安装更新

更新已下载到你的服务器,现在安装它们。


# freebsd-update install
src component not installed, skipped
Installing updates... done.

如果需要,重新引导到新内核

11.0-RELEASE-p1升级到11.0-RELEASE-p11需要安装新内核,重新引导实例以引导到新安装的内核。


# shutdown -r now
... system reboot ... 
# freebsd-version
11.0-RELEASE-p11

你已经成功地将实例从11.0-RELEASE升级到11.0-RELEASE-p11 ,启用你的服务并测试实例。

步骤3: 更新到次要或主要版本

正在下载升级

在本节中,我们将FreeBSD实例从FreeBSD 11.0-RELEASE升级到FreeBSD 11.1-RELEASE ,在本例中,freebsd-update命令与之前的补丁版本升级,注意,如果由于本地更改导致文件中存在一些冲突,freebsd-update将提示你输入相同的信息,并允许你解决冲突。


# freebsd-version
11.0-RELEASE-p11
# freebsd-update upgrade -r 11.1-RELEASE
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching metadata signature for 11.0-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system... done.

The following components of FreeBSD seem to be installed:
kernel/generic kernel/generic-dbg world/base world/lib32

The following components of FreeBSD do not seem to be installed:
world/base-dbg world/doc world/lib32-dbg

Does this look reasonable (y/n)? y
Fetching metadata signature for 11.1-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Fetching files from 11.0-RELEASE for merging... done.
Preparing to download files... done.
Fetching 11513 patches.....10....11510. done.
Applying patches... done.
Fetching 262 files... done.
Attempting to automatically merge changes in files... done.
The following files will be removed as part of updating to 11.1-RELEASE-p0:
/usr/include/netinet/ip_ipsec.h
...
The following files will be added as part of updating to 11.1-RELEASE-p0:
/boot/kernel/amd_ecc_inject.ko
...
The following files will be updated as part of updating to 11.1-RELEASE-p0:
/.cshrc
...
To install the downloaded upgrades, run"/usr/sbin/freebsd-update install".

安装升级

现在文件已经下载,并且所有冲突已经解决了,你可以继续安装更新了。


# freebsd-update install
src component not installed, skipped
Installing updates...
Kernel updates have been installed. Please reboot and run
"/usr/sbin/freebsd-update install" again to finish installing updates.

重新引导到新内核并继续安装

一旦实例重新启动,你就可以确认正在运行的内核版本,并继续安装。


# uname -a
FreeBSD fbsd 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017
 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
# freebsd-version
11.0-RELEASE-p11
# freebsd-update install
src component not installed, skipped
Installing updates...
Completing this upgrade requires removing old shared object files.
Please rebuild all installed 3rd party software (e.g., programs
installed from the ports tree) and then run"/usr/sbin/freebsd-update install"
again to finish installing updates.

主要版本使用不同的应用程序二进制接口(ABI ),这将破坏大多数第三方应用程序,如果使用ports构建第三方应用程序,则需要构建所有这些应用程序,如果使用包管理系统,那么可以使用以下命令。


# pkg-static upgrade -f

安装完所有包后,完成freebsd-update安装。


# freebsd-update install
src component not installed, skipped
Installing updates... done.
# freebsd-version
11.1-RELEASE

恭喜,你的实例已升级到11.1-RELEASE

Anne655 profile image