如何将 FreeBSD 从 10.2 版升级到 10.3 版

介绍

<$>[注] 注: 截至 2022 年 7 月 1 日,DigitalOcean 不再支持通过控制面板或 API 创建新的 FreeBSD Droplets。

FreeBSD 正在不断发展;团队正在添加新功能和修补安全漏洞. 保持服务器操作系统的更新确保了更好的安全性和兼容性,而 FreeBSD 包含了freebsd-update工具,以便轻松完成此操作。

<$>[警告] 警告: 与操作系统的主要版本之间几乎任何升级一样,此过程具有固有故障、数据丢失或软件配置故障的风险。

为了避免这些问题,如果可能的话,我们建议迁移到新 FreeBSD 服务器,而不是在现场升级,您可能需要在升级时查看软件配置差异,但核心系统可能具有更大的稳定性。

前提条件

要遵循本教程,您将需要:

  • 一个运行 FreeBSD 10.2 的服务器
  • 一个配置为运行命令的用户帐户sudo。 为本教程的目的,我们将使用用户 freebsd. 有关 FreeBSD 服务器及其基本管理的更多信息,请参阅 Getting Started with FreeBSD 教程系列。

步骤1 - 提取和应用补丁

为了升级操作系统,我们首先需要提取我们的目标版本的包和补丁. 使用 freebsd帐户登录服务器。

1ssh freebsd@your_server_ip

然后,使用freebsd-upgrade命令收集有关系统升级的信息,并确定需要更改的内容。

1sudo freebsd-update upgrade -r 10.3-RELEASE

我们使用-r交换机来指定我们要升级的版本,即10.3-RELEASE

 1[secondary_label Output]
 2src component not installed, skipped
 3Looking up update.FreeBSD.org mirrors... 4 mirrors found.
 4Fetching public key from update6.freebsd.org... done.
 5Fetching metadata signature for 10.2-RELEASE from update6.freebsd.org... done.
 6Fetching metadata index... done.
 7Fetching 2 metadata files... done.
 8Inspecting system... 
 9
10The following components of FreeBSD seem to be installed:
11kernel/generic world/base world/doc world/games world/lib32
12
13The following components of FreeBSD do not seem to be installed:
14
15Does this look reasonable (y/n)? y

这为您提供了审查任何潜在问题的机会. 输入y并按ENTER继续。

<$>[注] 注: 请记住,本教程使用新 FreeBSD 10.2 服务器指导您升级 FreeBSD 基系统到版本 10.3-RELEASE-p4 的所有步骤。

一旦您同意继续,此过程将应用更新和补丁,您将看到以下输出:

 1[secondary_label Output]
 2Fetching metadata signature for 10.3-RELEASE from update6.freebsd.org... done.
 3Fetching metadata index... done.
 4Fetching 1 metadata patches. done.
 5Applying metadata patches... done.
 6Fetching 1 metadata files... done.
 7Inspecting system... 
 8Fetching files from 10.2-RELEASE for merging... done.
 9Preparing to download files... 
10Fetching 10722 patches.....10....20....30....40....50....60....70....80....90
11....100....110....120....130....140....150....160....170....180....190....200
12
13    **. . .**
14
15....10650....10660....10670....10680....10690....10700....10710....10720. done.
16Applying patches... done.
17Fetching 152 files... 
18Attempting to automatically merge changes in files... done.

然而,这个过程不能自动修补一切,我们需要手动干预。

步骤二:解决冲突

将修补程序应用到操作系统后,freebsd-update会向您显示两个警告消息,您将需要在两个不同的配置文件中手动解决一些小的冲突。

你看到的第一个警告如下:

1[secondary_label output]
2The following file could not be merged automatically: `/etc/rc.subr`
3Press Enter to edit this file in vi and resolve the conflicts
4manually...

当你按Enter,在vi文本编辑器中打开/etc/rc.subr文件,你会看到以下文本:

1[label /etc/rc.subr file with conflicts to solve manually]
2# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
3<<<<<<< current version
4# $FreeBSD: releng/10.1/etc/rc.subr 273188 2014-10-16 22:00:24Z hrs $
5=======
6# $FreeBSD: releng/10.3/etc/rc.subr 292450 2015-12-18 19:58:34Z jilles $
7>>>>>>> 10.3-RELEASE

通过删除与当前版本相关的行来修改本节,这些行在上面以红色突出。尽管我们目前正在运行 FreeBSD 10.2,但此文件引用了 10.1 作为当前

1[label /etc/rc.subr ready to proceed]
2# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
3# $FreeBSD: releng/10.3/etc/rc.subr 292450 2015-12-18 19:58:34Z jilles $

将更改保存到文件中,然后离开编辑器。

一旦你关闭文本编辑器,你会看到一行报告你刚刚更改的文件的成功合并,然后你会看到第二个警告,该警告说‘/etc/ssh/sshd_config’配置文件需要你的注意:

1[secondary_label Output]
2/var/db/freebsd-update/merge/new//etc/rc.subr: 2087 lines, 47888 characters.
3
4The following file could not be merged automatically: `/etc/ssh/sshd_config`
5Press Enter to edit this file in vi and resolve the conflicts
6manually...

就像以前一样,当你按下ENTER时,你会收到一个文本文件,你需要修改。

1[label /etc/ssh/sshd_config file with conflicts to solve manually]
2<<<<<<< current version
3#       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
4#       $FreeBSD: releng/10.1/crypto/openssh/sshd_config 264692 2014-04-20 12:46:18Z des $
5=======
6#       $OpenBSD: sshd_config,v 1.98 2016/02/17 05:29:04 djm Exp $
7#       $FreeBSD: releng/10.3/crypto/openssh/sshd_config 296853 2016-03-14 13:05:13Z des $
8>>>>>>> 10.3-RELEASE

再次,通过删除与当前版本相关的行来修改此部分,直到文件的部分看起来像这样:

1[label /etc/ssh/sshd_config ready to proceed]
2#       $OpenBSD: sshd_config,v 1.98 2016/02/17 05:29:04 djm Exp $
3#       $FreeBSD: releng/10.3/crypto/openssh/sshd_config 296853 2016-03-14 13:05:13Z des $

将更改保存到文件中,并关闭编辑器。

编辑器关闭后,freebsd-update过程会显示您所更改的每个文件,并询问这些更改是否看起来合理。

一旦您同意这些更改,您将看到一份将被更新的二进制和配置文件列表。这个列表非常长;按SPACE按下以便在列表上一次滚动。

名单看起来像这样:

 1[secondary_label Output]
 2The following files will be added as part of updating to 10.3-RELEASE-p5:
 3/boot/kernel/ismt.ko
 4/boot/kernel/ismt.ko.symbols
 5/boot/kernel/linux64.ko
 6/boot/kernel/linux64.ko.symbols
 7/boot/kernel/linux_common.ko
 8/boot/kernel/linux_common.ko.symbols
 9/boot/kernel/mlx5.ko
10
11    . . .
12
13The following files will be updated as part of updating to 10.3-RELEASE-p5:
14/.cshrc
15/.profile
16/COPYRIGHT
17/bin/[
18/bin/cat
19/bin/chflags
20/bin/chio
21
22    . . .

一旦您查看了列表,您将返回您的终端提示. 您已准备好执行安装。

步骤 3 — 安装 FreeBSD 10.3

已下载更新并成功合并或配置必要的文件,因此要安装下载的升级,请使用以下命令:

1sudo /usr/sbin/freebsd-update install

以下是你会看到的结果:

1[secondary_label Output]
2src component not installed, skipped
3Installing updates...
4Kernel updates have been installed. Please reboot and run
5"/usr/sbin/freebsd-update install" again to finish installing updates.

安装提示您重新启动,所以执行此命令来重新启动您的机器:

1sudo reboot

您将从您的 SSH 会话中断连接,重新启动将需要大约一分钟。

<$>[注] 注: 您必须重新启动您的服务器才能加载新的 10.3-RELEASE-p4 内核及其修补的二进制文件,这些文件仅在启动过程中加载。

步骤4:完成安装过程

让我们检查我们的服务器的版本,以确保升级过程奏效,并加载了新的内核。

1ssh freebsd@your_server_ip

登录后,运行以下命令:

1uname -a

您将看到以下输出,表示升级工作了:

1[secondary_label Output]
2FreeBSD YOUR_HOSTNAME 10.3-RELEASE-p4 FreeBSD 10.3-RELEASE-p4 #0: Sat May 28 12:23:44 UTC 2016 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64

我们需要安装自发布以来可能发生的任何最终更新,所以再次运行freebsd-update

1sudo /usr/sbin/freebsd-update install

您将看到以下输出:

1[secondary_label Output]
2src component not installed, skipped
3Installing updates...
4Installing updates...
5install: ///var/db/etcupdate/current/etc/mtree/BSD.debug.dist: No such file or directory
6install: ///var/db/etcupdate/current/etc/periodic/daily/480.leapfile-ntpd: No such file or directory
7 done.

無視兩個警告是安全的,這兩個檔案都會由這個過程創建或更新。

当您升级 FreeBSD 时,您还应该升级所有第三方安装的软件包,特别是如果您正在进行重大版本升级。

1sudo pkg upgrade

结果将是这样的:

 1[secondary_label Output]
 2Updating FreeBSD repository catalogue...
 3FreeBSD repository is up-to-date.
 4All repositories are up-to-date.
 5
 6    . . .
 7
 8Processing entries: 100%
 9FreeBSD repository update completed. 25089 packages processed.
10New version of pkg detected; it needs to be installed first.
11The following 1 package(s) will be affected (of 0 checked):
12
13Installed packages to be UPGRADED:
14        pkg: 1.5.6 -> 1.7.2
15
16The process will require 242 KiB more space.
172 MiB to be downloaded.
18
19Proceed with this action? [y/N]: y

输入y,然后按ENTER,继续,你会看到以下输出:

 1[secondary_label Output]
 2Fetching pkg-1.7.2.txz: 100%    2 MiB 1.3MB/s 00:02    
 3Checking integrity... done (0 conflicting)
 4[1/1] Upgrading pkg from 1.5.6 to 1.7.2...
 5[1/1] Extracting pkg-1.7.2: 100%
 6Updating FreeBSD repository catalogue...
 7Repo "FreeBSD" upgrade schema 2011 to 2012: Add depends formula field
 8Repo "FreeBSD" upgrade schema 2012 to 2013: Add vital field
 9FreeBSD repository is up-to-date.
10All repositories are up-to-date.
11Checking for upgrades (24 candidates): 100%
12Processing candidates (24 candidates): 100%
13The following 24 package(s) will be affected (of 0 checked):
14
15Installed packages to be UPGRADED:
16        xproto: 7.0.27 -> 7.0.28
17        sudo: 1.8.13 -> 1.8.16_1
18        rsync: 3.1.1_3 -> 3.1.2_1
19        python27: 2.7.9_1 -> 2.7.11_2
20        py27-setuptools27: 17.0 -> 20.0
21        py27-pip: 7.0.3 -> 8.0.2
22        perl5: 5.20.2_5 -> 5.20.3_12
23        pcre: 8.37_4 -> 8.38_1
24        libxml2: 2.9.2_3 -> 2.9.3
25        libxcb: 1.11_1 -> 1.11.1
26        libnet: 1.1.6_3,1 -> 1.1.6_4,1
27        libiconv: 1.14_8 -> 1.14_9
28        libX11: 1.6.2_3,1 -> 1.6.3,1
29        kbproto: 1.0.6 -> 1.0.7
30        indexinfo: 0.2.3 -> 0.2.4
31        gobject-introspection: 1.42.0 -> 1.46.0
32        glib: 2.42.2 -> 2.46.2
33        gettext-runtime: 0.19.4 -> 0.19.7
34        expat: 2.1.0_3 -> 2.1.1_1
35        dbus: 1.8.16 -> 1.8.20
36        curl: 7.43.0_2 -> 7.48.0_1
37        ca_root_nss: 3.19.3 -> 3.22.2
38        avahi-app: 0.6.31_3 -> 0.6.31_5
39
40Installed packages to be REINSTALLED:
41        dbus-glib-0.104 (option added: DOCS)
42
43The process will require 5 MiB more space.
4439 MiB to be downloaded.
45
46Proceed with this action? [y/N]: y

再次键入y,然后是ENTER,以继续。

包将升级,但为了确保您的用户可以访问最新版本,请运行rehash命令:

1rehash

有了这个,升级过程已经完成了,但是如果有什么不对劲呢?

步骤 5 — 返回失败的安装(可选)

整个升级过程应该顺利进行,但如果升级过程中有什么不对劲,您可以使用以下命令回滚最近安装的软件包:

1sudo freebsd-update rollback

这将启动回归过程,将您带回原来的位置,您还可以恢复您在启动过程前做的最新备份。

结论

升级操作系统到更新的版本,并及时应用安全补丁是持续系统管理的重要方面。freebsd-update命令使这两个任务都很容易完成。

要了解如何升级 FreeBSD 的更多信息,您可以阅读 An Introduction To Basic FreeBSD Maintenance,或在 FreeBSD 手册中查看相应的章节。

Published At
Categories with 技术
comments powered by Disqus