dpkg:处理包时出错 - 无法使用 apt 和 dpkg 修复/删除 linux 映像版本
apt
我在dpkg
更新 Linux 内核版本时遇到了问题。
如能得到帮助我将非常感激,我也将此视为一次很好的 Linux 学习机会 :)
我在网上查看了许多类似的解决方案,它们建议的命令在运行时会出现与我下面显示的相同或非常相似的错误,或者我的/boot
目录可能已满,但我不认为这是问题所在,因为它报告了 50%。无论如何,我无法删除内核版本来释放空间(请参阅以下错误):
我希望达到的状态是拥有最新的内核版本,并且拥有几个以前的版本作为后备。
目前$ dpkg --list 'linux-image-*'
返回 50 个左右版本(5.4*
、5.8*
和的变体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
我当前的内核版本是:
$ uname -r
5.11.0-27-generic
操作系统:
~$ 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
当我跑步时sudo apt --fix-broken install
我得到了:
$ 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)
我尝试使用 dpkg 清除图像并且还尝试将其设置为安装:
$ echo "linux-image-5.11.0-34-generic install" | sudo dpkg --set-selections
后续apt
命令最终都会将其设置回已删除状态。
我一直在尝试各种remove
、purge
和install
命令。由于linux-image-5.11.0-34-generic
处于某种half-installed
状态,我认为我可以完全删除它以便重新安装它,或者完成当前安装,但无法成功阻止它被标记为已删除。
目前的状态dpkg --list 'linux-image*'
是
$ 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
根据以下几行:
/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
我研究了如何解决这个问题。网上的解决方案建议删除某些 grub 包并重新安装它们。考虑到我目前的问题,apt
我避免这样做,以免使我的机器状态变得更糟。而且无论如何我都无法运行任何状态更改apt
命令。
以下是 的内容/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```
答案1
您可能需要先更新。先完成所有循环。
reboot
sudo apt update
sudo apt upgrade
sudo apt autoremove
然后就这样...
sudo apt install linux-generic
sudo apt upgrade
sudo apt autoremove
sudo apt update
reboot