There is a very similar question here "How do I apt-get -y dist-upgrade without a grub config prompt?" about updating grub without the prompt using apt-get.

However I would like to to know how to install grub2 with apt-get on a brand new image. I am preparing virtual machine disk images starting with debootstrap and going from there.

I would like to install the grub2 software on an image - but not configure it or install it on the boot sector at all ; a later script takes care of configuration and installation proper.

How can I do this?


Answering my own question - I have found I can do it like this:

echo "grub-pc grub-pc/install_devices_empty   boolean true" | debconf-set-selections
DEBIAN_FRONTEND=text apt-get -y install grub2

My case may be a little different, but I had interactive questions from the installer when upgrading my freshly created VMs This ruined the automation, and finding how to get rid of it was quite hard, so here is what I did around my upgrade :

sed -i "s/#\ conf_force_conffold=YES/conf_force_conffold=YES/g" /etc/ucf.conf
apt-get -y upgrade
sed -i "s/conf_force_conffold=YES/#conf_force_conffold=YES/g" /etc/ucf.conf

It removes the interactivity ONLY for the time of my upgrade, which in that case, is produced by ucf, and not debconf.
By the way, you may also edit files manually if you prefer, but I tend to convert everything to copy/pastable, since it makes life waaaaaaaaay easier.

I use Ubuntu 16.04


Your question may be almost two years old, but I believe I have a better answer that I should share.

Don't install grub2 or grub-pc. Install grub-pc-bin and grub2-common.

grub-install and update-grub are provided by grub2-common, but all the debconf and ucf stuff is provided by grub-pc.

But be warned that grub-pc is a recommended package for most (all?) kernel image packages, so you have to install the kernel image and any kernel image upgrades with the --no-install-recommends option.

Notice the use of the --assume-yes option as well, so apt-get can run noninteractively.


sudo apt-get update
sudo apt-get install --assume-yes --no-install-recommends linux-image-virtual grub-pc-bin grub2-common
sudo grub-install /dev/sdX
sudo update-grub


sudo apt-get update
sudo apt-get dist-upgrade --assume-yes --no-install-recommends

Hope this helps!!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.