Debian 8 Jessie 升级至 Debian 9 Stretch 教程

By | 2020年12月12日

Debian 9 Stretch 已经在 2017 年 6 月 17 号发布,而很多商家的步伐并未那么快,比如某千万云,所以我们可以选择自己升级

本教程会指导你如何在 Debian 8 Jessie 的机器上快速升级到 Debian 9 Stretch

以下安装步骤都在 root 用户下完成,请自行使用 su 命令切换到 root 用户

此教程仅适用于 KVM、Xen 等可以更换内核的虚拟环境或独立服务器,OpenVZ 等无法更换内核的环境是不能升级的

1、备份数据

如果你的机器不是新开的,上面跑了一些服务,那么强烈建议备份好数据,我们推荐你备份所有的软件配置和数据库,因为升级以后,大部分软件都会更新版本,一部分软件甚至是无法滚回的,比如 Mariadb 会升级到 10.1,如果你不备份,而你的数据库没法在新的系统上运行,那么损失就大了

以下内容你可以根据自己的需求来备份

  1. 服务器上应用的源代码,比如 WordPress
  2. 数据库,比如 MySQL, SQLite3, Postgres
  3. 配置文件,比如 Nginx, Apache, DNS, PHP
  4. 邮件和账号
  5. 系统添加的用户和 SSH Key

当然,新开的机器的话,别废话,直接看下面的步骤

2、更新系统

首先检查你当前的系统版本

root@debian ~ # lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 8.8 (jessie)
Release:	8.8
Codename:	jessie

然后按照以下顺序更新系统

apt-get update
apt-get upgrade
apt-get dist-upgrade

建议重启一次

3、替换 sources.list 源文件

Debian 8 代号 Jessie ,我们需要替换 /etc/apt/sources.list 里的源为 Debian 9 的代号 Stretch 或 Stable

备份一下原来的文件

cp -r /etc/apt/sources.list /etc/apt/sources.list.old

然后直接替换

sed -i 's/jessie/stretch/g' /etc/apt/sources.list

当然也可以替换为 stable ,但是我们并不建议这么做,因为未来 Debian 10 成为 stable 版的时候也会自动升级从而可能造成错误

注意的是,如果你的系统带有 /etc/apt/sources.list.d/*.list 文件,也就是某些软件会单独在这个目录下生成 .list 文件,那么也记得对应修改,修改前请先去官网查看是否有 Debian 9 Stretch 版本,没有的话升级就会失败

替换后,你的 /etc/apt/sources.list 文件就会像这个样子

deb http://deb.debian.org/debian/ stretch main
deb-src http://deb.debian.org/debian/ stretch main

deb http://security.debian.org/debian-security/ stretch/updates main
deb-src http://security.debian.org/debian-security/ stretch/updates main

deb http://deb.debian.org/debian/ stretch-updates main
deb-src http://deb.debian.org/debian/ stretch-updates main

4、更新系统

还是老步骤,建议一步一步来

apt-get update
apt-get upgrade

5、升级系统

更新完系统之后,就可以直接升级了

apt-get dist-upgrade

升级过程中会让你选择是否保留旧的配置文件,这个就取决于自行选择,如果出现一长串软件版本更新、CA 证书更新的文本,可以按 q 跳过查看

6、重启并验证系统

全部更新完毕,直接重启系统

reboot

如果不出意外,重启后进入服务器并验证系统

root@debian ~ # lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.0 (stretch)
Release:	9.0
Codename:	stretch

再次提醒,升级系统是个大工程,如在生产环境下进行请务必务必务必备份好数据,如果没备份就直接升级,那么后果自负

2 thoughts on “Debian 8 Jessie 升级至 Debian 9 Stretch 教程

  1. junchol Post author

    为了一些工作原因需要升级 Linux kernel 到 5 及其以上版本进行一些调试,大部分默认的开发机系统为 Debian 9,于是花了几个小时对系统进行了升级。

    Debian 9 Stretch 升级 Debian 10 Buster

    准备阶段

    先检查冲突:

    sudo apt-mark showhold
    

    正常返回为空,如果存在冲突则按以下方式删除:

    sudo apt-mark unhold package_name
    

    简单执行一下 sudo apt update 看看有没有类似以下的报错:

    the package XXXXXX needs to be reinstalled but I can't find an archive for it.
    

    若有报错,则备份 /var/lib/dpkg/status 后,通过修改该文件,删除相关的 Package 段。

    排除冲突和错误后,稳妥起见,可以刷新一次索引:

    sudo apt update
    sudo apt upgrade
    sudo apt full-upgrade
    sudo apt autoremove
    

    升级

    修改 sources.list 文件:

    sudo vim /etc/apt/sources.list
    

    sources.list:

    deb http://deb.debian.org/debian buster main
    deb http://deb.debian.org/debian buster-updates main
    deb http://security.debian.org/debian-security buster/updates main
    

    随后进行更新升级:

    sudo apt update
    sudo apt upgrade
    sudo apt full-upgrade
    sudo apt autoremove
    

    完成通过 sudo reboot 重启系统,通过 lsb_release -a 检查版本。确认升级成功后进行内核升级

    Linux 内核升级

    配置和检索

    修改 sources.list 文件,更新和使用 buster-backports:

    sudo vim /etc/apt/sources.list.d/backports.list
    

    backports.list

    deb http://http.debian.net/debian buster-backports main
    deb-src http://http.debian.net/debian buster-backports main
    

    刷新索引:

    sudo apt update
    sudo apt upgrade
    

    随后搜索可用的 linux image,找到类似以下字样。

    sudo apt search linux-image-
    

    其中 amd64 可能会有差别,有些情况下会包含 cloud- 前缀,now 之后的当前版本也可能有差别,但是注意:amd64 之类的平台描述之后应该没有 -dbg 标志,名称中也不应该制定类似 5.2.0-0.bpo3 之类的特定版本信息(除非需要安装指定版本 release,并不再升级)。

    linux-image-amd64/buster-backports,now 5.2+107~bpo10+1 amd64
    

    类似的,搜索 linux headers。建议安装,header 都用不到可能没有不得不升级系统的必要吧(笑

    sudo apt search linux-headers-
    

    同样,应该包含类似这样的结果:

    linux-headers-amd64/buster-backports,now 5.2+107~bpo10+1 amd64
    

    升级

    升级内核:

    sudo apt install -t buster-backports linux-image-amd64
    sudo apt install -t buster-backports linux-headers-amd64
    sudo update-grub
    

    grub 更新结果应该类似如下,可能有多余的版本,5.x.x 的版本号也可能不同:

    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-5.2.0-0.bpo.3-amd64
    Found initrd image: /boot/initrd.img-5.2.0-0.bpo.3-amd64
    done
    

    随后 sudo reboot 重启即可。

    垃圾清理

    重启进入系统后,通过 uname -r 检查内核版本。确认升级成功后进行清理工作。

    多余的 image 和 headers

    sudo apt list|grep installed|grep -v automatic|grep linux-image-
    sudo apt list|grep installed|grep -v automatic|grep linux-headers-
    

    手动记录下 除了刚刚安装的内核版本之外 ,旧版本的 image 和 headers。

    清理

    通过以下命令将上一步记录的结果清理掉:

    
    sudo apt purge linux-xxxxxxxx
    

    继续清理:

    sudo apt clean
    sudo apt autoremove
    

    至此,优雅的完成升级。

    Reference

    Reply
  2. junchol

    简单几步把debian 9升级到debian 10 2019年11月1日00:11:48 18 6,170

    最近在用pacificrack的时候发现其后台只有debian 9,而debian 10发布之后很多新东西都很方便,对于debian\centos这样的Linux发型版本,如果我们不是有特殊的需求的情况下还是尽量追新吧。站长最近也打算抛弃ubuntu回归debian了。

    不废话了:

    更新

    apt-get update && apt-get upgrade

    备份一份

    cp /etc/apt/sources.list /etc/apt/sources.list.orig

    将/etc/apt/sources.list里所有“stretch”替换为“buster”

    sed -i ‘s/stretch/buster/g’ /etc/apt/sources.list

    再更新一下

    apt-get update && apt-get upgrade

    执行升级命令

    apt-get dist-upgrade

    提示完成后重启

    reboot

    查看下当前debian版本

    lsb_release -a

    Reply

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注