如何在基于ssh的会话上使用命令行从Debian Linux 8 Jessie升级到Debian 9 Stretch

时间:2020-01-09 10:39:48  来源:igfitidea点击:

如何在基于ssh的会话上使用命令行将我的Debian 8(Jessie)系统升级到Debian 9(Stretch)?
可以使用ssh从Debian 8升级到Debian 9。
本教程显示了如何使用命令行从Debian 8 Jessie Linux升级到Debian 9 Stretch。
请注意,Debian 9进行了重大更改,升级可能会失败,包括由于数据格式更改而可能导致数据损坏。

步骤1:备份服务器上的所有重要数据

进行备份(我正在使用Rsnapshot),在执行此备份之前,对它进行系统备份有多么重要,这一点已经足够强调了。
本教程中列出的大多数操作是在假设它们将由运行bash或任何其他现代shell的root用户执行的前提下编写的。
执行以下命令以查看当前版本:

$ uname -mrs

输出示例:

Linux 3.16.0-4-amd64 x86_64

或者

$ lsb_release -a

输出示例:

No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 8.8 (jessie)
Release:	8.8
Codename:	jessie

步骤2:修补现有系统

执行以下apt-get命令/apt命令:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade

或者

$ sudo apt update
$ sudo apt upgrade
$ sudo apt dist-upgrade

如果内核或其他库正在更新,请重新引导系统,运行:

$ sudo reboot

步骤3:更新/etc/apt/sources.list文件

同样,在执行以下任何命令之前,请先阅读此页。
这是我的默认/etc/apt/sources.list

$ cat /etc/apt/sources.list

输出示例:

deb http://httpredir.debian.org/debian          jessie   main contrib
deb http://security.debian.org/ jessie/updates main

使用文本编辑器(例如joe命令/vi命令)以如下方式更新文件(将jessie替换为Stretch):

$ sudo vi /etc/apt/sources.list

输出示例:

deb http://httpredir.debian.org/debian          stretch  main contrib 
deb http://security.debian.org/ stretch/updates main

保存并关闭文件。
要更新可用软件包的列表以进行拉伸,请运行:

$ sudo apt-get update

输出示例:

Get:1 http://mirrors.kernel.org stretch InRelease [195 kB]
Get:2 http://security.debian.org stretch/updates InRelease [62.9 kB]              
Get:3 http://security.debian.org stretch/updates/main amd64 Packages [1,404 B]    
Get:4 http://security.debian.org stretch/updates/main Translation-en [1,767 B]
Get:5 http://mirrors.kernel.org stretch/contrib Translation-en [45.9 kB]
Get:6 http://mirrors.kernel.org stretch/main Translation-en [5,392 kB]
Get:7 http://mirrors.kernel.org stretch/main amd64 Packages [7,095 kB]
Get:8 http://mirrors.kernel.org stretch/contrib amd64 Packages [50.9 kB]
Fetched 12.8 MB in 6s (2,129 kB/s)                                                                                                                                          
Reading package lists... Done
Building dependency tree       
Reading state information... Done

查看升级所需的磁盘空间:

$ sudo apt-get -o APT::Get::Trivial-Only=true dist-upgrade

输出示例:

....
  sysv-rc sysvinit-utils tar task-english task-ssh-server tasksel tasksel-data tcpd telnet texinfo time traceroute tzdata ucf udev util-linux util-linux-locales vim
  vim-common vim-runtime vim-tiny w3m wget whiptail whois xauth xdg-user-dirs xkb-data xml-core xz-utils zlib1g
398 upgraded, 139 newly installed, 3 to remove and 0 not upgraded.
Need to get 213 MB of archives.
After this operation, 335 MB of additional disk space will be used.
E: Trivial Only specified but this is not a trivial operation.

使用NA命令查看可用磁盘空间:

$ df -H

输出示例:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda         21G  1.1G   19G   6% /
udev             11M     0   11M   0% /dev
tmpfs           210M  4.5M  206M   3% /run
tmpfs           525M     0  525M   0% /dev/shm
tmpfs           5.3M     0  5.3M   0% /run/lock
tmpfs           525M     0  525M   0% /sys/fs/cgroup

通过安装/升级软件包来升级系统:

$ sudo apt-get upgrade

输出示例:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
  docutils-common docutils-doc libasprintf0c2 liblcms2-2 libpaper-utils libpaper1 libperl4-corelibs-perl libuuid-perl libwebp5 libwebpdemux1 libwebpmux1 python-docutils
  python-pil python-pygments python-roman
Use 'apt-get autoremove' to remove them.
Done
The following packages have been kept back:
  apt apt-listchanges apt-utils aptitude aptitude-common bc bind9-host curl dbus dmsetup dnsutils eject exim4 exim4-base exim4-config exim4-daemon-light file ftp gnupg
  gnupg-agent gnupg2 ifupdown init init-system-helpers initramfs-tools initscripts iotop iproute2 iptables iputils-ping isc-dhcp-client isc-dhcp-common
  libarchive-extract-perl libavahi-client3 libc-bin libc6 libcairo2 libclass-c3-xs-perl libcpan-meta-perl libcryptsetup4 libcups2 libcurl3 libcurl3-gnutls libdbus-1-3
  libdevmapper1.02.1 libfcgi-perl libfreetype6 libgcc1 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgnutls-openssl27 libgtk2.0-0 libgtk2.0-bin libhtml-parser-perl
....
..
The following packages will be upgraded:
  acl acpi acpi-support-base acpid adduser aptitude-doc-en at base-files base-passwd bash bash-completion bsd-mailx bsdmainutils bsdutils busybox bzip2 ca-certificates
  console-setup console-setup-linux coreutils cpio cron dash dc debconf debconf-i18n debian-archive-keyring debian-faq debianutils dictionaries-common diffutils discover
  dmidecode doc-debian docutils-common docutils-doc dpkg e2fslibs e2fsprogs findutils fontconfig fontconfig-config fonts-dejavu-core geoip-database gettext-base gpgv grep
  groff-base grub-common grub-pc grub-pc-bin grub2-common gzip hicolor-icon-theme host hostname iamerican ibritish ienglish-common info insserv install-info
....
..
283 upgraded, 0 newly installed, 0 to remove and 115 not upgraded.
Need to get 69.9 MB of archives.
After this operation, 14.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.kernel.org/debian/ stretch/main base-files amd64 9.9 [67.2 kB]
Get:2 http://mirrors.kernel.org/debian/ stretch/main libtinfo5 amd64 6.0+20151126-1 [299 kB]
Get:3 http://mirrors.kernel.org/debian/ stretch/main libncurses5 amd64 6.0+20151126-1 [93.4 kB]
Get:4 http://mirrors.kernel.org/debian/ stretch/main libncursesw5 amd64 6.0+20151126-1 [115 kB]
....
....
..
Get:281 http://mirrors.kernel.org/debian/ stretch/main xdg-user-dirs amd64 0.15-2+b1 [52.2 kB]                                                                              
Get:282 http://mirrors.kernel.org/debian/ stretch/main host all 1:9.10.3.dfsg.P4-12.3 [185 kB]                                                                              
Get:283 http://mirrors.kernel.org/debian/ stretch/main os-prober amd64 1.75 [29.8 kB]                                                                                       
Fetched 69.9 MB in 1min 3s (1,104 kB/s)      
...
...
..
update-alternatives: using /usr/share/docutils/scripts/python2/rst2html4 to provide /usr/bin/rst2html4 (rst2html4) in auto mode
update-alternatives: using /usr/share/docutils/scripts/python2/rst2html5 to provide /usr/bin/rst2html5 (rst2html5) in auto mode
Setting up tasksel (3.39) ...
Setting up task-english (3.39) ...
Setting up task-ssh-server (3.39) ...
Setting up tasksel-data (3.39) ...
Processing triggers for libc-bin (2.19-18+deb8u9) ...
Processing triggers for systemd (215-17+deb8u7) ...
Processing triggers for ca-certificates (20151130+nmu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Processing triggers for dictionaries-common (1.27.2) ...
ispell-autobuildhash: Processing 'american' dict.
ispell-autobuildhash: Processing 'british' dict.

最后,智能升级所有内容:

$ sudo apt-get dist-upgrade

输出示例:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
  docutils-common docutils-doc libasprintf0c2 libbind9-90 libdns100 libintl-perl libintl-xs-perl libisc95 libisccc90 libisccfg90 libjasper1 liblcms2-2 liblwres90
....
..
Done
The following packages will be REMOVED:
  libcwidget3 libsigc++-2.0-0c2a perl-modules
The following NEW packages will be installed:
  dh-python dirmngr distro-info-data firmware-linux-free gcc-6-base gnome-icon-theme gnupg-l10n gtk-update-icon-cache initramfs-tools-core irqbalance keyutils libapparmor1
  libapt-inst2.0 libapt-pkg5.0 libb-hooks-endofscope-perl libbind9-140 libboost-filesystem1.62.0 libboost-iostreams1.62.0 libboost-system1.62.0 libc-l10n
  libclass-method-modifiers-perl libclass-xsaccessor-perl libcpan-changes-perl libcroco3 libcwidget3v5 libdata-perl-perl libdevel-caller-perl
....
..
The following packages will be upgraded:
  apt apt-listchanges apt-utils aptitude aptitude-common bc bind9-host curl dbus dmsetup dnsutils eject exim4 exim4-base exim4-config exim4-daemon-light file ftp gnupg
  gnupg-agent gnupg2 ifupdown init init-system-helpers initramfs-tools initscripts iotop iproute2 iptables iputils-ping isc-dhcp-client isc-dhcp-common
  libarchive-extract-perl libavahi-client3 libc-bin libc6 libcairo2 libclass-c3-xs-perl libcpan-meta-perl libcryptsetup4 libcups2 libcurl3 libcurl3-gnutls libdbus-1-3
  libdevmapper1.02.1 libfcgi-perl libfreetype6 libgcc1 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgnutls-openssl27 libgtk2.0-0 libgtk2.0-bin libhtml-parser-perl
  libintl-perl libldap-2.4-2 liblocale-gettext-perl libmagic1 libmodule-pluggable-perl libnet-ssleay-perl libparams-util-perl libpod-readme-perl libpython-stdlib
  libpython2.7-minimal libpython2.7-stdlib librtmp1 libsasl2-2 libsasl2-modules libstdc++6 libsub-name-perl libsystemd0 libtext-charwidth-perl libtext-iconv-perl
  libtext-soundex-perl libudev1 libuuid-perl libxml-libxml-perl libxml-parser-perl libxml2 linux-image-amd64 locales lsb-release mutt nfs-common openssh-client
  openssh-server openssh-sftp-server openssl perl perl-base pinentry-gtk2 procps python python-apt python-debianbts python-minimal python-pil python2.7 python2.7-minimal
  reportbug rsyslog systemd sysv-rc sysvinit-utils telnet texinfo udev util-linux util-linux-locales vim vim-common vim-runtime vim-tiny w3m wget
115 upgraded, 139 newly installed, 3 to remove and 0 not upgraded.
Need to get 143 MB of archives.
After this operation, 320 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.kernel.org/debian/ stretch/main locales all 2.24-11 [3,290 kB]
Get:2 http://mirrors.kernel.org/debian/ stretch/main libc-l10n all 2.24-11 [819 kB]
Get:3 http://mirrors.kernel.org/debian/ stretch/main libc6 amd64 2.24-11 [2,691 kB]
Get:4 http://mirrors.kernel.org/debian/ stretch/main libc-bin amd64 2.24-11 [779 kB]
Get:5 http://mirrors.kernel.org/debian/ stretch/main gcc-6-base amd64 6.3.0-18 [180 kB]
....
..
...
 
Get:250 http://mirrors.kernel.org/debian/ stretch/main w3m amd64 0.5.3-34 [1,030 kB]                                                                                        
Get:251 http://mirrors.kernel.org/debian/ stretch/main gnupg-l10n all 2.1.18-6 [892 kB]                                                                                     
Get:252 http://mirrors.kernel.org/debian/ stretch/main irqbalance amd64 1.1.0-2.3 [40.4 kB]                                                                                 
Get:253 http://mirrors.kernel.org/debian/ stretch/main publicsuffix all 20160424.0717-1 [98.2 kB]                                                                           
Get:254 http://mirrors.kernel.org/debian/ stretch/main python-debianbts all 2.6.1 [11.5 kB]                                                                                 
Fetched 143 MB in 1min 11s (2,000 kB/s)                                                                                                                                     
Reading changelogs... Done
apt-listchanges: Mailing root: apt-listchanges: news for localhost
Extracting templates from packages: 100%
Preconfiguring packages ...
Deferring configuration of apt-listchanges until python3 is available
(Reading database ... 32357 files and directories currently installed.)
Preparing to unpack .../locales_2.24-11_all.deb ...
Unpacking locales (2.24-11) over (2.19-18+deb8u9) ...
Selecting previously unselected package libc-l10n.
Preparing to unpack .../libc-l10n_2.24-11_all.deb ...
Unpacking libc-l10n (2.24-11) ...
Preparing to unpack .../libc6_2.24-11_amd64.deb ...
Checking for services that may need to be restarted...
Checking init scripts...
Unpacking libc6:amd64 (2.24-11) over (2.19-18+deb8u9) ...
Setting up libc6:amd64 (2.24-11) ...
Checking for services that may need to be restarted...
Checking init scripts...

接下来重启服务器/台式机/笔记本电脑,运行:

$ sudo reboot

验证新升级

执行以下命令:

$ uname -mrs

输出示例:

Linux 4.9.0-3-amd64 x86_64
$ lsb_release -a

输出示例:

:No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.0 (stretch)
Release:	9.0
Codename:	stretch