grub-common 修复失败

use*_*426 6 apt dpkg

我有问题apt-get。当我尝试更新系统时发生了一些错误,并且当我尝试修复它apt-get install -f时失败并显示以下消息:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
    grub-common
Suggested packages:
    multiboot-doc grub-emu xorriso desktop-base
The following packages will be upgraded:
    grub-common
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
24 not fully installed or removed.
Need to get 0 B/1,706 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 315805 files and directories currently installed.)
preparing to unpack .../grub-common_2.02~beta2-36ubuntu3.1_amd64.deb ...
Failed to stop grub-common.service: Unit grub-common.service not loaded.
invoke-rc.d: initscript grub-common, action "stop" failed.
dpkg: warning: subprocess old pre-removal script returned error exit status 5
dpkg: trying script from the new package instead ...
Failed to stop grub-common.service: Unit grub-common.service not loaded.
invoke-rc.d: initscript grub-common, action "stop" failed.
dpkg: error processing archive /var/cache/apt/archives/grub-common_2.02~beta2-36ubuntu3.1_amd64.deb (--unpack):
 subprocess new pre-removal script returned error exit status 5
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Failed to start grub-common.service: Unit grub-common.service not found.
invoke-rc.d: initscript grub-common, action "start" failed.
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 5
Errors were encountered while processing:
 /var/cache/apt/archives/grub-common_2.02~beta2-36ubuntu3.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

如果我检查服务的状态,service grub-common status我会得到这个:

grub-common.service
  Loaded: not-found (Reason: Not a directory)
  Active: inactive (dead)
Run Code Online (Sandbox Code Playgroud)

我搜索了 grub-common,apt search "grub-" |grep inst我得到了这个:

grub-gfxpayload-lists/xenial,now 0.7 amd64 [installed]
   Handles update-grub for ec2 instances
grub-pc/xenial-updates,now 2.02~beta2-36ubuntu3.1 amd64 [installed]
grub-pc-bin/xenial-updates,now 2.02~beta2-36ubuntu3.1 amd64 [installed]
Run Code Online (Sandbox Code Playgroud)

我如何解决它?

And*_*tto 7

解释

Failed to stop grub-common.service: Unit grub-common.service not loaded.
invoke-rc.d: initscript grub-common, action "stop" failed.
dpkg: warning: subprocess old pre-removal script returned error exit status 5
dpkg: trying script from the new package instead ...
Run Code Online (Sandbox Code Playgroud)

包管理器正在尝试停止grub-common服务,但是您的系统处于不一致状态并且失败。的预删除脚本grub-common位于此处:

/var/lib/dpkg/info/grub-common.prerm
Run Code Online (Sandbox Code Playgroud)

它以以下部分结束,在我的系统上:

# Automatically added by dh_installinit
if [ -x "/etc/init.d/grub-common" ] || [ -e "/etc/init/grub-common.conf" ]; then
        invoke-rc.d grub-common stop || exit $?
fi
# End automatically added section
Run Code Online (Sandbox Code Playgroud)

如您所见,它正在测试两个文件(/etc/init.d/grub-common/etc/init/grub-common.conf)中的任何一个是否存在,并invoke-rc.d grub-common stop在它们存在时执行。此命令失败。

路线

重命名上述文件以保留它们但“停用”它们:

sudo mv /etc/init.d/grub-common /etc/init.d/grub-common.bak
sudo mv /etc/init/grub-common.conf /etc/init/grub-common.conf.bak
Run Code Online (Sandbox Code Playgroud)

如果这两个命令之一失败,请不要担心。

在此步骤之后,您应该能够使用以下方法修复软件包:

sudo apt-get install -f
Run Code Online (Sandbox Code Playgroud)