How can I sliently upgrade LXD containers from 16.04 to 18.04 to 20.04?

I’m in a situation where I need to upgrade ~20 LXD containers from 16.04 to 18.04 to 20.04. I’ve created a test container to see how well this will work. Due to the large number of containers, I’d prefer not to sit around answering questions - :triumph:. Google hunting revealed

lxc exec <vm> -- script /dev/null -c do-release-upgrade -f DistUpgradeViewNonInteractive

However, I’m still being prompted to answer questions - not as many as without -f DistUpgradeViewNonInteractive, but still a little annoying.

Question: “Is it possible to have a totally silent upgrade that will take me from 16.04 to 18.04 to 20.04?”

I was hoping to script this - i.e.:

for i in 1 2; do
  lxc exec ...
  #ignore any errors and continue - I'll fix them later when I'm at 20.04
done

–Cheers.

Hi,
Firstly, you have to install apt install ubuntu-release-upgrader-core package to execute the related command do-release-upgrade -f DistUpgradeViewNonInteractive.

for k in $(lxc ls --format csv -c n); do lxc exec $k -- more do-release-upgrade -f DistUpgradeViewNonInteractive; done

Thanks @cemzafer - that was not mentioned in the several places I saw it provided as an answer.

I’ll go back and add notes where I can - like on this askubuntu answer.

EDIT: Before performing the upgrade on the test container, I had created a snapshot. So I decided to restore the snapshot, install ubuntu-release-upgrader-core then redo the do-release-upgrade. Oddly, I got this when I went to install it:

Details
# apt install ubuntu-release-upgrader-core
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ubuntu-release-upgrader-core is already the newest version (1:16.04.32).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.7 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.7 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

From this:

  1. Does it mean that the prompts that came up cannot be silenced?
  2. If I ought not to be getting prompted, should I raise a bug to have this corrected?

–Cheers.

EDIT2:
I noticed you used a different command to mine when doing the upgrade - specifically:

lxc exec testupgrade -- more do-release-upgrade -f DistUpgradeViewNonInteractive

However, for me, that resulted in:

$ lxc exec testupgrade -- more do-release-upgrade -f DistUpgradeViewNonInteractive
more: stat of do-release-upgrade failed: No such file or directory
more: stat of -f failed: No such file or directory
more: stat of DistUpgradeViewNonInteractive failed: No such file or directory

OK - discovered that running the command below from outside the container will result in prompts:

lxc exec testupgrade -- script /dev/null -c do-release-upgrade -f DistUpgradeViewNonInteractive

If I instead execute the command via ssh, I get no prompts and the upgrade successfully completes without prompting:

ssh root@testupgrade bash -s <<<"do-release-upgrade -f DistUpgradeViewNonInteractive"

Takes about 28 minutes to upgrade from 16.04 to 18.04

EDIT - Strike that:
However, attempting to run the command again, to go from 18.04 to 20.04, I got the following output:

$ ssh root@10.12.12.73 bash -s <<<"do-release-upgrade -f DistUpgradeViewNonInteractive"
Checking for a new Ubuntu release
Please install all available updates for your release before upgrading.

On an EC2 instance on AWS it successfully upgraded without these prompts. I suspect that wherever LXC is getting upgrade packages from, they are not the latest hence this error.

In addition, at the end of the upgrade from 16.04 to 18.04, removal of friendly-recovery fails as it is trying to do some grub stuff which of course fails in the container. I have to edit both friendly-recovery.postinst and friendly-recovery.postrm to remove reference to grub for the removal to complete successfully.

After manually installing all pending updates, the container was now at 20.04.3.

I’ll revert the snapshot and run through the process one more time then I’ll be ready to do it on production containers.

–Cheers.

Ohh sorry, this is just a typo, the correct command should be like that, sorry for the inconvenience.

lxc exec $k -- sh -c "/usr/bin/do-release-upgrade -f DistUpgradeViewNonInteractive"

Cheers.