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
- vi /etc/apt/sources.list
-
deb http://at.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
-
- ADJUST FOR YOUR VERSON!
- apt update
- vi /etc/apt/sources.list
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
- RELEASE_UPGRADER_ALLOW_THIRD_PARTY=1
- https://www.linuxuprising.com/2019/01/ubuntu-users-can-now-keep-ppas-and.html
- To keep 3rd party repos -> still need to change xenial to bionix though....
- Re-enable 3rd party ppas
- for f in /etc/apt/sources.list.d/*.list; do sed -i 's/xenial/bionic/g' $f; sed -i 's/^# \(.*\) # disabled on upgrade to.*/\1/g' $f;done
- apt update
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-
Solution:
-
Replace /etc/apt/sources.list with original file
-
e.g. for 16.04 Xenial:
-
cp -a /etc/apt/sources.list /etc/apt/sources.list.old;wget --output-document=/etc/apt/sources.list https://gist.githubusercontent.com/rohitrawat/60a04e6ebe4a9ec1203eac3a11d4afc1/raw/fcdfde2ab57e455ba9b37077abf85a81c504a4a9/sources.list && apt update
-
-
Ansible playbook