如何升级到 Ubuntu 22.04 果冻水母

介绍

Ubuntu 操作系统的最新长期支持 (LTS) 版本 Ubuntu 22.04 (Jammy Jellyfish) 于 2022 年 4 月 21 日发布。

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

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

前提条件

此指南假定您有一个 Ubuntu 20.04 或更高版本的系统配置了 sudo 启用的非根用户。

潜在的陷阱

虽然许多系统可以在现场进行升级,但通过从头开始安装发行版,通过仔细测试配置服务,并作为一个单独的步骤迁移应用程序或用户数据,迁移到一个主要的新版本往往更安全和更可预测。

您不应该在不先在舞台环境中对部署的所有软件和服务进行升级之前升级生产系统. 请记住,图书馆、语言和系统服务可能发生了重大变化。

步骤1 - 备份您的系统

在尝试在任何系统上进行重大升级之前,您应该确保在升级失败时不会丢失数据. 实现这一点的最佳方法是对整个文件系统进行备份。 如果没有,请确保您有用户主目录的副本,任何自定义配置文件,以及服务(如关系数据库)存储的数据。

在DigitalOcean Droplet中,一种方法是下载系统并拍摄瞬间照片(下载瞬间照片确保文件系统更加一致)。 请参阅 How to Create Snapshots of Droplets 有关瞬间照片过程的更多细节。

对于大多数 Ubuntu 系统上可用的备份方法,请参阅 如何为 VPS 选择有效的备份策略

步骤 2 – 更新目前安装的软件包

在启动版本升级之前,最安全的是更新到最新版本的所有包 对于当前版本. 开始更新包列表:

1sudo apt update

接下来,将安装的软件包升级到其最新的可用版本:

1sudo apt upgrade

您将看到升级列表,并被要求继续。 按 y 以确认并按 Enter

此过程可能需要一段时间。一旦完成,请使用apt-getdist-upgrade命令,该命令将执行任何附加升级,其中包括更改依赖性,根据需要添加或删除新包。

1sudo apt dist-upgrade

再次,当被要求继续时,回答 y,然后等待升级完成。

现在你已经安装了Ubuntu的最新版本,你可以使用Do-release-upgrade升级到22.04版本。

步骤 3 – 使用 Ubuntu 的 do-release-upgrade 工具升级

传统上,Ubuntu版本可以通过更改Apt的/etc/apt/sources.list - 它指定了包库 - 并使用apt-get dist-upgrade来执行升级本身进行升级。

'do-release-upgrade' 处理查找新版本、更新'sources.list' 和一系列其他任务,是必须通过远程连接执行的服务器升级的官方推荐升级路径。

開始執行「執行發行升級」,沒有選項:

1sudo do-release-upgrade

如果新的Ubuntu版本尚未正式发布,您可能会获得以下输出:

1[secondary_label Output]
2Checking for a new Ubuntu release
3No new release found

请注意,在Ubuntu Server上,新的LTS版本直到其第一个 point release,在这种情况下 22.04.1,才可用于Do-release-upgrade

如果您看不到可用的版本,请添加 -d 选项来升级到 development 版本:

1sudo do-release-upgrade -d

对于虚拟机或受管理服务器,您应该记住,失去 SSH 连接是一种风险,特别是如果您没有其他方法可以远程连接到系统的控制台(例如基于 Web 的控制台功能)。

对于您控制的其他系统,请记住,只有当您有直接物理访问机器时,才进行重大操作系统升级是最安全的。

在提示中,键入 y 并按 Enter 继续:

 1[secondary_label Output]
 2Reading cache
 3
 4Checking package manager
 5
 6Continue running under SSH?
 7
 8This session appears to be running under ssh. It is not recommended
 9to perform a upgrade over ssh currently because in case of failure it
10is harder to recover.
11
12If you continue, an additional ssh daemon will be started at port
13'1022'.
14Do you want to continue?
15
16Continue [yN]

接下来,您将被告知Do-release-upgrade正在在端口 1022 上启动一个新的sshd实例:

 1[secondary_label Output]
 2Starting additional sshd
 3
 4To make recovery in case of failure easier, an additional sshd will
 5be started on port '1022'. If anything goes wrong with the running
 6ssh you can still connect to the additional one.
 7If you run a firewall, you may need to temporarily open this port. As
 8this is potentially dangerous it's not done automatically. You can
 9open the port with e.g.:
10'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'
11
12To continue please press [ENTER]

在DigitalOcean系统上,忽略此警告并继续升级是安全的,因为实际上有可用的是22.04的本地镜子。

 1[secondary_label Output]
 2Updating repository information
 3
 4No valid mirror found
 5
 6While scanning your repository information no mirror entry for the
 7upgrade was found. This can happen if you run an internal mirror or
 8if the mirror information is out of date.
 9
10Do you want to rewrite your 'sources.list' file anyway? If you choose
11'Yes' here it will update all 'focal' to 'jammy' entries.
12If you select 'No' the upgrade will cancel.
13
14Continue [yN]

一旦下载了新包列表并计算了更改,您将被问及是否要开始升级。

 1[secondary_label Output]
 2Do you want to start the upgrade?
 3
 44 packages are going to be removed. 107 new packages are going to be
 5installed. 554 packages are going to be upgraded.
 6
 7You have to download a total of 547 M. This download will take about
 81 minute with a 40Mbit connection and about 14 minutes with a 5Mbit
 9connection.
10
11Fetching and installing the upgrade can take several hours. Once the
12download has finished, the process cannot be canceled.
13
14 Continue [yN]  Details [d]

您可能会收到关于无法禁用锁屏的另一个警告:

1[secondary_label Output]
2Unable to disable lock screen
3
4It is highly recommended that the lock screen be disabled during the
5upgrade to prevent later issues. Please ensure your screen lock is
6disabled before continuing.

如果您正在连接到Ubuntu服务器,而不是桌面,您可以通过点击Enter来忽略此警告。

新的包将被检索、解包和安装,即使您的系统处于快速连接状态,这也需要一段时间。

在安装过程中,您可能会收到交互式对话框以回答各种问题,例如,您可能会被问及在需要时是否要自动重新启动服务:

Service Restart Dialog

在这种情况下,回答是安全的,在其他情况下,您可能会被问及您是否想要更改的配置文件。

一旦新包已完成安装,您将被问及是否准备好删除过时的包。在没有自定义配置的库存系统上,应该安全地在这里输入 y。在您大大修改的系统上,您可能希望输入 d并检查要删除的包的列表,如果它包含任何您需要稍后重新安装的内容。

1[secondary_label Output]
2Remove obsolete packages?
3
453 packages are going to be removed.
5
6 Continue [yN]  Details [d]

最后,假设一切顺利,您将被告知升级完成,需要重新启动。

1[secondary_label Output]
2System upgrade is complete.
3
4Restart required
5
6To finish the upgrade, a restart is required.
7If you select 'y' the system will be restarted.
8
9Continue [yN]

在 SSH 会话中,您可能会看到以下内容:

1[secondary_label Output]
2Connection to 203.0.113.241 closed by remote host.
3Connection to 203.0.113.241 closed.

您可能需要按下一个键来退出本地提示,因为您的SSH会话将在服务器端结束。

等待一会儿,你的服务器重新启动,然后重新连接. 在登录时,你应该收到一个确认你现在在Focal Fossa的消息:

1[secondary_label Output]
2Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-25-generic x86_64)

结论

您现在应该有一个运行的Ubuntu 22.04 安装。从这里开始,您可能需要调查所部署的服务和应用程序所需的配置更改。

您可以在我们的 Ubuntu 22.04 教程标签页面上找到更多 22.04 教程和问题。

Published At
Categories with 技术
comments powered by Disqus