跳至内容

如何将 Amazon EC2 Linux 实例上的 Ubuntu 从一个 LTS 版本升级到另一个 LTS 版本?

2 分钟阅读
0

我想升级 Amazon Elastic Compute Cloud (Amazon EC2) 实例上的长期支持 (LTS) Ubuntu 版本。

简短描述

您只能将 EC2 实例的 LTS Ubuntu 版本升级到下一个顺序版本。例如,要从 LTS Ubuntu 版本 18.04 升级到版本 24.04,必须先升级到版本 20.04。然后,升级到 22.04,最后升级到 24.04。

解决方法

先决条件:

  • 请查看 Ubuntu 网站上的 Pre-upgrade checklist(升级前检查清单)。
  • 创建数据备份
  • 确保您的 /etc/update-manager/release-upgrades 文件包含 Prompt=lts
  • 确认您的系统可以访问 Ubuntu 的软件包存储库。

更新您的系统

完成以下步骤:

  1. 要检查您的操作系统 (OS) 版本,请运行以下命令:

    lsb_release -a

    输出示例:

    No LSB modules are available.
    Distributor ID:    Ubuntu
    Description:    Ubuntu 20.04.6 LTS
    Release:    20.04
    Codename:    focal
  2. 要为现有 LTS Ubuntu 版本安装所有可用更新,请运行以下命令:

    sudo apt update
    sudo apt upgrade
  3. 重启服务器。
    **注意:**最佳做法是在安装更新后同时重启实例,验证您运行的是否为最新内核。

升级 LTS Ubuntu 版本

完成以下步骤:

  1. 要升级 Ubuntu 版本,请运行以下 Ubuntu 命令:

    sudo do-release-upgrade

    **注意:**只有在最新 LTS 版本的第一个点版本发布之后,您才能升级到下一个 LTS Ubuntu 版本。例如,要将 Ubuntu 18.04 LTS 升级到 20.04 LTS,Ubuntu 必须发布 20.04.1。要在点发布之前测试或评估升级,请在上述命令中添加 -d 标志以升级到 Ubuntu 的开发版本。不要在生产环境中使用 -d 标志。开发版本未经过充分测试,也不受支持。有关版本列表和支持状态,请参阅 Ubuntu 网站上的 List of releases(版本列表)。

  2. 查看收到的摘要中的升级,然后按 Y
    升级摘要示例:

    Do you want to start the upgrade?
    3 packages are going to be removed. 90 new packages are going to be
    installed. 567 packages are going to be upgraded.
    
    You have to download a total of 356 M. This download will take about
    1 minute with your connection.
    
    Installing the upgrade can take several hours. Once the download has
    finished, the process cannot be canceled.
    
     Continue [yN]  Details [d]
  3. 如果现有版本中存在升级可能会覆盖的自定义配置,则实用程序会提示您确认更改。最佳做法是使用默认选择。要保留现有版本,请按 N。要安装软件包维护者的版本,请按 Y。某些场景(例如 /boot/grub/menu.lst)需要您安装软件包维护者的版本。要查看文件版本之间的差异,请按 D
    提示符示例:

    Configuration file '/etc/ssh/ssh_config' ==> Modified (by you or by a script) since installation. ==> Package distributor has shipped an updated version.
       What would you like to do about it ?  Your options are:
        Y or I  : install the package maintainer's version
        N or O  : keep your currently-installed version
          D     : show the differences between the versions
          Z     : start a shell to examine the situation
     The default action is to keep your current version.
    *** ssh_config (Y/I/N/O/D/Z) [default=N] ?
  4. 要移除过时的软件包,请在以下提示符中按 Y

    Searching for obsolete software
    Reading state information... Done
    Remove obsolete packages?
    
    73 packages are going to be removed.
    Continue [yN]  Details [d]
  5. 要重启系统,请在以下提示符中按 Y

    System upgrade is complete.Restart required
    
    To finish the upgrade, a restart is required.
    If you select 'y' the system will be restarted.
    
    Continue [yN]
  6. 重启实例才能完成升级。

  7. 要检查您的 Ubuntu 版本,请重新运行以下命令:

    lsb_release -a

    输出示例:

    No LSB modules are available.
    Distributor ID:    Ubuntu
    Description:    Ubuntu 24.04 LTS
    Release:    24.04
    Codename:    focal
AWS 官方已更新 6 个月前