根本无法使用 apt 安装或删除任何软件包 - “无法加载 /boot/System.map-4.8.0-59-generic:没有此文件或目录”

根本无法使用 apt 安装或删除任何软件包 - “无法加载 /boot/System.map-4.8.0-59-generic:没有此文件或目录”

注意:我怀疑这个问题与因为我不使用 DKMS


您好,我的服务器(最近从一个可怕的内核问题中恢复)apt autoremove --purge给出了以下结果:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-image-extra-4.8.0-59-generic
0 upgraded, 0 newly installed, 1 to remove and 36 not upgraded.
2 not fully installed or removed.
After this operation, 161 MB disk space will be freed.
(Reading database ... 264820 files and directories currently installed.)
Removing linux-image-extra-4.8.0-59-generic (4.8.0-59.64) ...
depmod: FATAL: could not load /boot/System.map-4.8.0-59-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.8.0-59-generic /boot/vmlinuz-4.8.0-59-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.8.0-59-generic /boot/vmlinuz-4.8.0-59-generic
update-initramfs: Generating /boot/initrd.img-4.8.0-59-generic
cp: failed to restore the default file creation context: Invalid argument
E: /usr/share/initramfs-tools/hooks/kmod failed with return 1.
update-initramfs: failed for /boot/initrd.img-4.8.0-59-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.8.0-59-generic (--remove):
 installed linux-image-extra-4.8.0-59-generic package post-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-4.8.0-59-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

这里有一条有趣的线索:

depmod: FATAL: could not load /boot/System.map-4.8.0-59-generic: No such file or directory

ls /boot

0 LD-Server /etc/update-motd.d ls /boot
abi-4.15.0-42-generic     grub/                         System.map-4.15.0-42-generic  vmlinuz-4.15.0-43-generic
config-4.15.0-42-generic  initrd.img-4.15.0-42-generic  System.map-4.15.0-43-generic
config-4.15.0-43-generic  retpoline-4.15.0-42-generic   vmlinuz-4.15.0-42-generic

我看到了System.map-4.15.0-42-generic并且System.map-4.15.0-43-generic但是没有System.map-4.8.0-59-generic......

我的服务器似乎启动正常(毕竟它现在正在运行),但我现在不太想测试它......有什么办法可以解决这个问题吗?

答案1

这是initramfs-tools此链接中打开的一个错误:https://bugs.launchpad.net/ubuntu/+source/initramfs-tools/+bug/1776652

在这个特定案例中,它是由/usr/share/initramfs-tools/hooks/kmod

#!/bin/sh -e
# Copy the compatibility symlinks until initramfs-tools will be converted
# to use the kmod program.

if [ "$1" = "prereqs" ]; then exit 0; fi

. /usr/share/initramfs-tools/hook-functions

copy_exec /bin/kmod
cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/

mkdir -p $DESTDIR/lib/modprobe.d/
if [ "$(echo /lib/modprobe.d/*)" != "/lib/modprobe.d/*" ]; then
  cp -a /lib/modprobe.d/* $DESTDIR/lib/modprobe.d/
fi

注释此行

 #cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/

技巧update-initramfs命令来绕过错误。

相关内容