如何通过命令行升级Debian 9为Debian 10

如何通过命令行升级Debian 9为Debian 10

我们已经在先前的文章中看到如何安装 Debian 10(Buster)。今天,我们将学习如何从 Debian 9 升级为 Debian 10,虽然我们已将看到 Debian 10 和它的特色,所以这里我们不会深入介绍。但是可能读者没有机会读到那篇文章,让我们快速了解一下 Debian 10 和它的新功能。

在差不多两年的开发后,Debian  团队最终发布一个稳定版本,Debian 10 的代码名称是 Buster。Buster 是一个 LTS (长期支持支持)版本,因此未来将由 Debian 支持 5 年。

Debian 10(Buster)新的特色

Debian 10(Buster)回报给大多数 Debian 爱好者大量的新特色。一些特色包括:

  • GNOME 桌面 3.30
  • 默认启用 AppArmor
  • 支持 Linux 内核 4.19.0-4
  • 支持 OpenJDk 11.0
  • 从 Nodejs 4 ~ 8 升级到 Nodejs 10.15.2
  • Iptables 替换为 NFTables

等等。

从 Debian 9 到 Debian 10 的逐步升级指南

在我们开始升级 Debian 10 前,让我们看看升级需要的必备条件:

步骤 1) Debian 升级必备条件

  • 一个良好的网络连接
  • root 用户权限
  • 数据备份

备份你所有的应用程序代码库、数据文件、用户账号详细信息、配置文件是极其重要的,以便在升级出错时,你可以总是可以还原到先前的版本。

步骤 2) 升级 Debian 9 现有的软件包

接下来的步骤是升级你所有现有的软件包,因为一些软件包被标志为保留不能升级,从 Debian 9 升级为 Debian 10 有失败或引发一些问题的可能性。所以,我们不冒任何风险,更好地升级软件包。使用下面的代码来升级软件包:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt update </span><span class="pun">&&</span><span class="pln"> </span><span class="kwd">sudo</span><span class="pln"> apt upgrade </span><span class="pun">-</span><span class="pln">y</span>

步骤 3) 修改软件包存储库文件 /etc/sources.list

接下来的步骤是修改软件包存储库文件 /etc/sources.list,你需要用文本 Buster 替换 Stretch

但是,在你更改任何东西前,确保如下创建一个 sources.list 文件的备份:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">cp</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="kwd">list</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="kwd">list</span><span class="pun">.</span><span class="pln">bak</span>

现在使用下面的 sed 命令来在软件包存储库文件中使用 Buster 替换 Stretch,示例如下显示:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">sed</span><span class="pln"> </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/stretch/buster/g'</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="kwd">list</span>
  2. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">sed</span><span class="pln"> </span><span class="pun">-</span><span class="pln">i </span><span class="str">'s/stretch/buster/g'</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="kwd">list</span><span class="pun">.</span><span class="pln">d</span><span class="com">/*.list</span>

更新后,你需要如下更新软件包存储库索引:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt update</span>

在开始升级你现有的 Debian 操作系统前,让我们使用下面的命令验证当前版本,

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">cat</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="com">/*-release</span>
  2. <span class="com">PRETTY_NAME="Debian GNU/Linux 9 (stretch)"</span>
  3. <span class="com">NAME="Debian GNU/Linux"</span>
  4. <span class="com">VERSION_ID="9"</span>
  5. <span class="com">VERSION="9 (stretch)"</span>
  6. <span class="com">ID=debian</span>
  7. <span class="com">HOME_URL="https://www.debian.org/"</span>
  8. <span class="com">SUPPORT_URL="https://www.debian.org/support"</span>
  9. <span class="com">BUG_REPORT_URL="https://bugs.debian.org/"</span>
  10. <span class="com">root@linuxtechi:~$</span>

步骤 4) 从 Debian 9 升级到 Debian 10

你做完所有的更改后,是时候从 Debian 9 升级到 Debian 10 了。但是在这之前,再次如下确保更新你的软件包:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt update </span><span class="pun">&&</span><span class="pln"> </span><span class="kwd">sudo</span><span class="pln"> apt upgrade </span><span class="pun">-</span><span class="pln">y</span>

在软件包升级期间,你将被提示启动服务,所以选择你较喜欢的选项。

一旦你系统的所有软件包升级完成,就升级你的发行版的软件包。使用下面的代码来升级发行版:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt dist</span><span class="pun">-</span><span class="pln">upgrade </span><span class="pun">-</span><span class="pln">y</span>

升级过程可能花费一些时间,取决于你的网络速度。记住在升级过程中,你将被询问一些问题,在软件包升级后是否需要重启服务、你是否需要保留现存的配置文件等。如果你不想进行一些自定义更改,简单地键入 “Y” ,来让升级过程继续。

步骤 5) 验证升级

一旦升级过程完成,重启你的机器,并使用下面的方法检测版本:

  1. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$ lsb_release </span><span class="pun">-</span><span class="pln">a</span>

如果你获得如下输出:

  1. <span class="typ">Distributor</span><span class="pln"> ID</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Debian</span>
  2. <span class="typ">Description</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Debian</span><span class="pln"> GNU</span><span class="pun">/</span><span class="typ">Linux</span><span class="pln"> </span><span class="lit">10</span><span class="pln"> </span><span class="pun">(</span><span class="pln">buster</span><span class="pun">)</span>
  3. <span class="typ">Release</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10</span>
  4. <span class="typ">Codename</span><span class="pun">:</span><span class="pln"> buster</span>
  5. <span class="pln">root@linuxtechi</span><span class="pun">:~</span><span class="pln">$</span>

是的,你已经成功地从 Debian 9 升级到 Debian 10。

验证升级的备用方法:

相关推荐