解释

解释

我遇到了问题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)

如果我使用以下命令检查服务状态,service grub-common status则会得到以下信息:

grub-common.service
  Loaded: not-found (Reason: Not a directory)
  Active: inactive (dead)

我搜索了 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]

我如何解决它?

答案1

解释

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 ...

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

/var/lib/dpkg/info/grub-common.prerm

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

# 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

如您所见,它正在测试两个文件(/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

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

完成此步骤后,您应该能够使用以下命令修复软件包:

sudo apt-get install -f

相关内容