2

First of all, I believe I should say that I just installed Ubuntu 18.04 LTS earlier this week so I basically don't know anything.
I was installing the python3 idle today and encountred an error:

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)

So I ran Sudo apt-get upgrade thinking it's just about upgrading the linux modules and I got the same error message. I look up the error message online and I find this post that has the same error message. So I first ran the command the asker used: sudo apt-get install -f and got this error message:

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)

Which from what I understood differs a bit from the first in that the first said the package is not configured and the second said I should reinstall it because it's in a bad state before configuring. It gives an almost identical error message to that of the asker. so I tried the steps mentioned in the accepted answer. I ran this command sudo rm /etc/apt/sources.list and then this one sudo software-properties-gtkand I get this error message:

WARNING:root:could not open file '/etc/apt/sources.list'

WARNING:root:could not open file '/etc/apt/sources.list'

So I wrote the second command again and it opened software-properties-gtk and wrote this into the terminal:

 Gtk-Message: 20:43:48.389: GtkDialog mapped without a transient parent. This is discouraged.

So I used these settings. I hit Revert, nothing happened. I hit it again and still nothing happened. So, I hit Close and got this error message/notification. I realized that I can't follow with that tutorial because he just purged chrome and I can't purge linux modules. So, I reran sudo apt-get -f install and now, it shows a way shorter error message:

    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. 

I tried sudo apt-get clean and nothing showed up on the terminal and then I tried to use this command I saw on this post: sudo apt-get install --reinstall linux-modules-4.15.0-22-generic I don't know if that's the name of the package to reinstall but it was worth a try. I got the same error message.

Did I break something? Do I need to reformat my system?

Edit: Output of ls -la /etc/apt/sources.list is -rw-r--r-- 1 root root 84 May 26 20:43 /etc/apt/sources.list

Output of uname -a is 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

18
  • Try please the following commands in succesion of each other: sudo apt clean, sudo apt update, sudo apt install --reinstall linux-generic. As of now there is a newer kernel available. Other problem which could have been is that the packages where corrupted as you downloaded them while updating.
    – Videonauth
    May 26, 2018 at 21:27
  • It tells me E: The package linux-modules-4.15.0-22-generic needs to be reinstalled, but I can't find an archive for it.
    – Oussema
    May 26, 2018 at 21:30
  • What is the output of ls -la /etc/apt/sources.list? if you get an empty line you need to recreate your sources.list file. Just tell me. And pleas edit your question to include the output of uname -a.
    – Videonauth
    May 26, 2018 at 21:35
  • Output of ls -la /etc/apt/sources.list is -rw-r--r-- 1 root root 84 May 26 20:43 /etc/apt/sources.list Output of uname -a is 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
    – Oussema
    May 26, 2018 at 21:39
  • And sorry to bother you what is the output of cat /etc/apt/sources.list ?
    – Videonauth
    May 26, 2018 at 22:00

3 Answers 3

8

From the comments I can read that you have cleaned out your sources.list file, so let's fix this first by copying the following block over into your terminal:

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

Now we can begin to fix your installation which seems to have ended up in a weird state.

First remove the removable packages after having run an update to get the proper package archives updated:

sudo apt update
sudo apt autoremove --purge

This should remove all removable packages so far except the one which managed to get messed up which we can then remove then by installing it and then removing it properly:

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

Now cleaning up the archives by running:

sudo apt clean

And now we can reinstall the packages properly after having run an complete update process:

sudo apt update
sudo apt dist-upgrade

with the following line:

sudo apt install --reinstall linux-generic

This should have fixed your system into a complete working state again. Have fun and welcome to the Linux community.

1

If all the above solution doesn't work and facing issue while doing "sudo apt autoremove --purge" or most of apt or dpkg related commands similar to "sudo dpkg --configure -a" with following reason pasting exact real scenario issue:>

    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

Even after giving full permission to permission denied using

    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/

Even then still facing the issue that permission is denied its not the issue of permission as eventhough permission given its due to grub issue follow below steps

    "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".

Do the following:>

    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 

(If any issue menu.lst not found)

    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.

Else proceed with following:>

    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 

Install the maintainer version if prompted if unable to choose where the bootloader needs to be installed proceed without choosing the disk the gui will prompt warning if using scsi disk sd(a,b,c) partition disk comes with 1,2,3 appended for number of partition inside if HDD is used hd(a,b,c) partition disk comes with 1,2,3 appended for number of partition inside ex:hda1,hda2,hdb1

    apt-get install grub-pc grub-common

sda or hda This will install in primary partition or root partition of the disk assigned for boot.

    grub-install /dev/sda

Check below command if updated without issue you have got the latest bootloader and all the issue related with the update will be removed and apt and dpkg commands will work normally.

    update-grub
0

I've had this issue twice now with two different versions of this image. See my fix here: https://askubuntu.com/a/1141915/954416

I had this issue on two separate machines today after doing an apt update and apt upgrade except mine was for linux-image-4.15.0-48-generic. (Ubuntu 18.04.2)

My fix was this (reproduced on both machines):

sudo rm /var/lib/dpkg/info/linux-image-4.15.0-48-generic.postinst
sudo dpkg --configure -a
sudo apt-get update

Then reinstall the package:

sudo apt install linux-image-4.15.0-48-generic

This will set the package to manually installed and will replace the *.postinst file.

2
  • Please include essential parts here.
    – user833907
    May 16, 2019 at 13:45
  • @Coditoergosum - edited/updated.
    – Ben Molloy
    May 16, 2019 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .