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

sudo dpkg-reconfigure grub-pc 之後,我們將引導程式碼安裝在 MBR 中。

答案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 的條目(指向不存在的檔案)。

相關內容