我正在使用 Ubuntu 18.04,并尝试使用 apt 卸载旧内核映像。但是,我收到一条错误消息,提示无法卸载,因为缺少标头。我该如何卸载它们?以下是该命令的部分输出sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-image-extra-3.13.0-39-generic linux-image-extra-3.13.0-40-generic
linux-image-extra-3.13.0-43-generic linux-image-extra-3.13.0-46-generic
linux-image-extra-3.13.0-48-generic linux-image-extra-3.13.0-49-generic
linux-image-extra-3.13.0-52-generic linux-image-extra-3.13.0-53-generic
linux-image-extra-3.13.0-54-generic linux-image-extra-3.13.0-55-generic
linux-image-extra-3.13.0-57-generic linux-image-extra-3.13.0-58-generic
linux-image-extra-3.13.0-59-generic linux-image-extra-3.13.0-61-generic
linux-image-extra-3.13.0-62-generic linux-image-extra-3.13.0-63-generic
linux-image-extra-3.13.0-65-generic linux-image-extra-3.13.0-66-generic
linux-image-extra-3.13.0-68-generic linux-image-extra-3.13.0-77-generic
linux-image-extra-3.13.0-88-generic linux-image-extra-3.13.0-91-generic
linux-image-extra-3.13.0-92-generic linux-image-extra-3.13.0-93-generic
0 upgraded, 0 newly installed, 24 to remove and 14 not upgraded.
24 not fully installed or removed.
After this operation, 3,646 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 459090 files and directories currently installed.)
Removing linux-image-extra-3.13.0-39-generic (3.13.0-39.66) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-39-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-39-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-39-generic
WARNING: missing /lib/modules/3.13.0-39-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-39-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
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-3.13.0-39-generic with
1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.13.0-39-generic (--remove):
installed linux-image-extra-3.13.0-39-generic package post-removal
script subprocess returned error exit status 1
Removing linux-image-extra-3.13.0-40-generic (3.13.0-40.69) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-40-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-40-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-40-generic
WARNING: missing /lib/modules/3.13.0-40-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-40-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
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-3.13.0-40-generic with
1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.13.0-40-generic (--remove):
installed linux-image-extra-3.13.0-40-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-extra-3.13.0-43-generic (3.13.0-43.72) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-43-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0- 43-generic /boot/vmlinuz-3.13.0-43-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-43-generic /boot/vmlinuz-3.13.0-43-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-43-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-43-generic /boot/vmlinuz-3.13.0-43-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-43-generic
WARNING: missing /lib/modules/3.13.0-43-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-43-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
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-3.13.0-43-generic with
1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.13.0-43-generic (--remove):
installed linux-image-extra-3.13.0-43-generic package post-removal script subprocess returned error exit status 1
输出继续这样,最后的部分如下:
dpkg: error processing package linux-image-extra-3.13.0-93-generic (--remove):
installed linux-image-extra-3.13.0-93-generic package post-removal script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
Errors were encountered while processing:
linux-image-extra-3.13.0-39-generic
linux-image-extra-3.13.0-40-generic
linux-image-extra-3.13.0-43-generic
linux-image-extra-3.13.0-46-generic
linux-image-extra-3.13.0-48-generic
linux-image-extra-3.13.0-49-generic
linux-image-extra-3.13.0-52-generic
linux-image-extra-3.13.0-53-generic
linux-image-extra-3.13.0-54-generic
linux-image-extra-3.13.0-55-generic
linux-image-extra-3.13.0-57-generic
linux-image-extra-3.13.0-58-generic
linux-image-extra-3.13.0-59-generic
linux-image-extra-3.13.0-61-generic
linux-image-extra-3.13.0-62-generic
linux-image-extra-3.13.0-63-generic
linux-image-extra-3.13.0-65-generic
linux-image-extra-3.13.0-66-generic
linux-image-extra-3.13.0-68-generic
linux-image-extra-3.13.0-77-generic
linux-image-extra-3.13.0-88-generic
linux-image-extra-3.13.0-91-generic
linux-image-extra-3.13.0-92-generic
linux-image-extra-3.13.0-93-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
答案1
首先,列出系统上所有旧内核
sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`
然后逐个移除旧内核
sudo apt-get purge linux-image-x.xx.x-xx
用正确的内核名称替换linux-image-x.xx.x-xx
。然后运行命令sudo apt autoremove
。之后使用命令更新内核sudo update-grub