使用 Debian Snapshot 软件源回到过去

日期2024-06-03
#Linux
#Debian

Debian Snapshot外部链接 是 Debian 官方提供的时间机器,保留着 Debian 官方软件源的历史。最早的快照可以追溯到 2005 年外部链接 ,每天至少快照一次。

把它设置为 apt 源就能搭建过去的环境,非常适合做考古研究或者跑老软件。

TL;DR

  • 运行一个比快照的时间老的 debian 虚拟机 / docker 容器 / chroot / 随便什么别的东西
  • 在 sources.list 的 URL 前面加上 [check-valid-until=no]
  • 把 sources.list 的 URL 都改成 http://snapshot.debian.org/archive/debian/${时间戳},时间戳格式为 yyyymmddThhmmssZ 或 yyyymmdd
  • apt update && apt upgrade

sources.list 示例:

deb [check-valid-until=no] http://snapshot.debian.org/archive/debian/20191224T000000Z buster main
deb [check-valid-until=no] http://snapshot.debian.org/archive/debian-security/20191224T000000Z buster/updates main
deb [check-valid-until=no] http://snapshot.debian.org/archive/debian/20191224T000000Z buster-updates main

(上面的配置不适合特别特别古老的情况,请参考下文“使用 snapshot 源”)

基础知识

先来熟悉一下 sources.list 的语法。当然跳过也没关系

本节以下内容节选、参考了官方 wiki外部链接

sources.list 文件的每一条记录符合以下格式:

deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3

包的类型

每一行的第一个词(debdeb-src)指定包的类型。deb外部链接 表示事先编译好的二进制包,我们平时用的就是这个。deb-src 表示源码包外部链接 ,包含未经修改的源码外部链接 、Debian 控制文件(.dsc外部链接 )和 diff.gz(这个软件在 debian 上所需的补丁

仓库 URL

第二列是仓库外部链接 的 URL,软件包就是从这个 URL 下载的。Debian 仓库的镜像列表外部链接

发行版(distribution)

发行版字段可以填发行代号(stretch外部链接 buster外部链接 bullseye外部链接 bookworm外部链接 sid外部链接 )或发行类(oldoldstable外部链接 oldstable外部链接 stable外部链接 testing外部链接 unstable外部链接 。想保持跟进某个发行类就填发行类,想保持跟进某个大版本就填发行代号。最好避免使用发行类,否则容易在没有准备的情况下突然面临大版本更新,容易把系统搞坏。更新大版本应当是个谨慎、小心的过程,并且两年改一次配置文件也不是麻烦事。

例如,如果你想帮助测试 testing 版本,可以填 testing。如果你想一直用 trixie,从 testing 用到停止支持,就填 trixie。

组件(component)

main外部链接 由符合 Debian 自由软件指导方针(DFSG外部链接 )的包构成,并且这些包不依赖 main 以外的包。Debian 发行版只由这些包组成。

contrib外部链接 的包同样符合 DFSG,但是依赖不在 main 里的包(可能在 non-free 里

non-free外部链接 包含不符合 DFSG 的软件。

此外,Debian 近两年新增了 non-free-firmware 组件,可以让 bookworm 及以后的版本更方便地安装一些非自由的固件。

官方 sources.list 示例

Debian 12/Bookworm (stable)(2023 年 6 月 10 日发布)

deb http://deb.debian.org/debian bookworm main non-free-firmware
deb-src http://deb.debian.org/debian bookworm main non-free-firmware

deb http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main non-free-firmware

需要 contribnon-free 的话:

deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware

deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

更多示例请参考原文外部链接

使用 snapshot 源

本节内容节选、参考了官网外部链接

要使用过去某时刻的软件源,给你的 sources.list 添加如下代码:

deb     https://snapshot.debian.org/archive/debian/20091004T111800Z/ lenny main
deb-src https://snapshot.debian.org/archive/debian/20091004T111800Z/ lenny main
deb     https://snapshot.debian.org/archive/debian-security/20091004T121501Z/ lenny/updates main
deb-src https://snapshot.debian.org/archive/debian-security/20091004T121501Z/ lenny/updates main

要使用 https 的话,需要有 ca-certificates 包(当然直接用 http 也可以

要了解请求的快照是否存在(日期是否合法,用浏览器查看即可。合法的日期格式是 yyyymmddThhmmssZyyyymmdd。如果请求的时间戳没有快照,会返回时间戳之前的最新的一个快照。

不新的快照会导致 apt 报 Release file expired 的错误,可以参考下面的例子添加 [check-valid-until=no] 来解决。

如果你的环境特别特别老,apt 版本小于 1.1.exp9 的话,可以用 aptitude -o Acquire::Check-Valid-Until=false updateapt-get -o Acquire::Check-Valid-Until=false update 解决。

deb [check-valid-until=no] https://snapshot.debian.org/archive/debian/20091004T111800Z/ lenny main
deb-src [check-valid-until=no] https://snapshot.debian.org/archive/debian/20091004T111800Z/ lenny main
deb [check-valid-until=no] https://snapshot.debian.org/archive/debian-security/20091004T121501Z/ lenny/updates main
deb-src [check-valid-until=no] https://snapshot.debian.org/archive/debian-security/20091004T121501Z/ lenny/updates main

想查找某个包的历史信息的话,可以在官网外部链接 搜索包名,或者手动翻目录。

注意事项

  • Debian snapshots 没有镜像源,需要加速的话可以使用 apt-cacher-ng 在本地搭建缓存。另外最好避免直接把 snapshot 源写进 docker 镜像里,不要给 snapshot 太大的压力reddit 评论外部链接

  • 2019 年 9 月 4 日 ~ 8 日的数据丢了(官网的 News 栏有写

注意

你的浏览器版本较低,可能无法正常显示本站页面。