Ubuntu do-release-upgrade (unattended)

Cookbook

If a virtual machine

  • Power off vm
  • On the hypervisor (kvm/virsh)
  • virsh list
    • Make sure vm is down
  • cd /var/lib/libvirt/images
  • cp -av --sparse=always myserver-root.qcow2 myserver-root.qcow2_2025-08-05_before_ubuntu2204
    • also copy other partitions if necessary
  • Make sure vm has >= 1GB RAM for modern Ubuntu
  • virsh start myserver

Ubuntu Upgrade

On the actual server/vm:

Make sure apt mirrors work:

  • apt update
  • If anything fails, fix it first! 
  • E.g. use local mirrors like

Prep:

  • cat /etc/apt/apt.conf.d/local 
    • Should have, if not add with editor:
    • DPkg::options { "--force-confdef"; "--force-confold"; }
  • Stop services
    • sudo systemctl stop cron

  • Make sure at least 3GB free space on /

    • df -h

    • ncdu

    • journalctl --vacuum-size=100M

    • apt get clean

Do it:

  • screen
    • In case your connection drops
  • DEBIAN_FRONTEND=noninteractive do-release-upgrade -f DistUpgradeViewNonInteractive |& tee ~/do-release-upgrade.log
  • In case of problems check log:
    • sudo less +G /var/log/dist-upgrade/main.log

Post:

  • To make sure system boots, force grub install
  • Find device:
    • echo "$(lsblk -no PKNAME "$(findmnt -no SOURCE /)" | sed 's|^|/dev/|')"

  • grub-install /dev/xxx
  • update-grub
  • reboot

Checks:

  • systemctl status --no-pager

  • systemctl --failed

  • journalctl -p 3 -xb

Cleanup:

  • sudo apt autoremove --purge -y

  • sudo apt clean

  • sudo apt autoclean


apt upgrade without questions

  • vi /etc/apt/apt.conf.d/local

    • DPkg::options { "--force-confdef"; "--force-confold"; }
  • apt update
  • DEBIAN_FRONTEND=noninteractive apt --yes -o Dpkg::Options='--force-confdef --force-confold' dist-upgrade
    • --force-confdef = select default option @questions
    • --force-confold = if no default -> use old config

Do a release update and accept defaults (=no to new config files)

  • vi /etc/apt/apt.conf.d/local
    • DPkg::options { "--force-confdef"; "--force-confold"; }
  • DEBIAN_FRONTEND=noninteractive do-release-upgrade -f DistUpgradeViewNonInteractive |& tee ~/do-release-upgrade.log

 

Handling of 3rd party repositories

troubleshooting

  • log files are in
    • /var/log/dist-upgrade
  • resume interrupted upgrade with
    • dpkg --configure -a
  • unattended do-release-update does not seem to output error messages.
  • list of possible errors:
    • After updating your package information, the essential package
      'ubuntu-minimal' could not be located. This may be because you have
      no official mirrors listed in your software sources, or because of
      excessive load on the mirror you are using. See /etc/apt/sources.list
      for the current list of configured software sources.
      In the case of an overloaded mirror, you may want to try the upgrade
      again later.


      Restoring original system state

Ansible playbook

https://www.jeffgeerling.com/blog/2018/ansible-playbook-upgrade-all-ubuntu-1204-lts-hosts-1404-or-1604-1804-etc