Ubuntu 20.04.3 LTS (Focal Fossa): Error "Package linux-image-generic is not configured" when updating linux-firmware

I kindly ask somebody experienced to help me with the following painful issue. Recently, my automated software updater suggested me to update linux-firmware. The update failed and I am receiving such message ever since during every update. I tried to google solutions and fix the issue but I never succeeded. Here is the summary of what I tried:

Here is what I obtain after executing sudo apt install linux-firmware:

$ sudo apt install linux-firmware
Reading package lists... Done
Building dependency tree       
Reading state information... Done
linux-firmware is already the newest version (1.187.24).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
6 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-firmware (1.187.24) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package linux-firmware (--configure):
 installed linux-firmware package post-installation script subprocess returned error exit status 1
Setting up linux-image-5.4.0-92-generic (5.4.0-92.103) ...
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-firmware; however:
  Package linux-firmware is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 5.4.0.92.96); however:
  Package linux-image-generic is not configured yet.

dpkg: error processing package linux-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.
                       No apport report written because MaxReports is reached already
                                                                                     dpkg: dependency problems prevent configuration of linux-generic-hwe-18.04:
 linux-generic-hwe-18.04 depends on linux-generic; however:
  Package linux-generic is not configured yet.

dpkg: error processing package linux-generic-hwe-18.04 (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Processing triggers for linux-image-5.4.0-92-generic (5.4.0-92.103) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-92-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-92-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-5.4.0-92-generic (--configure):
 installed linux-image-5.4.0-92-generic package post-installation script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-firmware
 linux-image-generic
 linux-generic
 linux-generic-hwe-18.04
 initramfs-tools
 linux-image-5.4.0-92-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Here is the output which I get when I try sudo dpkg --configure -a:

$ sudo dpkg --configure -a                       
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-5.4.0-92-generic; however:
  Package linux-image-5.4.0-92-generic is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
Setting up initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: deferring update (trigger activated)
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 5.4.0.92.96); however:
  Package linux-image-generic is not configured yet.

dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
Setting up linux-firmware (1.187.24) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package linux-firmware (--configure):
 installed linux-firmware package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of linux-generic-hwe-18.04:
 linux-generic-hwe-18.04 depends on linux-generic; however:
  Package linux-generic is not configured yet.

dpkg: error processing package linux-generic-hwe-18.04 (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-generic
 linux-generic
 linux-firmware
 linux-generic-hwe-18.04
 initramfs-tools

Finally, I also tried sudo apt --fix-broken install:

$ sudo apt --fix-broken install                                     
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
6 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-firmware (1.187.24) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package linux-firmware (--configure):
 installed linux-firmware package post-installation script subprocess returned error exit status 1
Setting up linux-image-5.4.0-92-generic (5.4.0-92.103) ...
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-firmware; however:
  Package linux-firmware is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 5.4.0.92.96); however:
  Package linux-image-generic is not configured yet.

dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic-hwe-18.04:
 linux-generic-hwe-18.04 depends on linux-generic; however:
  Package linux-generic is not configured yet.

No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report wrrom a previous failure.
                       No apport report written because MaxReports is reached already
                                                                                     dpkg: error processing package linux-gen
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-91-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-91-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Processing triggers for linux-image-5.4.0-92-generic (5.4.0-92.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-92-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/kubuntu--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-92-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-5.4.0-92-generic (--configure):
 installed linux-image-5.4.0-92-generic package post-installation script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-firmware
 linux-image-generic
 linux-generic
 linux-generic-hwe-18.04
 initramfs-tools
 linux-image-5.4.0-92-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

I hope that somebody will be able to help me with the problem. Thank you very much in advance!


Seems like some problems with the older kernels. Let's work together step by step to fix this problem.

  1. First, purge all the older kernels which are no longer in use or are causing errors:

     dpkg -l | egrep "linux-(signed|modules|image|headers)" | grep -v $(uname -r | cut -d - -f 1) | awk {'print $2'} | xargs sudo apt purge -y
    
  2. Run the apt -f again:

    sudo apt --fix-broken install
    

Alternatively, you could use a little complex way of doing the same.

  1. Remove the post-installation files for the error packages and run a fresh update:

     cd /var/lib/dpkg/info/ && sudo mv linux-firmware* ~/ && sudo mv linux-image-generic* ~/ && sudo mv linux-generic* ~/ && sudo mv linux-generic-hwe-18.0* ~/ && sudo mv initramfs-tools* ~/ && sudo mv linux-image-5.4.0-92-generic* ~/
    
  2. Run apt -f

    sudo apt --fix-broken install 
    
  3. Now, update again:

    sudo apt update && sudo apt upgrade -y
    
  4. Now reinstall the packages:

    sudo apt install linux-firmware linux-image-generic linux-generic linux-generic-hwe-18.04 initramfs-tools linux-image-5.4.0-92-generic
    

An alternative way to do the above steps in one copy-paste friendly line.

sudo dpkg --purge --force-all linux-firmware linux-image-generic linux-generic linux-generic-hwe-18.04 initramfs-tools linux-image-5.4.0-92-generic && sudo apt -f install && sudo apt update && sudo apt upgrade  && sudo apt install linux-firmware linux-image-generic linux-generic linux-generic-hwe-18.04 initramfs-tools linux-image-5.4.0-92-generic

This problem was solved in a chat room. (If you've any query about this answer then please comment here. Don't continue that chat room.)