无法安装任何软件包:“软件包 linux-image-5.4.0-42-generic 缺少最后的换行符”?

无法安装任何软件包:“软件包 linux-image-5.4.0-42-generic 缺少最后的换行符”?

我尝试在 Ubuntu 20.04.5 上安装一些软件包更新,但一切都失败了:

dpkg: unrecoverable fatal error, aborting:
 files list file for package 'linux-image-5.4.0-42-generic' is missing final newline

我该如何解决这个问题?

这是我尝试过的示例:

> sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro
The following NEW packages will be installed:
  linux-headers-5.15.0-52-generic linux-hwe-5.15-headers-5.15.0-52 linux-image-5.15.0-52-generic linux-modules-5.15.0-52-generic linux-modules-extra-5.15.0-52-generic
The following packages will be upgraded:
  code docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin git git-man gitk gthumb gthumb-data libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal
  libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal libkrb5-26-heimdal libksba8 libroken18-heimdal libwind0-heimdal linux-generic-hwe-20.04
  linux-headers-generic-hwe-20.04 linux-image-generic-hwe-20.04 linux-libc-dev unzip zlib1g zlib1g:i386 zlib1g-dev
28 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
23 standard LTS security updates
Need to get 0 B/286 MB of archives.
After this operation, 606 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Extracting templates from packages: 100%
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'linux-image-5.4.0-42-generic' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)
(base)  ~

答案1

您的/var/lib/dpkg/info/linux-image-5.4.0-42-generic.list文件已损坏。您应该将其移开,然后dpkg才能继续:

sudo mv /var/lib/dpkg/info/linux-image-5.4.0-42-generic.list{,.bak}

理想情况下,您可以重新安装该软件包,以便dpkg可以正确删除它,但这可能不再可能(该软件包无法从存储库中获得)。您应该手动检查其中列出的内容/var/lib/dpkg/info/linux-image-5.4.0-42-generic.list.bak并删除其中列出的不属于任何其他包的任何文件(用于dpkg -S检查)。

您可能需要手动清理/lib/modules/5.4.0-42-generic/boot也检查并删除相应的vmlinuz文件(initrd如果有)。

相关内容