18.04 Xubuntu:修复未满足的依赖项(linux-images、linux-modules)?

18.04 Xubuntu:修复未满足的依赖项(linux-images、linux-modules)?

我在 Xubuntu 18.04 中遇到了一个很奇怪的问题...之后我运行了以下命令sudo apt update

sudo apt upgrade

但这会导致错误:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 linux-image-5.0.0-36-generic : Depends: linux-modules-5.0.0-36-generic but it is not going to be installed
E: Broken packages

我假设我必须安装 linux-modules-5.0.0-36-generic,但我不确定,而且我会做坏事...我只是 Linux 环境的初学者。

一些细节:

uname -a
>>Linux mistapopo-Aspire-A515-52G 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

当我运行以下命令时

sudo apt update 
sudo apt dist-upgrade

我收到以下日志:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  libllvm8
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
5 not fully installed or removed.
Need to get 0 B/8 426 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up linux-image-unsigned-5.3.1-050301-generic (5.3.1-050301.201909210632) ...
Setting up linux-image-5.3.0-28-generic (5.3.0-28.30~18.04.1) ...
Setting up linux-image-5.3.0-26-generic (5.3.0-26.28~18.04.1) ...
Setting up linux-image-unsigned-5.3.1-050301-lowlatency (5.3.1-050301.201909210632) ...
Processing triggers for linux-image-unsigned-5.3.1-050301-generic (5.3.1-050301.201909210632) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.3.1-050301-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.1-050301-lowlatency
Found initrd image: /boot/initrd.img-5.3.1-050301-lowlatency
Found linux image: /boot/vmlinuz-5.3.1-050301-generic
Found initrd image: /boot/initrd.img-5.3.1-050301-generic
Found linux image: /boot/vmlinuz-5.3.0-28-generic
Found initrd image: /boot/initrd.img-5.3.0-28-generic
Found linux image: /boot/vmlinuz-5.3.0-26-generic
Found initrd image: /boot/initrd.img-5.3.0-26-generic
Found linux image: /boot/vmlinuz-5.0.0-37-generic
Found initrd image: /boot/initrd.img-5.0.0-37-generic
Found linux image: /boot/vmlinuz-5.0.0-36-generic
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
/usr/sbin/grub-mkconfig: 295: /usr/sbin/grub-mkconfig: /usr/bin/grub-script-check: not found
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-unsigned-5.3.1-050301-generic (--configure):
 installed linux-image-unsigned-5.3.1-050301-generic package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-5.3.0-28-generic (5.3.0-28.30~18.04.1) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.3.0-28-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.1-050301-lowlatency
Found initrd image: /boot/initrd.img-5.3.1-050301-lowlatency
Found linux image: /boot/vmlinuz-5.3.1-050301-generic
Found initrd image: /boot/initrd.img-5.3.1-050301-generic
Found linux image: /boot/vmlinuz-5.3.0-28-generic
Found initrd image: /boot/initrd.img-5.3.0-28-generic
Found linux image: /boot/vmlinuz-5.3.0-26-generic
Found initrd image: /boot/initrd.img-5.3.0-26-generic
Found linux image: /boot/vmlinuz-5.0.0-37-generic
Found initrd image: /boot/initrd.img-5.0.0-37-generic
Found linux image: /boot/vmlinuz-5.0.0-36-generic
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
/usr/sbin/grub-mkconfig: 295: /usr/sbin/grub-mkconfig: /usr/bin/grub-script-check: not found
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-5.3.0-28-generic (--configure):
 installed linux-image-5.3.0-28-generic package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-5.3.0-26-generic (5.3.0-26.28~18.04.1) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.3.0-26-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.1-050301-lowlatency
Found initrd image: /boot/initrd.img-5.3.1-050301-lowlatency
Found linux image: /boot/vmlinuz-5.3.1-050301-generic
Found initrd image: /boot/initrd.img-5.3.1-050301-generic
Found linux image: /boot/vmlinuz-5.3.0-28-generic
Found initrd image: /boot/initrd.img-5.3.0-28-generic
Found linux image: /boot/vmlinuz-5.3.0-26-generic
Found initrd image: /boot/initrd.img-5.3.0-26-generic
Found linux image: /boot/vmlinuz-5.0.0-37-generic
Found initrd image: /boot/initrd.img-5.0.0-37-generic
Found linux image: /boot/vmlinuz-5.0.0-36-generic
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
/usr/sbin/grub-mkconfig: 295: /usr/sbin/grub-mkconfig: /usr/bin/grub-script-check: not found
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-5.3.0-26-generic (--configure):
 installed linux-image-5.3.0-26-generic package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-unsigned-5.3.1-050301-lowlatency (5.3.1-050301.201909210632) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.3.1-050301-lowlatency
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.1-050301-lowlatency
Found initrd image: /boot/initrd.img-5.3.1-050301-lowlatency
Found linux image: /boot/vmlinuz-5.3.1-050301-generic
Found initrd image: /boot/initrd.img-5.3.1-050301-generic
Found linux image: /boot/vmlinuz-5.3.0-28-generic
Found initrd image: /boot/initrd.img-5.3.0-28-generic
Found linux image: /boot/vmlinuz-5.3.0-26-generic
Found initrd image: /boot/initrd.img-5.3.0-26-generic
Found linux image: /boot/vmlinuz-5.0.0-37-generic
Found initrd image: /boot/initrd.img-5.0.0-37-generic
Found linux image: /boot/vmlinuz-5.0.0-36-generic
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
/usr/sbin/grub-mkconfig: 295: /usr/sbin/grub-mkconfig: /usr/bin/grub-script-check: not found
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-unsigned-5.3.1-050301-lowlatency (--configure):
 installed linux-image-unsigned-5.3.1-050301-lowlatency package post-installation script subprocess returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-unsigned-5.3.1-050301-generic
 linux-image-5.3.0-28-generic
 linux-image-5.3.0-26-generic
 linux-image-unsigned-5.3.1-050301-lowlatency
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

适用于大多数用户的原始答案:

dpkg尝试完成内核的安装配置时,它会在运行自动生成grub-script-check时运行。如果您的配置文件有问题,它将返回此错误。该错误表示您的目录中的其他 grub 配置文件之一存在语法问题。grub-mkconfig/boot/grub/grub.cfg/etc/default/grub/etc/default/grub.d

如果您最近对任何 grub 配置文件/etc/default/grub或目录中的任何其他文件进行了更改/etc/default/grub.d,则需要更正或删除所做的更改。

修复文件后,运行以下命令:

sudo dpkg --configure -a

或者

sudo apt -f install

这个答案这个详细的例子有关 grub 语法错误的更多信息。


更新:

运行以下命令:

file /usr/bin/grub-script-check

如果返回“没有这样的文件或目录”则运行:

sudo apt install --reinstall grub-common

然后运行:

sudo dpkg --configure -a

或者

sudo apt -f install

每当您遇到“未找到”错误时,您可以在以下位置搜索包含该文件的包名称:packages.ubuntu.com或者你可以使用apt-file 应用程序但要安装apt-file您必须首先启用 Universe 存储库:sudo add-apt-repository; sudo apt update


以下是我解决这个问题的方法。

从输出的末尾开始,我们看到两个非常通用的错误,但这些错误并没有真正告诉我们任何信息:

E: Sub-process /usr/bin/dpkg returned an error code (1)

dpkg: error processing package linux-image-unsigned-5.3.1-050301-lowlatency (--configure):

现在,当我们向上滚动时,我们会看到一个实际的错误,它告诉我们一些事情(语法错误):

Syntax errors are detected in generated GRUB config file.

在这一行上方,我们可以看到这个错误发生的确切时间:

/usr/sbin/grub-mkconfig: 295: /usr/sbin/grub-mkconfig: /usr/bin/grub-script-check: not found

现在,文件名后跟“未找到”通常意味着缺少文件,但我们也有语法错误,表明其中一个 grub 配置文件存在问题。

文件名后的数字( /usr/sbin/grub-mkconfig: 295) 通常表示文件的行号,因此我查看了该文件/usr/sbin/grub-mkconfig,在第 295 行,它引用了grub_script_check(/usr/bin/grub-script-check),后来它说如果返回任何内容则返回语法错误。

在这种情况下,语法错误不是由grub-script-check命令返回的,而是由于未找到命令而返回的grub-script-check,因此没有实际的语法错误。

相关内容