我无法删除旧内核映像 - Ubuntu 16.04.6 LTS

我无法删除旧内核映像 - Ubuntu 16.04.6 LTS

我的uname -a回报如下。

Linux <hidden> 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

当我尝试升级软件包时,升级失败并显示有关旧内核的以下错误。

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be REMOVED:
  linux-image-3.13.0-68-generic linux-image-extra-3.13.0-68-generic
The following packages have been kept back:
  libapache2-mod-php libapache2-mod-php7.0 libgd3 php-gd php-mbstring php-mysql php-xml php7.0-cli php7.0-common php7.0-curl php7.0-dev php7.0-fpm php7.0-gd
  php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-soap php7.0-tidy php7.0-xml php7.0-xmlrpc php7.0-zip
0 upgraded, 0 newly installed, 2 to remove and 24 not upgraded.
4 not fully installed or removed.
After this operation, 194 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 142623 files and directories currently installed.)
Removing linux-image-extra-3.13.0-68-generic (3.13.0-68.111) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-68-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-68-generic
WARNING: missing /lib/modules/3.13.0-68-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-68-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
depmod: WARNING: could not open /var/tmp/mkinitramfs_30aiDQ/lib/modules/3.13.0-68-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_30aiDQ/lib/modules/3.13.0-68-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
run-parts: executing /etc/kernel/postinst.d/x-grub-legacy-ec2 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/memtest86+.bin
dpkg-query: error: package 'grub-legacy-ec2' is not installed
run-parts: /etc/kernel/postinst.d/x-grub-legacy-ec2 exited with return code 10
dpkg: error processing package linux-image-extra-3.13.0-68-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-3.13.0-68-generic (3.13.0-68.111) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
update-initramfs: Deleting /boot/initrd.img-3.13.0-68-generic
run-parts: executing /etc/kernel/postrm.d/x-grub-legacy-ec2 3.13.0-68-generic /boot/vmlinuz-3.13.0-68-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/memtest86+.bin
dpkg-query: error: package 'grub-legacy-ec2' is not installed
run-parts: /etc/kernel/postrm.d/x-grub-legacy-ec2 exited with return code 10
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.13.0-68-generic.postrm line 328.
dpkg: error processing package linux-image-3.13.0-68-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-3.13.0-68-generic
 linux-image-3.13.0-68-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

编辑:输出apt list --installed | grep grub

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

grub-common/xenial-updates,now 2.02~beta2-36ubuntu3.22 amd64 [installed]
grub-gfxpayload-lists/xenial,now 0.7 amd64 [installed,automatic]
grub-pc/xenial-updates,now 2.02~beta2-36ubuntu3.22 amd64 [installed]
grub-pc-bin/xenial-updates,now 2.02~beta2-36ubuntu3.22 amd64 [installed,automatic]
grub2-common/xenial-updates,now 2.02~beta2-36ubuntu3.22 amd64 [installed,automatic]

答案1

sudo dpkg -P grub-legacy-ec2

删除可能残留的文件。

我最好通过 dpkg 来询问。

如果出现错误,但只有当

sudo mv /etc/kernel/postinst.d/x-grub-legacy-ec2 $HOME

请删除相同的内容

/boot/grub/default

以及

/boot/grub/菜单.lst

然后干燥去除旧内核

sudo dpkg -P linux-image-3.13.0-68-generic linux-image-extra-3.13.0-68-generic

下一步很重要,这样您就不会没有任何引导加载程序。

sudo apt install --reinstall grub-common grub-gfxpayload-lists grub-pc grub-pc-bin grub-pc-bin grub2-common

现在安装 grub2 启动代码。我们不知道 mbr 中存在哪一个。

sudo dpkg-reconfigure grub-pc

grub2

至少

sudo update-grub

相关内容