有什么方法可以修复 dpkg 中损坏的图像吗?

有什么方法可以修复 dpkg 中损坏的图像吗?

我的服务器 (21.04) 出了大问题。我无法安装任何 apt 包。无论我做什么,它都会永远停留在“update-initramfs:删除 /boot/initrd.img-5.11.0-41-generic”上。有什么解决办法吗?

先感谢您!

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

编辑:添加了所需信息:

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

编辑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

编辑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

编辑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

答案1

尝试:

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

检查新创建的 initramfs 是否存在,然后重新启动。如果出现故障,请使用 grub 提示符(在启动选项选择菜单中按 C)来恢复并修复它(您可能想把它们记下来!)

  • set pager=1- 为诸如帮助之类的长命令输出启用分页器
  • ls- 列出可用的磁盘设备。应返回诸如 (hdX,gptX) 或 (hdX,mbrX) 之类的列表,其中 X 是数字
  • ls (device)/- 列出给定设备上的文件系统。
  • set ROOT=(device)- 设置文件系统根目录
  • linux /<path to kernel>- 加载内核(通常是/boot/vmlinuz)
  • initrd /<path to initrd>- 加载 initramfs (通常是 /boot/initrd.img)。内核和 initrd 版本必须匹配。
  • boot- 启动系统

如果你使用 RAID、LVM 或 LUKS,请事先了解需要加载哪些模块(insmod <module>

重启后运行sudo apt purge initramfs-tools,它会删除额外的包,但不用担心,让它重新运行。然后sudo apt install initramfs-tool <whatever packages were removed without the asterisk>。现在应该没问题了。

答案2

好的,首先看看您是否有足够的空间和可用的 inode,如果您有自己的 /boot 分区,这非常重要。df -h;df -i

当我们尝试删除令人不安的内核包时。

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

您的系统需要稍微清理一下。

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

含义;从已卸载的软件包中删除剩余的文件。

如果这不起作用,请在我们尝试其他方法之前备份您的数据。

相关内容