Score:1

Any way to repair broken image in dpkg?

br flag

I have a huge problem with my server (21.04). I cannot install any apt package. Whatever I do, it gets stuck on "update-initramfs: Deleting /boot/initrd.img-5.11.0-41-generic" forever. Any solutions to this?

Thank you in advance!

tech@vs777:~$ sudo apt install timeshift
[sudo] password for tech:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 linux-modules-5.11.0-41-generic : Depends: linux-image-5.11.0-41-generic but it is not going to be installed or
                                            linux-image-unsigned-5.11.0-41-generic but it is not going to be installed
 timeshift : Depends: libcairo2 (>= 1.2.4) but it is not going to be installed
             Depends: libgdk-pixbuf-2.0-0 (>= 2.22.0) but it is not going to be installed
             Depends: libgee-0.8-2 (>= 0.8.3) but it is not going to be installed
             Depends: libgtk-3-0 (>= 3.16.2) but it is not going to be installed
             Depends: libjson-glib-1.0-0 (>= 1.5.2) but it is not going to be installed
             Depends: libvte-2.91-0 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
tech@vs777:~$ apt --fix-broken install
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
tech@vs777:~$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  amd64-microcode intel-microcode iucode-tool
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  linux-image-unsigned-5.11.0-41-generic
Suggested packages:
  fdutils linux-doc | linux-source-5.11.0 linux-tools linux-modules-extra-5.11.0-41-generic
The following packages will be REMOVED:
  linux-image-5.11.0-41-generic linux-image-5.4.0-89-generic
The following NEW packages will be installed:
  linux-image-unsigned-5.11.0-41-generic
0 upgraded, 1 newly installed, 2 to remove and 1 not upgraded.
2 not fully installed or removed.
Need to get 0 B/11.6 MB of archives.
After this operation, 11.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: linux-image-5.11.0-41-generic: dependency problems, but removing anyway as you requested:
 linux-modules-5.11.0-41-generic depends on linux-image-5.11.0-41-generic | linux-image-unsigned-5.11.0-41-generic; however:
  Package linux-image-5.11.0-41-generic is to be removed.
  Package linux-image-unsigned-5.11.0-41-generic is not installed.

(Reading database ... 121324 files and directories currently installed.)
Removing linux-image-5.11.0-41-generic (5.11.0-41.45) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.11.0-41-generic

Edit: added requested information:

tech@vs777:~$ uname -r
5.4.0-91-generic
tech@vs777:~$ dpkg -l | egrep 'linux-[i|m|g|h]'
ii  binutils-x86-64-linux-gnu              2.36.1-6ubuntu1                                                      amd64        GNU binary utilities, for x86-64-linux-gnu target
ii  linux-headers-5.11.0-41                5.11.0-41.45                                                         all          Header files related to Linux kernel version 5.11.0
ii  linux-headers-5.11.0-41-generic        5.11.0-41.45                                                         amd64        Linux kernel headers for version 5.11.0 on 64 bit x86 SMP
ii  linux-headers-5.4.0-91                 5.4.0-91.102                                                         all          Header files related to Linux kernel version 5.4.0
ii  linux-headers-5.4.0-91-generic         5.4.0-91.102                                                         amd64        Linux kernel headers for version 5.4.0 on 64 bit x86 SMP
ii  linux-headers-generic                  5.11.0.41.42                                                         amd64        Generic Linux kernel headers
rc  linux-image-3.16.0-25-generic          3.16.0-25.33                                                         amd64        Linux kernel image for version 3.16.0 on 64 bit x86 SMP
rc  linux-image-3.19.0-16-generic          3.19.0-16.16                                                         amd64        Linux kernel image for version 3.19.0 on 64 bit x86 SMP
rc  linux-image-3.19.0-58-generic          3.19.0-58.64                                                         amd64        Linux kernel image for version 3.19.0 on 64 bit x86 SMP
rc  linux-image-4.15.0-141-generic         4.15.0-141.145                                                       amd64        Signed kernel image generic
rc  linux-image-4.2.0-35-generic           4.2.0-35.40                                                          amd64        Linux kernel image for version 4.2.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-104-generic          4.4.0-104.127                                                        amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-108-generic          4.4.0-108.131                                                        amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-134-generic          4.4.0-134.160                                                        amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-148-generic          4.4.0-148.174                                                        amd64        Signed kernel image generic
rc  linux-image-4.4.0-159-generic          4.4.0-159.187                                                        amd64        Signed kernel image generic
rc  linux-image-4.4.0-177-generic          4.4.0-177.207                                                        amd64        Signed kernel image generic
rc  linux-image-4.4.0-208-generic          4.4.0-208.240                                                        amd64        Signed kernel image generic
rc  linux-image-4.4.0-21-generic           4.4.0-21.37                                                          amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-81-generic           4.4.0-81.104                                                         amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rH  linux-image-5.11.0-41-generic          5.11.0-41.45                                                         amd64        Signed kernel image generic
rc  linux-image-5.4.0-71-generic           5.4.0-71.79                                                          amd64        Signed kernel image generic
rc  linux-image-5.4.0-72-generic           5.4.0-72.80                                                          amd64        Signed kernel image generic
rc  linux-image-5.4.0-77-generic           5.4.0-77.86                                                          amd64        Signed kernel image generic
rc  linux-image-5.4.0-80-generic           5.4.0-80.90                                                          amd64        Signed kernel image generic
rc  linux-image-5.4.0-81-generic           5.4.0-81.91                                                          amd64        Signed kernel image generic
rc  linux-image-5.4.0-86-generic           5.4.0-86.97                                                          amd64        Signed kernel image generic
rH  linux-image-5.4.0-89-generic           5.4.0-89.100                                                         amd64        Signed kernel image generic
ii  linux-image-5.4.0-91-generic           5.4.0-91.102                                                         amd64        Signed kernel image generic
rc  linux-image-extra-3.16.0-25-generic    3.16.0-25.33                                                         amd64        Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
rc  linux-image-extra-3.19.0-16-generic    3.19.0-16.16                                                         amd64        Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
rc  linux-image-extra-3.19.0-58-generic    3.19.0-58.64                                                         amd64        Linux kernel extra modules for version 3.19.0 on 64 bit x86 SMP
rc  linux-image-extra-4.2.0-35-generic     4.2.0-35.40                                                          amd64        Linux kernel extra modules for version 4.2.0 on 64 bit x86 SMP
rc  linux-image-extra-4.4.0-104-generic    4.4.0-104.127                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-extra-4.4.0-108-generic    4.4.0-108.131                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-extra-4.4.0-134-generic    4.4.0-134.160                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-extra-4.4.0-21-generic     4.4.0-21.37                                                          amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-extra-4.4.0-81-generic     4.4.0-81.104                                                         amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-4.15.0-141-generic       4.15.0-141.145                                                       amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-148-generic        4.4.0-148.174                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-159-generic        4.4.0-159.187                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-177-generic        4.4.0-177.207                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-4.4.0-208-generic        4.4.0-208.240                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-modules-5.11.0-41-generic        5.11.0-41.45                                                         amd64        Linux kernel extra modules for version 5.11.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-71-generic         5.4.0-71.79                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-72-generic         5.4.0-72.80                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-77-generic         5.4.0-77.86                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-80-generic         5.4.0-80.90                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-81-generic         5.4.0-81.91                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-5.4.0-86-generic         5.4.0-86.97                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
ii  linux-modules-5.4.0-89-generic         5.4.0-89.100                                                         amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
ii  linux-modules-5.4.0-91-generic         5.4.0-91.102                                                         amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.15.0-141-generic 4.15.0-141.145                                                       amd64        Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-148-generic  4.4.0-148.174                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-159-generic  4.4.0-159.187                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-177-generic  4.4.0-177.207                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.4.0-208-generic  4.4.0-208.240                                                        amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.11.0-41-generic  5.11.0-41.45                                                         amd64        Linux kernel extra modules for version 5.11.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-71-generic   5.4.0-71.79                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-72-generic   5.4.0-72.80                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-77-generic   5.4.0-77.86                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-80-generic   5.4.0-80.90                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-81-generic   5.4.0-81.91                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-86-generic   5.4.0-86.97                                                          amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.4.0-89-generic   5.4.0-89.100                                                         amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
ii  linux-modules-extra-5.4.0-91-generic   5.4.0-91.102                                                         amd64        Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP

Edit 2:

tech@vs777:~$ sudo dpkg -P linux-modules-5.11.0-41-generic
[sudo] password for tech:
(Reading database ... 121324 files and directories currently installed.)
Removing linux-modules-5.11.0-41-generic (5.11.0-41.45) ...
Purging configuration files for linux-modules-5.11.0-41-generic (5.11.0-41.45) ...
tech@vs777:~$ sudo dpkg --configure -a
tech@vs777:~$ sudo apt -f install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  amd64-microcode intel-microcode iucode-tool
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  linux-image-5.11.0-41-generic linux-image-5.4.0-89-generic
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
2 not fully installed or removed.
After this operation, 26.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 120028 files and directories currently installed.)
Removing linux-image-5.11.0-41-generic (5.11.0-41.45) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.11.0-41-generic

Edit 3:

tech@vs777:~$ dpkg -l | egrep -v '^ii|rc'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
+++-======================================-====================================================================-============-===============================================================================
rH  linux-image-5.11.0-41-generic          5.11.0-41.45                                                         amd64        Signed kernel image generic
rH  linux-image-5.4.0-89-generic           5.4.0-89.100                                                         amd64        Signed kernel image generic

Edit 4:

tech@vs777:~$ df -h;df -i
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           795M  1.2M  794M   1% /run
/dev/vda1       138G   87G   45G  67% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
tmpfs           795M     0  795M   0% /run/user/1000
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
tmpfs          1017593    762 1016831    1% /run
/dev/vda1      9175040 526689 8648351    6% /
tmpfs          1017593      1 1017592    1% /dev/shm
tmpfs          1017593      3 1017590    1% /run/lock
tmpfs             1024     18    1006    2% /sys/fs/cgroup
tmpfs           203518     19  203499    1% /run/user/1000
nobody avatar
gh flag
`uname -r` and `dpkg -l | egrep 'linux-[i|m|g|h]'` please.
Lord M avatar
br flag
@nobody I have updated the main post with requested info.
nobody avatar
gh flag
`sudo dpkg -P linux-modules-5.11.0-41-generic` if this is working than try `sudo dpkg --configure -a` and `sudo apt -f install`
Lord M avatar
br flag
@nobody Same issue. Added that log as well to the main post.
nobody avatar
gh flag
maybe initramfs-tools package is defect itlself. `dpkg -l | egrep -v '^ii|rc'`
Lord M avatar
br flag
@nobody See Edit 3.
Score:0
in flag

Try:

cd /boot
echo Files now in /boot:
ls
for i in initrd.img*
do
    mv -v $i $i.bak # Remove the images and back them up in case of trouble
done
sudo update-initramfs -cvk $(uname -r) | less # Attempt to recreate the initial ramdisk, press q to continue
echo These files are now present
ls

Check that the freshly-created initramfs is present, and reboot. If something fails, use the grub prompt (press C in the boot option selection menu) to recover and fix it (you might want to write these down!)

  • set pager=1 - enable pager for long command outputs like help
  • ls - lists available disk devices. Should return a list of things like (hdX,gptX) or (hdX,mbrX) where X is a number
  • ls (device)/ - List the filesystem on a given device.
  • set ROOT=(device) - Set the FS root
  • linux /<path to kernel> - load kernel (usually /boot/vmlinuz)
  • initrd /<path to initrd> - load initramfs (usually /boot/initrd.img). The kernel and initrd versions have to match.
  • boot - Start system

If you're using RAID, LVM or LUKS, find out what modules you need to load (insmod <module>) beforehand

After rebooting run sudo apt purge initramfs-tools, it will delete additional packages, but don't worry, let it rerun. Then sudo apt install initramfs-tool <whatever packages were removed without the asterisk>. It should be fine now.

Score:0
gh flag

Okay, first look if you have enough place and inodes free very important if you have an own /boot partition. df -h;df -i

when we try to remove the disturbing kernel packages.

sudo dpkg -P linux-image-5.11.0-41-generic linux-image-5.4.0-89-generic

Your system needs a little bit cleaning.

sudo dpkg -P $(dpkg -l | egrep '^rc' | awk '{print $2}')

Meaning; remove remaining files from deinstalled packages.

If this is not working make a backup from your data before we try other things.

Lord M avatar
br flag
Still stuck at removing the image.
nobody avatar
gh flag
Great `ls -al /var/lib/initramfs-tools/` and `ls -al /boot/` you have enough place and a backup? Maybe we have to delete from hand.
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.