dpkg-query:错误:软件包‘grub-legacy-ec2’未安装

dpkg-query:错误:软件包‘grub-legacy-ec2’未安装
root@sites:~# apt-get update
Reading package lists... Done
root@sites:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  linux-modules-4.15.0-62-generic linux-modules-4.15.0-64-generic linux-modules-4.15.0-65-generic
  linux-modules-4.15.0-66-generic linux-modules-4.15.0-70-generic
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up linux-image-4.15.0-72-generic (4.15.0-72.81) ...
Setting up linux-image-unsigned-5.4.2-050402-generic (5.4.2-050402.201912042231) ...
Processing triggers for linux-image-4.15.0-72-generic (4.15.0-72.81) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-72-generic
cryptsetup: WARNING: failed to detect canonical device of /dev/sda1
cryptsetup: WARNING: could not determine root device from /etc/fstab
/etc/kernel/postinst.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0
Testing for an existing GRUB menu.lst file ...

Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub-legacy-ec2: line 1101: read: read error: 0: Bad file descriptor
run-parts: /etc/kernel/postinst.d/x-grub-legacy-ec2 exited with return code 1
dpkg: error processing package linux-image-4.15.0-72-generic (--configure):
 installed linux-image-4.15.0-72-generic package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-unsigned-5.4.2-050402-generic (5.4.2-050402.201912042231) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.2-050402-generic
cryptsetup: WARNING: failed to detect canonical device of /dev/sda1
cryptsetup: WARNING: could not determine root device from /etc/fstab
/etc/kernel/postinst.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0
Testing for an existing GRUB menu.lst file ...

Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub-legacy-ec2: line 1101: read: read error: 0: Bad file descriptor
run-parts: /etc/kernel/postinst.d/x-grub-legacy-ec2 exited with return code 1
dpkg: error processing package linux-image-unsigned-5.4.2-050402-generic (--configure):
 installed linux-image-unsigned-5.4.2-050402-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-72-generic
 linux-image-unsigned-5.4.2-050402-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

root@sites:/boot/grub# cp * backup
cp: -r not specified; omitting directory 'backup'
cp: -r not specified; omitting directory 'fonts'
cp: -r not specified; omitting directory 'i386-pc'
cp: -r not specified; omitting directory 'locale'
root@sites:/boot/grub# rm menu.lst
root@sites:/boot/grub# rm default
root@sites:/boot/grub# mv /etc/kernel/postrm.d/x-grub-legacy-ec2 backup
root@sites:/boot/grub# dpkg --configure -a
Setting up linux-image-4.15.0-72-generic (4.15.0-72.81) ...
Setting up linux-image-unsigned-5.4.2-050402-generic (5.4.2-050402.201912042231) ...
Processing triggers for linux-image-4.15.0-72-generic (4.15.0-72.81) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-72-generic
cryptsetup: WARNING: failed to detect canonical device of /dev/sda1
cryptsetup: WARNING: could not determine root device from /etc/fstab
/etc/kernel/postinst.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0
/usr/sbin/update-grub-legacy-ec2: line 556: grub-set-default: command not found
run-parts: /etc/kernel/postinst.d/x-grub-legacy-ec2 exited with return code 127
dpkg: error processing package linux-image-4.15.0-72-generic (--configure):
 installed linux-image-4.15.0-72-generic package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-unsigned-5.4.2-050402-generic (5.4.2-050402.201912042231) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.2-050402-generic
cryptsetup: WARNING: failed to detect canonical device of /dev/sda1
cryptsetup: WARNING: could not determine root device from /etc/fstab
/etc/kernel/postinst.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0
/usr/sbin/update-grub-legacy-ec2: line 556: grub-set-default: command not found
run-parts: /etc/kernel/postinst.d/x-grub-legacy-ec2 exited with return code 127
dpkg: error processing package linux-image-unsigned-5.4.2-050402-generic (--configure):
 installed linux-image-unsigned-5.4.2-050402-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-72-generic
 linux-image-unsigned-5.4.2-050402-generic
root@sites:/boot/grub#

 dpkg -l | grep grub
ic  grub-common                                2.02-2ubuntu8.14                                         amd64        GRand Unified Bootloader (common files)
ic  grub-pc                                    2.02-2ubuntu8.14                                         amd64        GRand Unified Bootloader, version 2 (PC/BIOS version)

无法删除或安装任何东西...我有点卡住了。

root@sites:/# apt install --reinstall initramfs-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-modules-4.15.0-62-generic linux-modules-4.15.0-64-generic linux-modules-4.15.0-65-generic
  linux-modules-4.15.0-66-generic linux-modules-4.15.0-70-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  linux-image-4.15.0-62-generic linux-image-4.15.0-64-generic linux-image-4.15.0-65-generic linux-image-4.15.0-66-generic
  linux-image-4.15.0-70-generic
0 upgraded, 0 newly installed, 1 reinstalled, 5 to remove and 0 not upgraded.
7 not fully installed or removed.
Need to get 9,568 B of archives.
After this operation, 41.9 MB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 initramfs-tools all 0.130ubuntu3.9 [9,568 B]
Fetched 9,568 B in 0s (56.6 kB/s)
(Reading database ... 211144 files and directories currently installed.)
Removing linux-image-4.15.0-62-generic (4.15.0-62.69) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-62-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
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/vmlinuz-5.4.2-050402-generic
Found kernel: /boot/vmlinuz-5.2.14-050214-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-70-generic
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
dpkg: error processing package linux-image-4.15.0-62-generic (--remove):
 installed linux-image-4.15.0-62-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-4.15.0-64-generic (4.15.0-64.73) ...
/var/lib/dpkg/info/linux-image-4.15.0-64-generic.postrm ... removing pending trigger
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-64-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
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/vmlinuz-5.4.2-050402-generic
Found kernel: /boot/vmlinuz-5.2.14-050214-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-70-generic
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
dpkg: error processing package linux-image-4.15.0-64-generic (--remove):
 installed linux-image-4.15.0-64-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-4.15.0-65-generic (4.15.0-65.74) ...
/var/lib/dpkg/info/linux-image-4.15.0-65-generic.postrm ... removing pending trigger
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-65-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
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/vmlinuz-5.4.2-050402-generic
Found kernel: /boot/vmlinuz-5.2.14-050214-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-70-generic
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
dpkg: error processing package linux-image-4.15.0-65-generic (--remove):
 installed linux-image-4.15.0-65-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-4.15.0-66-generic (4.15.0-66.75) ...
/var/lib/dpkg/info/linux-image-4.15.0-66-generic.postrm ... removing pending trigger
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-66-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
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/vmlinuz-5.4.2-050402-generic
Found kernel: /boot/vmlinuz-5.2.14-050214-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-70-generic
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
dpkg: error processing package linux-image-4.15.0-66-generic (--remove):
 installed linux-image-4.15.0-66-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-4.15.0-70-generic (4.15.0-70.79) ...
/var/lib/dpkg/info/linux-image-4.15.0-70-generic.postrm ... removing pending trigger
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-70-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
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/vmlinuz-5.4.2-050402-generic
Found kernel: /boot/vmlinuz-5.2.14-050214-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-70-generic
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
dpkg: error processing package linux-image-4.15.0-70-generic (--remove):
 installed linux-image-4.15.0-70-generic package post-removal script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-62-generic
 linux-image-4.15.0-64-generic
 linux-image-4.15.0-65-generic
 linux-image-4.15.0-66-generic
 linux-image-4.15.0-70-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

安全第一。备份,备份,备份。

sudo rm /boot/grub/menu.lst 

并且 sudo rm /etc/kernel/postrm.d/x-grub-legacy-ec2

sudo rm /boot/grub/default

然后尝试sudo dpkg --configure -a,没有错误?

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

之后,我们在 MBR 中安装引导代码(sudo dpkg-reconfigure grub-pc 如果您只有一个硬盘,/dev/sda 就是正确的位置)。

答案2

您遇到的错误非常容易解释:

dpkg-query: error: package 'grub-legacy-ec2' is not installed

我认为您确实需要安装该软件包。尝试安装后再试一次? sudo apt install grub-legacy-ec2

答案3

就我而言,我对上述内容做了一些改动:

  1. 除了 postrm.d 之外,我还删除了 /etc/kernel/postinst.d/x-grub-legacy-ec2

  2. 4.15 内核似乎来自 linux-image-virtual -package。我已将其删除,但错误仍然存​​在。然后我编辑了 /boot/grub/menu.lst 并删除了所有指出内核版本 4.15 的条目(指向不存在的文件)。

相关内容