通过“apt autoremove”修复损坏的 apt,**且**不会破坏我的系统

通过“apt autoremove”修复损坏的 apt,**且**不会破坏我的系统

不知何故,我apt的 Ubuntu 20.04.4 系统受到了攻击,现在有超过 1,800 个软件包被标记为需要卸载。

这是Xubuntu安装时产生的,这意味着我正在运行xfce桌面。

我知道修复此类apt问题的推荐方法是执行 ,apt autoremove然后重新安装软件包。但是,如果我这样做,那么我的系统在 之后将完全无法使用apt autoremove,因为我的系统中的大部分软件包都已被卸载。

我正在寻找另一种方法来修复我的apt数据库,这样我就不必apt autoremove为了纠正而用命令破坏我的系统apt

为了说明apt我的系统的状态,下面是我运行的一些操作...

% sudo apt-get install -f
[returns a list of the names of the 1,800 packages]

% sudo dpkg configure -a
[no output]

% sudo aptitude search ?broken
[no output]

% sudo cat /var/log/apt/history.log
Start-Date: 2022-05-04  18:01:54
Requested-By: [MYUSERID] (1000)
Upgrade: networkd-dispatcher:amd64 (2.1-2~ubuntu20.04.2, 2.1-2~ubuntu20.04.3), libvirt-daemon-system-systemd:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), openssl:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), librbd1:amd64 (15.2.14-0ubuntu0.20.04.2, 15.2.16-0ubuntu0.20.04.1), google-chrome-stable:amd64 (101.0.4951.41-1, 101.0.4951.54-1), libvirt-clients:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), iio-sensor-proxy:amd64 (2.8-1ubuntu1, 2.8-1ubuntu2), libvirt-daemon-driver-storage-rbd:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libpq5:amd64 (12.9-0ubuntu0.20.04.1, 12.10-0ubuntu0.20.04.1), ubuntu-drivers-common:amd64 (1:0.9.0~0.20.04.6, 1:0.9.0~0.20.04.7), libvirt-daemon-driver-qemu:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libvirt-daemon-system:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libssl-dev:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libssl-doc:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libmysqlclient21:amd64 (8.0.28-0ubuntu0.20.04.3, 8.0.29-0ubuntu0.20.04.2), libmysqlclient21:i386 (8.0.28-0ubuntu0.20.04.3, 8.0.29-0ubuntu0.20.04.2), libvirt0:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), lm-sensors:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libsensors-config:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libssl1.1:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libssl1.1:i386 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libsensors5:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libsensors5:i386 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), librados2:amd64 (15.2.14-0ubuntu0.20.04.2, 15.2.16-0ubuntu0.20.04.1), libvirt-daemon:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16)
End-Date: 2022-05-04  18:02:47

% sudo ls -l /etc/apt/sources.list
4 -rw-r--r-- 1 root root 3280 Jan 19 17:24 /etc/apt/sources.list
[note that the file hasn't changed in a few months]

% sudo ls -l /etc/apt/sources.list.d 
total 16
4 -rw-r--r-- 1 root root 190 Jan 19 17:24 google-chrome.list
4 -rw-r--r-- 1 root root 190 Jan 19 17:24 google-chrome.list.save
4 -rw-r--r-- 1 root root  56 Apr 14 11:06 skype-stable.list
4 -rw-r--r-- 1 root root  56 Jan 19 17:24 skype-stable.list.save
[note that none of this has changed recently]

% sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease                                                                                             
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                                                            
Hit:3 http://dl.winehq.org/wine-builds/ubuntu focal InRelease                                                                                         
Get:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]                                                                          
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                                                                          
Hit:6 http://archive.canonical.com/ubuntu focal InRelease                                                                                             
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease                                                                 
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [391 kB]      
Get:10 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]                     
Get:11 http://us.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [9,568 B]
Get:12 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.8 kB]
Hit:13 https://repo.skype.com/deb stable InRelease                                              
Get:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.6 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.3 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Fetched 1,155 kB in 2s (555 kB/s)                       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

% sudo grep -r "^deb" /etc/apt/ --include=*.list
/etc/apt/sources.list.d/google-chrome.list:deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main
/etc/apt/sources.list.d/skype-stable.list:deb [arch=amd64] https://repo.skype.com/deb stable main
/etc/apt/sources.list.d.save/alex-p-ubuntu-aegisub-focal.list:deb http://ppa.launchpad.net/alex-p/aegisub/ubuntu focal main
/etc/apt/sources.list.d.save/teamviewer.list:deb https://linux.teamviewer.com/deb stable main
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal main restricted
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal universe
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates universe
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates universe
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal multiverse
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates multiverse
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
/etc/apt/sources.list:deb http://archive.canonical.com/ubuntu focal partner
/etc/apt/sources.list:deb-src http://archive.canonical.com/ubuntu focal partner
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security main restricted
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security universe
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu focal-security universe
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security multiverse
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu focal-security multiverse
/etc/apt/sources.list:deb http://dl.winehq.org/wine-builds/ubuntu/ focal main

我以前遇到过类似的问题,并按照以下帖子的“答案”部分中的描述进行了修复:apt 忘记了 1000 多个软件包,我无法重新安装...这是以“我知道如何解决这个问题...”开头的答案

然而,这看起来像是一种解决这个问题的不成熟的方法,而且我不确定如果我现在运行它它会有多可靠。

有人能建议任何其他方法来解决此问题吗?sudo apt autoremove无需使用我过去使用的那种黑客方法?

提前非常感谢您。

附言:我每天都会备份我的系统。我可以从最新备份中恢复哪些文件或目录,其中包含未损坏的数据库版本apt

聚苯硫醚:我尝试xubuntu-desktop按照以下评论中讨论的方式进行安装。遗憾的是,它没有帮助……

% sudo apt install xubuntu-desktop
Reading package lists... Done
Building dependency tree       
Reading state information... Done
xubuntu-desktop is already the newest version (2.233).
xubuntu-desktop set to manually installed.
The following packages were automatically installed and are no longer required:
[list of 1,800 package names, followed by ...]
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

所有这些软件包仍然标记为需要卸载。

答案1

您可以尝试使用标志 --no-remove。(即 apt-get install --fix-broken --no-remove)或者确实如此apt-get install --fix-broken --trivial-only。请参阅:https://linux.die.net/man/8/apt-get

答案2

我解决了这个问题。

xubuntu-desktop重新安装和后xubuntu-core,问题仍然存在。因此,我认为问题不是由于依赖关系树顶部缺少一个安装而导致的,而是整个apt数据库可能因某种原因损坏。

因此,我放弃了捷径,我祈祷好运,最后我咬紧牙关,做了一些与过去略有不同的事情,正如我在这里的回答中所述:apt 忘记了 1000 多个软件包,我无法重新安装

这次,我仅安装了每个软件包,而不是在每次安装之前进行初始删除,而且成功了。以下是我采取的步骤...

步骤1:

% sudo apt-get install -f >apt-installs

运行此程序后,apt-installs文件包含此数据...

Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
[names of more than 1,800 packages]
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

第2步:

我编辑了此apt-installs文件以删除顶部 4 行和底部 2 行,然后重新格式化它,以便每行有一个包名称。

步骤3:

我将字符串添加fixit到每行的开头。

步骤4:

我创建了一个名为的 shell 函数fixit来安装指定的包,并将该函数放在文件顶部apt-installs。现在,下面是前十几行代码的样子apt-installs……

fixit() {
  [[ $# -lt 1 ]] && return 0
  package="${1}"
  shift
  echo "### fixing ${package}"
  apt-get -y install "${package}"
  echo ''
}
fixit accerciser
fixit accountsservice
fixit acpi-support
fixit acpid
fixit adb
[more than 1,800 similar lines]

步骤5:

我运行了这个:

% sudo bash apt-installs

这运行了大约 30 分钟并重新安装了每个软件包。从函数中可以看出fixitremove每个软件包之前都没有执行任何操作install

第 6 步:

然后我运行了这两个命令......

% sudo apt-get purge aptitude
% sudo apt-get install aptitude

aptitude与数据库重新同步了apt

现在一切似乎都恢复正常了。

我猜如果我知道apt从最近的备份中重新安装哪些与 相关的文件/目录,我也可以用这种方式解决问题。但是,我对 的底层内部结构了解不够apt,我无法快速找出需要恢复哪些项目。

为了将来的参考,我想知道有关如何恢复apt数据库的信息,因为如果再次发生此类问题,它将更容易修复。

非常感谢用户535733

相关内容