Ubuntu – How to apt-get -y dist-upgrade without a grub config prompt

amazon ec2aptgrub2

Per Make apt-get (or aptitude) run with -y but not prompt for replacement of configuration files?

I did the following:

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

On the machine:

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

I still get a prompt asking me which config file I want to use. These are the lines that come before the prompt:

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

then:

                         ┌───────────────────────────────────────────────────────┤ 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                                                        │                              

Best Answer

The /etc/default/grub file is generated at package install time, which is necessary because it integrates with debconf. This means that it can not treated as a dpkg conf file, and so dpkg's configuration file handling doesn't know about it.

Instead, it uses ucf, a more sophisticated Debian tool for handling configuration. This, unfortunately, doesn't understand dpkg options, so setting Dpkg::Options::="--force-confdef" won't help. It does have its own way of doing no-prompt upgrades, though, through the UCF_FORCE_CONFFNEW and UCF_FORCE_CONFFOLD environment variables.

ucf uses debconf for prompting, so setting the debconf interface to noninteractive will also silence the message. If you really want non-interactive updates you'll need to do this anyway - arbitrary packages may ask debconf questions (although they generally won't during upgrades).

You can set the debconf interface as a one-off by adding DEBIAN_FRONTEND=noninteractive to your environment, or can set it permanently by running dpkg-reconfigure debconf and selecting the noninteractive frontend. If you're using the noninteractive frontend you'll get the default answer for any questions a package might ask.

For ucf, the default answer is “keep the existing file”.

So, the full command to do a really, 100% guaranteed¹ no-prompting update would be.

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

¹: It's technically possible for packages to use another method of prompting than debconf, but this is against Debian policy. If you run across such a package, file a bug.