Cài đặt gói ở repo snapshot trên Debian

Trên Debian, khi cài đặt một gói cần thiết nào đó, ví dụ như linux-header cho Wireguard, có thể bạn sẽ nhận được thông báo lỗi tương tự như sau:

# apt install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.19.0-11-cloud-amd64
E: Couldn't find any package by glob 'linux-headers-4.19.0-11-cloud-amd64'
E: Couldn't find any package by regex 'linux-headers-4.19.0-11-cloud-amd64'

Không tìm thấy gói cài đặt!

Tuy nhiên, khi tìm kiếm ở trang snapshot của Debian thì gói cài đặt đó còn hiện hữu. Trong trường hợp này bạn có thể sử dụng lệnh wget để tải về và cài đặt thủ công bằng lệnh dpkg -i. Cách khác là bạn thêm repo snapshot vào file sourcelist để Debian tự tìm gói và cài đặt tự động. Việc cài đặt thủ công đôi lúc mất thời gian vì phải tìm và tải các gói phụ thuộc.

Bài viết này hướng dẫn bạn thiết lập tự động để Debian có thể lấy các gói đã được biên dịch sẵn và cài cho bản phân phối Debian tương ứng. Repo snapshot hiếm khi được nói đến nhưng bạn có thể sử dụng nó để tải và cài đặt các gói cài đặt cũ không còn được hỗ trợ nữa hoặc thậm chí các gói mới chưa ổn định trên bản Debian hiện tại.

Ngày tạo file snapshot

Nếu bạn muốn sử dụng file snapshot có trên hệ thống mới nhất được tạo ra trước ngày 2021-01-01, thì chỉ ghi đơn giản là 20210101

Chạy lệnh sau để thêm source list snapshot

nano /etc/apt/sources.list.d/snapshot.list

Thêm vào file nội dung sau

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

Không cập nhật chỉ mục gói lúc này (apt update) vì sẽ nhận được thông báo lỗi tương tự như sau:

# apt update
Hit:1 http://security.debian.org/debian-security buster/updates InRelease
Hit:2 http://deb.debian.org/debian buster InRelease
Hit:3 http://deb.debian.org/debian buster-updates InRelease
Hit:4 https://download.docker.com/linux/debian buster InRelease
Get:5 http://snapshot.debian.org/archive/debian/20210101 buster InRelease [121 kB]
Get:6 http://snapshot.debian.org/archive/debian/20210101 buster-updates InRelease [51.9 kB]
Get:7 http://snapshot.debian.org/archive/debian-security/20210101 buster/updates InRelease [65.4 kB]
Get:8 http://snapshot.debian.org/archive/debian/20210101 buster/main amd64 Packages [7,907 kB]
Get:9 http://snapshot.debian.org/archive/debian/20210101 buster/main Translation-en [5,971 kB]
Reading package lists... Done
E: Release file for http://snapshot.debian.org/archive/debian/20210101/dists/buster-updates/InRelease is expired (invalid since 94d 18h 52min 21s). Updates for this repository will not be applied.
E: Release file for http://snapshot.debian.org/archive/debian-security/20210101/dists/buster/updates/InRelease is expired (invalid since 94d 23h 27min 20s). Updates for this repository will not be applied.

Do đó cần thực hiện lệnh sau để tránh báo lỗi:

apt -o Acquire::Check-Valid-Until=false update

Thông tin các gói cài đặt

Bạn có thể chỉ rõ bản snapshot mong muốn chính xác bằng cách cung cấp giá trị giờ, phút và giây. Ví dụ 20170101T153528Z sẽ trả về bản snapshot được tạo tại thời điểm 2017-01-01 15:35:28

deb http://snapshot.debian.org/archive/debian/20170609T034604Z stretch main
deb http://snapshot.debian.org/archive/debian/20170609T034604Z stretch-updates main
deb http://snapshot.debian.org/archive/debian-security/20170920T221221Z stretch/updates main

Bạn có thể vào trang https://snapshot.debian.org/ để tìm kiếm các gói build sẵn (binary file) trỏ chuột vào file để xem thời gian snapshot chính xác của file đó.

Tham khảo: