尝试在没有互联网的情况下更新和安装后 apt 损坏

尝试在没有互联网的情况下更新和安装后 apt 损坏

在没有互联网接入的 debian buster 机器上,大多数 apt 命令(如 apt install/remove/autoremove)显示以下错误:

The following packages have unmet dependencies:
 systemd : Depends: libsystemd0 (= 241-7~deb10u6) but 241-7~deb10u8 is to be installed
           Recommends: libpam-systemd but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

当尝试运行时apt --fix-broken install,我收到此错误:

root@debian10-h1:/var/cuda-repo-debian10-11-4-local# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
 big list of packages
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  systemd
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 13.8 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 114294 files and directories currently installed.)
Removing systemd (241-7~deb10u6) ...
systemd is the active init system, please switch to another before removing systemd.
dpkg: error processing package systemd (--remove):
 installed systemd package pre-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 systemd
E: Sub-process /usr/bin/dpkg returned an error code (1)

我是如何到达那里的

我必须在无法访问互联网的 Debian Buster 服务器上安装一个程序。到目前为止,当我必须通过 apt 安装某些东西时,我会apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances <your-package-here> | grep "^\w" | sort -u)在虚拟机上运行以从包和所有依赖项下载 .deb 文件,将文件传输到我的目标计算机,然后运行dpkg -i *.deb安装在那里,这是有效的美好的。

我必须安装 CUDA,所以我遵循了 nvidia 安装指南。在某些时候,我应该运行这些命令:

wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda-repo-debian10-11-4-local_11.4.0-470.42.01-1_amd64.deb
sudo dpkg -i cuda-repo-debian10-11-4-local_11.4.0-470.42.01-1_amd64.deb
sudo apt-key add /var/cuda-repo-debian10-11-4-local/7fa2af80.pub
sudo add-apt-repository contrib
sudo apt-get update
sudo apt-get -y install cuda

我执行前 4 个命令没有任何问题(第一个命令在我的具有互联网连接的虚拟机上执行),但由于我没有互联网连接,所以第五个命令失败了:

root@debian10-h1:/home/user/installation# apt-get update
Get:1 file:/var/cuda-repo-debian10-11-4-local  InRelease
Ign:1 file:/var/cuda-repo-debian10-11-4-local  InRelease
Get:2 file:/var/cuda-repo-debian10-11-4-local  Release [564 B]
Get:2 file:/var/cuda-repo-debian10-11-4-local  Release [564 B]
Err:4 http://deb.debian.org/debian buster InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used                                                                                                                                                              instead.

还有第六个:

root@debian10-h1:/home/user/installation# apt-get -y install cuda
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 apt-utils : Depends: apt (= 1.8.2.2) but 1.8.2.3 is to be installed
 cuda : Depends: cuda-11-4 (>= 11.4.0) but it is not going to be installed
 libglib2.0-bin : Depends: libglib2.0-0 (= 2.58.3-2+deb10u2) but 2.58.3-2+deb10u
3 is to be installed
 libpython3.7 : Depends: libpython3.7-stdlib (= 3.7.3-2+deb10u2) but 3.7.3-2+deb10u3 is to be installed
 systemd : Depends: libsystemd0 (= 241-7~deb10u6) but 241-7~deb10u8 is to be installed
 udev : Depends: libudev1 (= 241-7~deb10u6) but 241-7~deb10u8 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

所以我尝试了apt --fix-broken install

root@debian10-h1:/home/user/installation# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  big list of packages
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  big list of packages
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  init systemd-sysv (due to init)
0 upgraded, 0 newly installed, 58 to remove and 1 not upgraded.
After this operation, 364 MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?]n

我尝试按照建议进行操作apt autoremove,但得到的结果E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).与以前相同。与 相同apt remove cuda。认为由于期间的问题而无法正常工作apt-get update,我尝试通过 apt-offline 进行更新,但再次被要求使用apt --fix-broken install

root@debian10-h1:/home/user/installation# apt-offline set ./my.sig

Generating database of files that are needed for an update.

Generating database of file that are needed for operation upgrade
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
ERROR: FATAL: Something is wrong with the APT system

由于我没有找到其他任何事情可做,因此我重试,apt --fix-broken install但这次接受继续:

root@debian10-h1:/home/user/installation# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  big list of packages
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  big list of packages
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  init systemd-sysv (due to init)
0 upgraded, 0 newly installed, 58 to remove and 1 not upgraded.
After this operation, 364 MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?]Yes, do as I say!
(Reading database ... 120959 files and directories currently installed.)

Lot of others thing were removed, I just kept the ones where I got a different message, can post the full list if needed.

Removing linux-image-amd64 (4.19+105+deb10u9) ...
Removing linux-image-4.19.0-14-amd64 (4.19.171-2) ...
W: Removing the running kernel
W: Last kernel image has been removed, so removing the default symlinks
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.19.0-14-amd64
/etc/kernel/postrm.d/zz-update-grub:
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Adding boot menu entry for EFI firmware configuration
done
update-initramfs: deferring update (trigger activated)
Removing initramfs-tools (0.133+deb10u1) ...
Removing initramfs-tools-core (0.133+deb10u1) ...
Removing systemd (241-7~deb10u6) ...
systemd is the active init system, please switch to another before removing systemd.
dpkg: error processing package systemd (--remove):
 installed systemd package pre-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 systemd
E: Sub-process /usr/bin/dpkg returned an error code (1)

我已经尝试过的

  • 已关注https://askubuntu.com/a/1093253:sudo apt-get clean不显示任何东西,

    root@debian10-h1:/home/user# dpkg --configure -a
    Processing triggers for mime-support (3.62) ...
    Processing triggers for hicolor-icon-theme (0.17-2) ...
    Processing triggers for libglib2.0-0:amd64 (2.58.3-2+deb10u3) ...
    Processing triggers for libc-bin (2.28-10) ...
    Processing triggers for man-db (2.8.5-2) ...
    Processing triggers for libreoffice-common (1:6.1.5-3+deb10u6) ...
    Processing triggers for dbus (1.12.20-0+deb10u1) ...
    Processing triggers for desktop-file-utils (0.23-4) ...
    

sudo apt upgrade --fix-missing要求我再做apt --fix-broken install一次。

我想知道是否有人知道如何解决该问题,如果需要,我可以提供更多信息。

答案1

我将解释系统如何最终陷入这种情况(至少是我的理论),以及将来如何避免这种情况;但首先,让我们看看如何修复它。

我怀疑您的设置太糟糕,无法apt-offline通过合理的步骤来修复问题。你最好下载一下当前点发行的第一张完整 DVD,并使用它。为此,请删除所有配置的存储库,在服务器上安装 DVD 映像,然后使用apt-cdrom,使用该--no-mount选项,这样apt-cdrom就不会尝试管理“DVD 驱动器”本身(假设您使用图像)。

这将为您提供最新的软件包源,您可以使用它来重新安装已删除的软件包并升级系统,使其处于一致的状态。我对此没有什么神奇的秘诀;您必须弄清楚哪些软件包被删除了。apt full-upgrade可能有帮助。

至于为什么系统最终会这样崩溃,我认为这与CUDA无关,而是与您离线安装所使用的技术有关。下载完整的依赖关系树,忽略已安装的内容,必然会最终下载与应一起升级的其他依赖关系树相交的软件包集。例如,许多包最终依赖于libsystemd0,但它们的依赖关系树不包括systemd;安装这样的软件包集会导致不匹配的systemdand libsystemd0,这解释了您问题中的第一个错误。dpkg -i可以允许这种不匹配的发生,但apt不喜欢它们,并且需要修复它们才能做任何明智的事情;这就是apt install --fix-broken修复的内容,但它需要一个包存储库......

为了避免这种情况,安装的软件包集必须保持全局一致。对于断开连接的系统,apt-offline这是最好的方法,但它必须一直使用,没有apt-cache depends技巧。对于部分连接的系统,IE对于位于网络上但无法直接访问 Internet 的情况,网络本地包缓存可能是更好的解决方案;参见例如apt-cacher-ng

相关内容