Score:0

dpkg: error processing package - Unable to repair/remove linux image version using apt and dpkg

mx flag

dpkg: error processing package - Unable to repair/remove linux image version using apt and dpkg


I'm having an issue with apt and dpkg updating my linux kernel version.

Help would be greatly appreciated and I'm also looking at this as a good linux learning opportunity for myself :)

I've looked at many similar solutions online which suggest commands which when run end up in the same or very similar errors to what I've shown below or that I might have a full /boot dir but I don't believe this is the issue as it's reporting 50%. I'm unable to remove kernel versions to free up space anyway (see below errors):

The state I would like to get in would be to have the most up to date kernel version and have a couple of previous versions as fallbacks.

Currently $ dpkg --list 'linux-image-*' returns 50 or so versions (variations of 5.4*, 5.8* and 5.11*)

$ sudo du -sh /boot
337M    /boot
$ sudo df /boot
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/nvme0n1p2    721392 328124    340804  50% /boot

My current kernel version is:

$ uname -r
5.11.0-27-generic

OS:

~$ uname -a
Linux thomas-labtop 5.11.0-27-generic #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal

When I run sudo apt --fix-broken install I'm getting:

$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  linux-image-5.11.0-34-generic
0 to upgrade, 0 to newly install, 1 to remove and 5 not to upgrade.
2 not fully installed or removed.
After this operation, 10.2 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 238716 files and directories currently installed.)
Removing linux-image-5.11.0-34-generic (5.11.0-34.36~20.04.1) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.11.0-34-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.0-27-generic
Found initrd image: /boot/initrd.img-5.11.0-27-generic
Found linux image: /boot/vmlinuz-5.11.0-25-generic
Found initrd image: /boot/initrd.img-5.11.0-25-generic
Found linux image: /boot/vmlinuz-5.4.0-84-generic
Found initrd image: /boot/initrd.img-5.4.0-84-generic
Adding boot menu entry for UEFI Firmware Settings
/etc/grub.d/35_fwupd: line 5: /usr/share/grub: Is a directory
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 126
dpkg: error processing package linux-image-5.11.0-34-generic (--remove):
 installed linux-image-5.11.0-34-generic package post-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
 linux-image-5.11.0-34-generic
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have tried purging the image using dpkg and I have also tried setting it to install:

$ echo "linux-image-5.11.0-34-generic install" | sudo dpkg --set-selections

Subsequent apt commands end up setting it back to removed anyways.

I have been trying various remove, purge and install commands. Since linux-image-5.11.0-34-generic is in a half-installed state I figured I could either completely remove it so I can install it fresh or finish the current installation but have been unable to successfully prevent it being marked as removed.

The current state of dpkg --list 'linux-image*' is

$ dpkg --list 'linux-image*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version               Architecture Description
+++-======================================-=====================-============-=================================
un  linux-image                            <none>                <none>       (no description available)
ii  linux-image-5.11.0-25-generic          5.11.0-25.27~20.04.1  amd64        Signed kernel image generic
ii  linux-image-5.11.0-27-generic          5.11.0-27.29~20.04.1  amd64        Signed kernel image generic
rH  linux-image-5.11.0-34-generic          5.11.0-34.36~20.04.1  amd64        Signed kernel image generic
un  linux-image-5.4.0-42-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-53-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-54-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-56-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-58-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-59-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-72-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-73-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-74-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-77-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-80-generic           <none>                <none>       (no description available)
un  linux-image-5.4.0-81-generic           <none>                <none>       (no description available)
...
...
...
more below

Based on the lines:

/etc/grub.d/35_fwupd: line 5: /usr/share/grub: Is a directory
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 126

I looked into how to resolve this. Solutions online have suggested removing certain grub packages and reinstalling them. Given my current issues with apt I've refrained from doing this in case it makes the state of my machine even worse. Also I'm unable to run any state changing apt commands anyways.


Below is the content of /etc/grub.d/35_fwupd:

$ cat /etc/grub.d/35_fwupd
#! /bin/bash
# SPDX-License-Identifier: LGPL-2.1+
set -e

${pkgdatadir:?}
# shellcheck source=/dev/null
. "$pkgdatadir/grub-mkconfig_lib"

if [ -f /var/lib/fwupd/uefi_capsule.conf ] &&
   ls /sys/firmware/efi/efivars/fwupd-*-0abba7dc-e516-4167-bbf5-4d9d1c739416 1>/dev/null 2>&1; then
      source /var/lib/fwupd/uefi_capsule.conf
      if [ "${EFI_PATH}" != "" ] && [ "${ESP}" != "" ]; then
      echo "Adding Linux Firmware Updater entry" >&2
cat << EOF
menuentry 'Linux Firmware Updater' \$menuentry_id_option 'fwupd' {
EOF
      ${grub_probe:?}
      prepare_grub_to_access_device '`${grub_probe} --target=device \${ESP}` | sed -e "s/^/\t/"'
cat << EOF
    chainloader ${EFI_PATH}
}
EOF
      fi
fi```
guiverc avatar
cn flag
You've not provided any OS & release details; my guess is you're using a LTS release and have *opted* (*intentionally or unintentionally*) to the HWE stack which upgrades during the first two years of the life cycle. Use the GA stack if you don't want this behavior. https://wiki.ubuntu.com/Kernel/LTSEnablementStack Note: *I may have missed your real question; title detail needs to be repeated as some browser setups do not show title when viewing the page and your question is unclear I feel*
tjheslin1 avatar
mx flag
Hi. Thanks I will update with more specific OS information. As for the title I agree it's a bit vague but reflects me not having a good idea of the underlying issue.
tjheslin1 avatar
mx flag
Could you suggest a command I run to print the right information? In the meantime I've provided the output of `lsb_release -a`
Kulfy avatar
mz flag
Probably GRUB configuration is messed up. Please [edit] your question and add the output of `cat /etc/grub.d/35_fwupd`.
tjheslin1 avatar
mx flag
Will do. Thank you!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.