升级后出现此错误

升级后出现此错误

最近升级后我收到此错误消息:

dpkg: dependency problems prevent configuration of initramfs-tools:
 initramfs-tools depends on initramfs-tools-bin (<< 0.99ubuntu13.2.1~); however:
  Version of initramfs-tools-bin on system is 0.103ubuntu0.2.
 klibc-utils (2.0.1-1ubuntu2) breaks initramfs-tools (<< 0.103) and is installed.
  Version of initramfs-tools to be configured is 0.99ubuntu13.2.
dpkg: error processing initramfs-tools (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of plymouth:
 plymouth depends on initramfs-tools; however:
  Package initramfs-tools is not configured yet.
dpkg: error processing plymouth (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of mountall:
 mountall depends on plymouth; however:
  Package plymouth is not configured yet.
dpkg: error processing mountall (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              No apport report written because MaxReports is reached already
      No apport report written because MaxReports is reached already
                                                                    dpkg: dependency problems prevent configuration of initscripts:
 initscripts depends on mountall (>= 2.28); however:
  Package mountall is not configured yet.
dpkg: error processing initscripts (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of upstart:
 upstart depends on initscripts; however:
  Package initscripts is not configured yet.
 upstart depends on mountall; however:
  Package mountall is not configured yet.
dpkg: error processing upstart (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of passwd:
 passwd depends on upstart-job; however:
  Package upstart-job is not installed.
  Package upstart which provides upstart-job is not configured yet.
dpkg: error processing passwd (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              No apport report written because MaxReports is reached already
      No apport report written because MaxReports is reached already
                                                                    Errors were encountered while processing:
 initramfs-tools
 plymouth
 mountall
 initscripts
 upstart
 passwd
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

打开终端并执行以下命令:

sudo apt-get autoremove
sudo apt-get --purge remove && sudo apt-get autoclean
sudo apt-get -f install
sudo dpkg-reconfigure -a

最后一个命令需要一些时间,具体取决于系统中安装的软件包。所以请耐心等待。如果您没有任何损坏/残留的软件包,它将静默执行,不会显示任何消息。

sudo apt-get update
sudo apt-get upgrade && sudo apt-get dist-upgrade
sudo dpkg-reconfigure -a
sudo dpkg --configure -a
sudo update-initramfs -u

然后重新启动系统。

答案2

我的一行代码用于删除旧内核(这也可以释放磁盘空间):

dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

解释(记住,|使用前一个命令的输出作为下一个命令的输入)

  • dpkg --list列出所有已安装的包
  • grep linux-image查找已安装的 Linux 映像
  • awk '{ print $2 }'只输出第二列(即包名称)
  • sort -V按版本号对项目进行排序
  • sed -n '/'`uname -r`'/q;p'打印当前内核之前的行
  • xargs sudo apt-get -y purge清除找到的内核

取消sed调用:

  • -n告诉sed要安静
  • `uname -r`输出当前安装的内核版本 - 我们将其包含在反引号中,以便输出作为命令的一部分(您可能还会看到它为$(uname -r)
  • /something/q说当你匹配“某物”时停止(在这种情况下,某物是的输出uname -r) -/围绕一个正则表达式
  • p是打印
  • ;命令分隔符,所以/something/q;p当你匹配某些东西时就表示退出,否则打印

总之,sed -n '/'`uname -r`'/q;p'就是打印行直到与当前内核名称匹配。

如果您很偏执(像我一样),您可以制作最后一部分xargs echo sudo apt-get -y purge,以便打印清除旧内核的命令,然后您可以在运行它之前检查是否包含任何意外内容。


修改后的版本删除了标题:

dpkg --list | grep 'linux-image' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y purge
dpkg --list | grep 'linux-headers' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y purge

注意:sed调用已被修改。"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"仅提取版本(例如“3.2.0-44”),而不提取“-generic”或类似内容uname -r


删除图像和标题的一体化版本(结合了上面的两个版本):

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge

相关内容