首先,我认为我应该说我本周早些时候才安装了 Ubuntu 18.04 LTS,所以我基本上什么都不知道。
我今天在安装 python3 idle 时遇到了一个错误:
dpkg: error processing package linux-modules-4.15.0-22-generic (--configure):
package is in a very bad inconsistent state; you should
reinstall it before attempting configuration
No apport report written because the error message indicates its a followup error from a previous failure.
dpkg: dependency problems prevent configuration of linux-image-4.15.0-22-generic:
linux-image-4.15.0-22-generic depends on linux-modules-4.15.0-22-generic; however:
Package linux-modules-4.15.0-22-generic is not configured yet.
dpkg: error processing package linux-image-4.15.0-22-generic (--configure):
dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.27-3ubuntu1) ...
dpkg: dependency problems prevent configuration of linux-modules-extra-4.15.0-22-generic:
linux-modules-extra-4.15.0-22-generic depends on linux-image-4.15.0-22-generic | linux-image-unsigned-4.15.0-22-generic; however:
Package linux-image-4.15.0-22-generic is not configured yet.
Package linux-image-unsigned-4.15.0-22-generic is not installed.
dpkg: error processing package linux-modules-extra-4.15.0-22-generic (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for man-db (2.8.3-2) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1) ...
Setting up libtcl8.6:amd64 (8.6.8+dfsg-3) ...
dpkg: dependency problems prevent configuration of linux-image-generic:
linux-image-generic depends on linux-image-4.15.0-22-generic; however:
Package linux-image-4.15.0-22-generic is not configured yet.
linux-image-generic depends on linux-modules-extra-4.15.0-22-generic; however:
Package linux-modules-extra-4.15.0-22-generic is not configured yet.
dpkg: error processing package linux-image-generic (--configure):
dependency problems - leaving unconfigured
Setting up libtk8.6:amd64 (8.6.8-4) ...
No apport report written because MaxReports is reached already
Setting up tk8.6-blt2.5 (2.5.3+dfsg-4) ...
dpkg: dependency problems prevent configuration of linux-generic:
linux-generic depends on linux-image-generic (= 4.15.0.22.23); however:
Package linux-image-generic is not configured yet.
dpkg: error processing package linux-generic (--configure):
dependency problems - leaving unconfigured
Setting up blt (2.5.3+dfsg-4) ...
No apport report written because MaxReports is reached already
Setting up python3-tk:amd64 (3.6.5-3) ...
Setting up idle-python3.6 (3.6.5-3) ...
Setting up idle (3.6.5-3) ...
Setting up idle3 (3.6.5-3) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Errors were encountered while processing:
linux-modules-4.15.0-22-generic
linux-image-4.15.0-22-generic
linux-modules-extra-4.15.0-22-generic
linux-image-generic
linux-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
所以我Sudo apt-get upgrade
以为这只是关于升级 Linux 模块,结果我得到了同样的错误消息。我在网上查找错误消息,发现这篇帖子有同样的错误信息。因此我首先运行了提问者使用的命令:sudo apt-get install -f
并收到了以下错误消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
5 not fully installed or removed.
Need to get 0 B/12.9 MB of archives.
After this operation, 0 B of additional disk space will be used.
dpkg: error processing package linux-modules-4.15.0-22-generic (--configure):
package is in a very bad inconsistent state; you should
reinstall it before attempting configuration
dpkg: dependency problems prevent configuration of linux-image-4.15.0-22-generic:
linux-image-4.15.0-22-generic depends on linux-modules-4.15.0-22-generic; however:
Package linux-modules-4.15.0-22-generic is not configured yet.
dpkg: error processing package linux-image-4.15.0-22-generic (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because the error message indicates its a followup error from a previous failure.
dpkg: dependency problems prevent configuration of linux-modules-extra-4.15.0-22-generic:
linux-modules-extra-4.15.0-22-generic depends on linux-image-4.15.0-22-generic | linux-image-unsigned-4.15.0-22-generic; however:
Package linux-image-4.15.0-22-generic is not configured yet.
Package linux-image-unsigned-4.15.0-22-generic is not installed.
dpkg: error processing package linux-modules-extra-4.15.0-22-generic (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-generic:
linux-image-generic depends on linux-image-4.15.0-22-generic; however:
Package linux-image-4.15.0-22-generic is not configured yet.
linux-image-generic depends on linux-modules-extra-4.15.0-22-generic; however:
Package linux-modules-extra-4.15.0-22-generic is not configured yet.
dpkg: error processing package linux-image-generic (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-genNo apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
eric:
linux-generic depends on linux-image-generic (= 4.15.0.22.23); however:
Package linux-image-generic is not configured yet.
dpkg: error processing package linux-generic (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
linux-modules-4.15.0-22-generic
linux-image-4.15.0-22-generic
linux-modules-extra-4.15.0-22-generic
linux-image-generic
linux-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
据我了解,这与第一个略有不同,第一个说包未配置,第二个说我应该重新安装它,因为它在配置之前处于不良状态。它给出的错误消息与提问者给出的几乎相同。所以我尝试了接受答案中提到的步骤。我运行了这个命令sudo rm /etc/apt/sources.list
,然后运行了这个命令sudo software-properties-gtk
,我得到了这个错误消息:
WARNING:root:could not open file '/etc/apt/sources.list'
WARNING:root:could not open file '/etc/apt/sources.list'
所以我再次写了第二条命令,它打开了 software-properties-gtk 并将其写入终端:
Gtk-Message: 20:43:48.389: GtkDialog mapped without a transient parent. This is discouraged.
所以我用这些设置。我点击了“恢复”,什么都没发生。我再次点击,仍然什么都没发生。所以我点击了“关闭”,结果如下:错误消息/通知。我意识到我无法按照该教程操作,因为他刚刚清除了 chrome,而我无法清除 linux 模块。因此,我重新运行,sudo apt-get -f install
现在它显示了一条更短的错误消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: The package linux-modules-4.15.0-22-generic needs to be reinstalled, but I can't find an archive for it.
我试过了sudo apt-get clean
,但终端上什么也没出现,然后我尝试使用我在这个帖子:sudo apt-get install --reinstall linux-modules-4.15.0-22-generic
我不知道这是否是要重新安装的软件包的名称,但值得一试。我收到了相同的错误消息。
我是不是弄坏了什么东西?我需要重新格式化我的系统吗?
编辑:输出ls -la /etc/apt/sources.list
为-rw-r--r-- 1 root root 84 May 26 20:43 /etc/apt/sources.list
的输出uname -a
是Linux Oussema 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
答案1
从评论中我可以看到您已经清理了 sources.list 文件,因此让我们首先通过将以下块复制到您的终端来解决这个问题:
sudo su
cat > /etc/apt/sources.list << "EOF"
deb http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse
deb http://archive.canonical.com/ubuntu bionic partner
deb-src http://archive.canonical.com/ubuntu bionic partner
EOF
exit
现在我们可以开始修复您的安装,它似乎已经陷入了奇怪的状态。
运行更新后,首先删除可移除软件包,以更新正确的软件包档案:
sudo apt update
sudo apt autoremove --purge
这应该会删除到目前为止所有可移动软件包,除了那个设法弄乱的软件包,我们可以通过安装它然后正确地删除它来删除它:
cd /var/cache/apt/archives
sudo dpkg -i linux-modules-4.15.0-22-generic_4.15.0-22.24_amd64.deb
sudo dpkg -r linux-modules-4.15.0-22-generic_4.15.0-22.24_amd64.deb
现在通过运行以下命令清理档案:
sudo apt clean
现在,我们可以在运行完整的更新过程后正确地重新安装软件包:
sudo apt update
sudo apt dist-upgrade
使用以下行:
sudo apt install --reinstall linux-generic
这应该已经将您的系统修复并重新恢复到完整的工作状态。祝您玩得开心,欢迎加入 Linux 社区。
答案2
如果上述所有解决方案均不起作用,并且在执行“sudo apt autoremove --purge”或大多数 apt 或 dpkg 相关命令(类似于“sudo dpkg --configure -a”)时遇到问题,原因如下,粘贴确切的真实场景问题:>
sudo dpkg --configure -a
Setting up linux-image-4.15.0-143-generic (4.15.0-143.147) ...
dpkg (subprocess): unable to execute installed linux-image-4.15.0-143-
generic package post-installation script (/var/lib/dpkg/info/linux-image-
4.15.0-143-generic.postinst): Permission denied
dpkg: error processing package linux-image-4.15.0-143-generic (--configure):
installed linux-image-4.15.0-143-generic package post-installation script
subprocess returned error exit status 2
Errors were encountered while processing:
linux-image-4.15.0-143-generic
即使在授予完全权限后仍拒绝使用
sudo chmod +x /var/lib/dpkg/info/linux-image-4.15.0-143-generic.postinst
or
cd /var/lib/dpkg/info/
ls -lrth //Check the existing permission then change either full or only for root access
sudo chmod -R +755 /var/lib/dpkg/info/
即使如此,仍然面临权限被拒绝的问题,这不是权限问题,因为即使给予了权限,这也是由于 grub 问题造成的,请按照以下步骤操作
"CAUTION:>After taking proper checkpoint or snapshot of data to be in safe side as we
are reinstalling bootloader if reboot happens by mistake without proper
bootloader the vm becomes useless until data_mountpoint is present for all
configuration file also stop replication if present to avoid copying to
replica also proper internet access to fetch new bootloader".
执行以下操作:>
apt-get purge grub-pc grub-common //This will purge the current bootloader setup new or update linux-image-*-generic and update-initramfs by generating /boot/initrd.img-*-generic if menu.lst not found eventhough present in the directory is found do the following
(如果未找到任何问题 menu.lst)
touch /boot/grub/menu.lst
apt-get purge grub-pc grub-common //Use the latest maintainer version to override the menu.lst it will make appropriate latest menu.lst changes if asked for in purge itself it would be mostly asked at "apt-get install grub-pc grub-common" as it finds multiple menu.lst will ask for compare but choosing maintainer version overide the files and will update with latest.
否则继续执行以下操作:>
rm -r /etc/grub.d/ //Check if grub is present if present will be removed mostly will be removed using purge and should show no files to remove or file doesn't exist
如果出现提示,请安装维护版本如果无法选择需要安装引导加载程序的位置,请继续而不选择磁盘,如果使用 scsi 磁盘,gui 将提示警告sd(a,b,c)分区磁盘附带 1,2,3 表示内部分区数,如果使用 HDD,hd(a,b,c)分区磁盘附带 1,2,3 表示内部分区数,例如:hda1,hda2,hdb1
apt-get install grub-pc grub-common
sda 或 hda 这将安装在指定用于启动的磁盘的主分区或根分区中。
grub-install /dev/sda
检查以下命令,如果更新没有问题,则说明您已获得最新的引导加载程序,并且与更新相关的所有问题都将被消除,并且 apt 和 dpkg 命令将正常工作。
update-grub
答案3
我已经两次遇到此问题,并且此图像有两个不同的版本。请参阅我的修复方法:https://askubuntu.com/a/1141915/954416
今天,在执行 apt update 和 apt upgrade 后,我在两台不同的机器上都遇到了这个问题,但我的是针对 linux-image-4.15.0-48-generic 的。(Ubuntu 18.04.2)
我的修复是这样的(在两台机器上重现):
sudo rm /var/lib/dpkg/info/linux-image-4.15.0-48-generic.postinst
sudo dpkg --configure -a
sudo apt-get update
然后重新安装该包:
sudo apt install linux-image-4.15.0-48-generic
这会将包设置为手动安装并将替换 *.postinst 文件。