如何在没有grub配置提示的情况下apt-get -y dist-upgrade?

Per Make apt-get(或aptitude)运行-y但不提示更换配置文件?

我做了以下事情:

ec2run ami-3c994355 --region us-east-1 -n 1 -t m1.large -z us-east-1d 

在机器上:

 sudo apt-get update sudo apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade 

我仍然得到一个提示,询问我想要使用哪个配置文件。 这些是提示之前的行:

 Setting up grub-pc (1.99-21ubuntu3.1) ... 

然后:

  ┌───────────────────────────────────────────────────────┤ Configuring grub-pc ├───────────────────────────────────────────────────────┐ │ A new version of configuration file /etc/default/grub is available, but the version installed currently has been locally modified. │ │ │ │ What do you want to do about modified configuration file grub? │ │ │ │ install the package maintainer's version │ 

/etc/default/grub文件是在软件包安装时生成的,这是必要的,因为它与debconf集成在一起。 这意味着它不能被视为dpkg conf文件,因此dpkg的配置文件处理不知道它。

相反,它使用ucf ,一种更复杂的Debian工具来处理配置。 不幸的是,这不了解dpkg选项,因此设置Dpkg::Options::="--force-confdef"将无济于事。 但是,它确实有自己的方式进行无提示升级,通过UCF_FORCE_CONFFNEWUCF_FORCE_CONFFOLD环境变量。

ucf使用debconf进行提示,因此将debconf接口设置为noninteractive也会使消息静音。 如果你真的想要非交互式更新,你无论如何都需要这样做 – 任意包可能会问debconf问题(虽然它们通常不会在升级期间)。

您可以通过将DEBIAN_FRONTEND=noninteractive添加到您的环境中来将debconf接口设置为一次性,或者可以通过运行dpkg-reconfigure debconf并选择非交互式前端来永久设置它。 如果您使用非交互式前端,您将获得包可能会提出的任何问题的默认答案。

对于ucf ,默认答案是“保留现有文件”。

所以,完全命令做一个真正的,100%保证¹无提示更新。

 sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade 

¹:从技术上讲,软件包可以使用另一种提示方法而不是debconf,但这违反了Debian政策。 如果您遇到这样的包,请提交错误。

离开RAOF的答案并且在网上搜索了无数个小时以便能够在Ubuntu 12.04上执行完全不干涉的更新和分散升级之后,我想出了这个post( https:// bug) .launchpad.net / ubuntu / + source / grub / + bug / 239674 / comments / 1 )当你想使用包维护者grub menu.lst而不是任何可能的本地菜单时,指出grub遵守UCF而不是Dpkg选项.lst编辑。

我把Dpkg force-confnew选项留给了不是grub的其他包。

 #!/bin/bash unset UCF_FORCE_CONFFOLD export UCF_FORCE_CONFFNEW=YES ucf --purge /boot/grub/menu.lst export DEBIAN_FRONTEND=noninteractive apt-get update apt-get -o Dpkg::Options::="--force-confnew" --force-yes -fuy dist-upgrade 

以前的解决方案不适用于16.04。 这是关于堆栈溢出的答案 :

 sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" install grub-pc