降级 Debian 系统
2019-08-24 17:50 linux
之前 NAS 服务器用的是 unstable
版的 debian 系统, 最近系统频繁更新, 比较麻烦,
正好 debian 10 - buster
也发正式版了, 就想着换成这个版本.
但是现在服务器上面跑着好几个服务, 不打算重新装系统, 就尝试着把 unstable
版本
降级为 buster
这个 stable
版.
更改 apt 源
之前的源列表是:
deb http://mirrors.ustc.edu.cn/debian sid main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian sid main contrib non-free
deb http://mirrors.huaweicloud.com/debian sid main contrib non-free
deb-src http://mirrors.huaweicloud.com/debian sid main contrib non-free
更改为 buster 正式版的源:
deb http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb http://mirrors.huaweicloud.com/debian buster main contrib non-free
deb-src http://mirrors.huaweicloud.com/debian buster main contrib non-free
然后 apt update
更新一下包索引.
国为 unstable 版包含了更新的软件包版本, 把源更改为 buster 之后, 是没有包可更新的. 接下来就需要手动降级了.
批量降级 apt 包
使用 apt-cache
命令可以查看一下包的所有可用的版本的信息:
$ apt-cache policy nginx
nginx:
Installed: 1.14.2-2
Candidate: 1.14.2-2
Version table:
*** 1.14.2-2 500
500 http://mirrors.ustc.edu.cn/debian buster/main amd64 Packages
500 http://mirrors.huaweicloud.com/debian buster/main amd64 Packages
100 /var/lib/dpkg/status
以上列出了 nginx
包, 本地安装的与源仓库中提供的版本是一至的.
如果是可降级的包, 显示的是这样的:
$ apt-cache policy docker-ce
docker-ce:
Installed: 5:18.09.8~3-0~debian-stretch
Candidate: 5:19.03.1~3-0~debian-stretch
Version table:
*** 5:19.03.1~3-0~debian-stretch 500
100 /var/lib/dpkg/status
5:19.03.0~3-0~debian-stretch 500
500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
5:18.09.8~3-0~debian-stretch 500
500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
5:18.09.7~3-0~debian-stretch 500
以上显示 docker-ce
这个包可以降级的几个版本.
如果要安装指定版本的包, 只需要这样:
$ sudo apt install docker-ce=5:19.03.1~3-0~debian-stretch
基于此, 使用以下的 python 代码, 可以生成系统中所有可降级的包及其版本号:
#!/usr/bin/env python3
# Downgrade apt packages
import os
import sys
import subprocess
def list_installed_pkgs():
output = subprocess.getoutput("dpkg -l | grep '^ii' | awk '{print $2}'")
return output.split("\n")
def filter_downgrade_pkg(pkg):
output = subprocess.getoutput("apt-cache policy %s" % pkg)
downgrade = False
for line in output.split("\n"):
if "/var/lib/dpkg/status" in line:
downgrade = True
elif downgrade:
parts = line.strip().split(" ")
return parts[0]
return ""
def main():
installed_pkgs = list_installed_pkgs()
print("sudo aptitude install", end=" ")
for pkg in installed_pkgs:
out = filter_downgrade_pkg(pkg)
if out:
print("%s=%s" % (pkg, out), end=" ")
if __name__ == "__main__":
main()
抓取到的系统中可降级的包有这样:
apparmor 2.13.2-10
aria2 1.34.0-4
base-files 10.3
bash-completion 1:2.8-6
bind9-host 1:9.11.5.P4+dfsg-5.1
binutils 2.31.1-16
binutils-common:amd64 2.31.1-16
binutils-x86-64-linux-gnu 2.31.1-16
bsdutils 1:2.33.1-0.1
bzip2 1.0.6-9.1
coreutils 8.30-3
curl 7.64.0-4
dash 0.5.10.2-5
debconf 1.5.71
debconf-i18n 1.5.71
debianutils 4.8.6.1
dh-python 3.20190308
dirmngr 2.2.12-1
dmidecode 3.2-1
dns-root-data 2019031302
dnsutils 1:9.11.5.P4+dfsg-5.1
e2fslibs:amd64 1.44.5-1
e2fsprogs 1.44.5-1
e2fsprogs-l10n 1.44.5-1
exim4-base 4.92-8
exim4-config 4.92-8
exim4-daemon-light 4.92-8
fdisk 2.33.1-0.1
file 1:5.35-4
findutils 4.6.0+git+20190209-2
firmware-amd-graphics 20190114-1
firmware-linux 20190114-1
firmware-linux-nonfree 20190114-1
firmware-misc-nonfree 20190114-1
firmware-realtek 20190114-1
geoip-database 20181108-1
ghostscript 9.27~dfsg-2
git 1:2.20.1-2
git-lfs 2.7.1-1+b1
git-man 1:2.20.1-2
gnupg 2.2.12-1
gnupg-l10n 2.2.12-1
gnupg-utils 2.2.12-1
golang-docker-credential-helpers 0.6.1-2
gpg 2.2.12-1
gpg-agent 2.2.12-1
gpg-wks-client 2.2.12-1
gpg-wks-server 2.2.12-1
gpgconf 2.2.12-1
gpgsm 2.2.12-1
gpgv 2.2.12-1
grub-common 2.02+dfsg1-20
grub-pc 2.02+dfsg1-20
grub-pc-bin 2.02+dfsg1-20
grub2 2.02+dfsg1-20
grub2-common 2.02+dfsg1-20
guile-2.2-libs:amd64 2.2.4+1-2
htop 2.2.0-1+b1
ibverbs-providers:amd64 22.1-1
ifupdown 0.8.35
init 1.56+nmu1
init-system-helpers 1.56+nmu1
initramfs-tools 0.133
initramfs-tools-core 0.133
install-info 6.5.0.dfsg.1-4+b1
iproute2 4.20.0-2
iptables 1.8.2-4
iputils-ping 3:20180629-2
krb5-locales 1.17-3
libapparmor1:amd64 2.13.2-10
libapt-inst2.0:amd64 1.8.2
libapt-pkg-perl 0.1.34+b1
libapt-pkg5.0:amd64 1.8.2
libaria2-0:amd64 1.34.0-4
libassuan0:amd64 2.5.2-1
libaudit-common 1:2.8.4-3
libaudit1:amd64 1:2.8.4-3
libbind9-161:amd64 1:9.11.5.P4+dfsg-5.1
libbinutils:amd64 2.31.1-16
libblkid1:amd64 2.33.1-0.1
libbloom1:amd64 1.5-5
libbluetooth3:amd64 5.50-1
libbsd0:amd64 0.9.1-2
libbz2-1.0:amd64 1.0.6-9.1
libc-ares2:amd64 1.14.0-1
libcap-ng0:amd64 0.7.9-2
libcgi-fast-perl 1:2.13-1
libcgi-pm-perl 4.40-1
libcom-err2:amd64 1.44.5-1
libcomerr2:amd64 1.44.5-1
libcryptsetup12:amd64 2:2.1.0-5
libcups2:amd64 2.2.10-6
libcupsfilters1:amd64 1.21.6-5
libcupsimage2:amd64 2.2.10-6
libcurl3-gnutls:amd64 7.64.0-4
libcurl4:amd64 7.64.0-4
libdb5.3:amd64 5.3.28+dfsg1-0.5
libdns-export1104 1:9.11.5.P4+dfsg-5.1
libdns1104:amd64 1:9.11.5.P4+dfsg-5.1
libedit2:amd64 3.1-20181209-1
libestr0:amd64 0.1.10-2.1
libev4:amd64 1:4.25-1
libexpat1:amd64 2.2.6-2
libexpat1-dev:amd64 2.2.6-2
libext2fs2:amd64 1.44.5-1
libfdisk1:amd64 2.33.1-0.1
libfreetype6:amd64 2.9.1-3
libfstrm0:amd64 0.4.0-1
libgdbm-compat4:amd64 1.18.1-4
libgdbm6:amd64 1.18.1-4
libgeoip1:amd64 1.6.12-1
libglib2.0-0:amd64 2.58.3-2
libglib2.0-data 2.58.3-2
libgnutls-dane0:amd64 3.6.7-4
libgnutls30:amd64 3.6.7-4
libgpg-error-l10n 1.35-1
libgpg-error0:amd64 1.35-1
libgpm2:amd64 1.20.7-5
libgs9:amd64 9.27~dfsg-2
libgs9-common 9.27~dfsg-2
libgsasl7:amd64 1.8.0-8+b2
libgssapi-krb5-2:amd64 1.17-3
libhogweed4:amd64 3.4.1-1
libibverbs1:amd64 22.1-1
libicu63:amd64 63.1-6
libidn2-0:amd64 2.0.5-1
libinnodb3 1.0.6.6750-1
libiptc0:amd64 1.8.2-4
libirs161:amd64 1:9.11.5.P4+dfsg-5.1
libisc-export1100:amd64 1:9.11.5.P4+dfsg-5.1
libisc1100:amd64 1:9.11.5.P4+dfsg-5.1
libisccc161:amd64 1:9.11.5.P4+dfsg-5.1
libisccfg163:amd64 1:9.11.5.P4+dfsg-5.1
libk5crypto3:amd64 1.17-3
libkrb5-3:amd64 1.17-3
libkrb5support0:amd64 1.17-3
liblcms2-2:amd64 2.9-3
libldap-2.4-2:amd64 2.4.47+dfsg-3
libldap-common 2.4.47+dfsg-3
libldb1:amd64 2:1.5.1+really1.4.6-3
liblognorm5:amd64 2.0.5-1
libltdl7:amd64 2.4.6-9
liblwp-mediatypes-perl 6.02-1
liblwres161:amd64 1:9.11.5.P4+dfsg-5.1
libmagic-mgc 1:5.35-4
libmagic1:amd64 1:5.35-4
libmariadb3:amd64 1:10.3.15-1
libmbedcrypto3:amd64 2.16.0-1
libmbim-glib4:amd64 1.18.0-1
libmbim-proxy 1.18.0-1
libmm-glib0:amd64 1.10.0-1
libmnl0:amd64 1.0.4-2
libmount1:amd64 2.33.1-0.1
libncurses5:amd64 6.1+20181013-2
libncurses6:amd64 6.1+20181013-2
libncursesw5:amd64 6.1+20181013-2
libncursesw6:amd64 6.1+20181013-2
libnetfilter-conntrack3:amd64 1.0.7-1
libnettle6:amd64 3.4.1-1
libnewt0.52:amd64 0.52.20-8
libnftnl11:amd64 1.1.2-2
libnghttp2-14:amd64 1.36.0-2
libnl-3-200:amd64 3.4.0-1
libnl-genl-3-200:amd64 3.4.0-1
libnl-route-3-200:amd64 3.4.0-1
libnm0:amd64 1.14.6-2
libnspr4:amd64 2:4.20-1
libnss-systemd:amd64 241-5
libnss3:amd64 2:3.42.1-1
libntlm0:amd64 1.5-1
libnvpair1linux 0.7.12-2+deb10u1
libp11-kit0:amd64 0.23.15-2
libpam-systemd:amd64 241-5
libpaper-utils 1.1.28
libpaper1:amd64 1.1.28
libparted2:amd64 3.2-25
libpcap0.8:amd64 1.8.1-6
libpcre2-8-0:amd64 10.32-5
libpcre3:amd64 2:8.39-12
libpcsclite1:amd64 1.8.24-1
libpng16-16:amd64 1.6.36-6
libproc-processtable-perl 0.56-1
libprocps7:amd64 2:3.3.15-2
libproxychains4:amd64 4.13-4
libpython2.7:amd64 2.7.16-2
libpython2.7-minimal:amd64 2.7.16-2
libpython2.7-stdlib:amd64 2.7.16-2
libpython3.7:amd64 3.7.3-2
libpython3.7-dev:amd64 3.7.3-2
libpython3.7-minimal:amd64 3.7.3-2
libpython3.7-stdlib:amd64 3.7.3-2
libqmi-glib5:amd64 1.22.0-1.2
libqmi-proxy 1.22.0-1.2
libseccomp2:amd64 2.3.3-4
libselinux1:amd64 2.8-1+b1
libsemanage-common 2.8-2
libsemanage1:amd64 2.8-2
libsepol1:amd64 2.8-1
libslang2:amd64 2.3.2-2
libsmartcols1:amd64 2.33.1-0.1
libsodium23:amd64 1.0.17-1
libsqlite3-0:amd64 3.27.2-3
libss2:amd64 1.44.5-1
libsystemd0:amd64 241-5
libtasn1-6:amd64 4.13-3
libteamdctl0:amd64 1.28-1
libtevent0:amd64 0.9.37-1
libtext-charwidth-perl 0.04-7.1+b1
libtext-iconv-perl 1.7-5+b7
libtext-wrapi18n-perl 0.06-7.1
libtiff5:amd64 4.0.10-4
libtinfo5:amd64 6.1+20181013-2
libtinfo6:amd64 6.1+20181013-2
libudev1:amd64 241-5
libunistring2:amd64 0.9.10-1
libutempter0:amd64 1.1.6-3
libuuid1:amd64 2.33.1-0.1
libuutil1linux 0.7.12-2+deb10u1
libwbclient0:amd64 2:4.9.5+dfsg-5
libwebp6:amd64 0.6.1-2
libxtables12:amd64 1.8.2-4
libzfs2linux 0.7.12-2+deb10u1
libzpool2linux 0.7.12-2+deb10u1
libzstd1:amd64 1.3.8+dfsg-3
linux-libc-dev:amd64 4.19.37-5
login 1:4.5-1.1
lsb-base 10.2019051400
lsof 4.91+dfsg-1
mailutils 1:3.5-3
mailutils-common 1:3.5-3
man-db 2.8.5-2
manpages 4.16-2
manpages-dev 4.16-2
mariadb-common 1:10.3.15-1
mime-support 3.62
modemmanager 1.10.0-1
mount 2.33.1-0.1
nano 3.2-3
ncurses-base 6.1+20181013-2
ncurses-bin 6.1+20181013-2
ncurses-term 6.1+20181013-2
network-manager 1.14.6-2
nftables 0.9.0-2
p7zip 16.02+dfsg-6
p7zip-full 16.02+dfsg-6
parted 3.2-25
passwd 1:4.5-1.1
patch 2.7.6-3
pigz 2.4-1
pinentry-curses 1.1.0-2
powermgmt-base 1.34
procps 2:3.3.15-2
proxychains4 4.13-4
psmisc 23.2-1
python-cffi-backend 1.12.2-1
python-crypto 2.6.1-9+b1
python-ldb 2:1.5.1+really1.4.6-3
python-samba 2:4.9.5+dfsg-5
python2.7 2.7.16-2
python2.7-minimal 2.7.16-2
python3-cffi-backend 1.12.2-1
python3-chardet 3.0.4-3
python3-configargparse 0.13.0-1
python3-crypto 2.6.1-9+b1
python3-distutils 3.7.3-1
python3-dockerpty 0.4.1-1
python3-gi 3.30.4-1
python3-idna 2.6-1
python3-josepy 1.1.0-2
python3-lib2to3 3.7.3-1
python3-pkg-resources 40.8.0-1
python3-setuptools 40.8.0-1
python3-yaml 3.13-2
python3.7 3.7.3-2
python3.7-dev 3.7.3-2
python3.7-minimal 3.7.3-2
readline-common 7.0-5
s-nail 14.9.11-2
samba-common 2:4.9.5+dfsg-5
samba-common-bin 2:4.9.5+dfsg-5
samba-dsdb-modules:amd64 2:4.9.5+dfsg-5
samba-libs:amd64 2:4.9.5+dfsg-5
shadowsocks-libev 3.2.5+ds-1
sqlite3 3.27.2-3
sudo 1.8.27-1
systemd 241-5
systemd-cron 1.5.14-2
systemd-sysv 241-5
sysvinit-utils 2.93-8
tar 1.30+dfsg-6
tasksel 3.53
tasksel-data 3.53
tig 2.4.1-1
tini 0.18.0-1
tmux 2.8-3
tree 1.8.0-1
tzdata 2019a-1
udev 241-5
usb.ids 2019.04.23-1
usbutils 1:010-3
util-linux 2.33.1-0.1
uuid-runtime 2.33.1-0.1
w3m 0.5.3-37
wget 1.20.1-1.1
whiptail 0.52.20-8
wpasupplicant 2:2.7+git20190128+0c1e29f-6
xfsprogs 4.20.0-1
zfsutils-linux 0.7.12-2+deb10u1
zlib1g:amd64 1:1.2.11.dfsg-1
zlib1g-dev:amd64 1:1.2.11.dfsg-1
之后使用 apt
命令安装一下即可.
The following packages will be DOWNGRADED:
apparmor aria2 base-files bash-completion bind9-host binutils binutils-common binutils-x86-64-linux-gnu bsdutils bzip2 coreutils curl dash debconf debconf-i18n debianutils dh-python dirmngr dmidecode dns-root-data dnsutils e2fslibs e2fsprogs
e2fsprogs-l10n exim4-base exim4-config exim4-daemon-light fdisk file findutils firmware-amd-graphics firmware-linux firmware-linux-nonfree firmware-misc-nonfree firmware-realtek geoip-database ghostscript git git-lfs git-man gnupg gnupg-l10n
gnupg-utils golang-docker-credential-helpers gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv grub-common grub-pc grub-pc-bin grub2 grub2-common guile-2.2-libs htop ibverbs-providers ifupdown init init-system-helpers initramfs-tools
initramfs-tools-core install-info iproute2 iptables iputils-ping krb5-locales libapparmor1 libapt-inst2.0 libapt-pkg-perl libapt-pkg5.0 libaria2-0 libassuan0 libaudit-common libaudit1 libbind9-161 libbinutils libblkid1 libbloom1 libbluetooth3
libbsd0 libbz2-1.0 libc-ares2 libcap-ng0 libcgi-fast-perl libcgi-pm-perl libcom-err2 libcomerr2 libcryptsetup12 libcups2 libcupsfilters1 libcupsimage2 libcurl3-gnutls libcurl4 libdb5.3 libdns-export1104 libdns1104 libedit2 libestr0 libev4
libexpat1 libexpat1-dev libext2fs2 libfdisk1 libfreetype6 libfstrm0 libgdbm-compat4 libgdbm6 libgeoip1 libglib2.0-0 libglib2.0-data libgnutls-dane0 libgnutls30 libgpg-error-l10n libgpg-error0 libgpm2 libgs9 libgs9-common libgsasl7 libgssapi-krb5-2
libhogweed4 libibverbs1 libicu63 libidn2-0 libinnodb3 libiptc0 libirs161 libisc-export1100 libisc1100 libisccc161 libisccfg163 libk5crypto3 libkrb5-3 libkrb5support0 liblcms2-2 libldap-2.4-2 libldap-common libldb1 liblognorm5 libltdl7
liblwp-mediatypes-perl liblwres161 libmagic-mgc libmagic1 libmariadb3 libmbedcrypto3 libmbim-glib4 libmbim-proxy libmm-glib0 libmnl0 libmount1 libncurses5 libncurses6 libncursesw5 libncursesw6 libnetfilter-conntrack3 libnettle6 libnewt0.52
libnftnl11 libnghttp2-14 libnl-3-200 libnl-genl-3-200 libnl-route-3-200 libnm0 libnspr4 libnss-systemd libnss3 libntlm0 libnvpair1linux libp11-kit0 libpam-systemd libpaper-utils libpaper1 libparted2 libpcap0.8 libpcre2-8-0 libpcre3 libpcsclite1
libpng16-16 libproc-processtable-perl libprocps7 libproxychains4 libpython2.7 libpython2.7-minimal libpython2.7-stdlib libpython3.7 libpython3.7-dev libpython3.7-minimal libpython3.7-stdlib libqmi-glib5 libqmi-proxy libseccomp2 libselinux1
libsemanage-common libsemanage1 libsepol1 libslang2 libsmartcols1 libsodium23 libsqlite3-0 libss2 libsystemd0 libtasn1-6 libteamdctl0 libtevent0 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl libtiff5 libtinfo5 libtinfo6 libudev1
libunistring2 libutempter0 libuuid1 libuutil1linux libwbclient0 libwebp6 libxtables12 libzfs2linux libzpool2linux libzstd1 linux-libc-dev login lsb-base lsof mailutils mailutils-common man-db manpages manpages-dev mariadb-common mime-support
modemmanager mount nano ncurses-base ncurses-bin ncurses-term network-manager nftables p7zip p7zip-full parted passwd patch pigz pinentry-curses powermgmt-base procps proxychains4 psmisc python-cffi-backend python-crypto python-ldb python-samba
python2.7 python2.7-minimal python3-cffi-backend python3-chardet python3-configargparse python3-crypto python3-distutils python3-dockerpty python3-gi python3-idna python3-josepy python3-lib2to3 python3-pkg-resources python3-setuptools python3-yaml
python3.7 python3.7-dev python3.7-minimal readline-common s-nail samba-common samba-common-bin samba-dsdb-modules samba-libs shadowsocks-libev sqlite3 sudo systemd systemd-cron systemd-sysv sysvinit-utils tar tasksel tasksel-data tig tini tmux
tree tzdata udev usb.ids usbutils util-linux uuid-runtime w3m wget whiptail wpasupplicant xfsprogs zfsutils-linux zlib1g zlib1g-dev
The following NEW packages will be installed:
gsfonts{a} libmailutils5{a} libnftables0{a}
The following packages will be REMOVED:
fonts-urw-base35{u} libip4tc2{u} libip6tc2{u} libjson-c4{u} libmailutils6{u} libnftables1{u} libreadline8{u} logsave{u}
The following packages are RECOMMENDED but will NOT be installed:
要注意的是, 安装期间有些包会提示更改配置, 像这样:
Configuration file '/etc/nanorc'
==> 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.
*** nanorc (Y/I/N/O/D/Z) [default=N] ? y
如果配置文件是自己改动过的, 可以选 N
, 如果没修改过可以选 Y
.
降级内核
降级内核的话, 需要记得的是, 要确认 grub.cfg
里面的默认启动项指向的是低版本的内核.
因为服务器并没有启动界面可以选 grub 的启动项.
使用低版本内核重启系统后, 记得清理掉高版本的旧内核及其他模块.