This is mostly a note to myself on how to remotely upgrade a ubuntu server using ssh. Also available on AskUbuntu.
All of these steps assume your package repository is working. Meaning if you execute apt-get update you are not presented with lots of 404s due to having an outdated version. You need to fix that first, so see this answer for that.
0. Update all existing packages
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
1. Set up passwordless execution
Add myself to the list of users that can execute do-release-upgrade using sudo without entering a password is achieved by executing
sudo visudo -f /etc/sudoers.d/do-release-upgrade.
and adding the following line, substituting my-username for your own of course:
my-username ALL=NOPASSWD: /sbin/reboot, /usr/bin/apt-get, /usr/bin/do-release-upgrade
2. Start incremental upgrades
Log out and execute the following command from your computer. It will do an upgrade without prompting you for input (accepting all default answers), wait for the computer to reboot, and then try upgrading again. It runs until you are upgraded to the latest version.
while true; do ssh -T my-user@my-server << EOF sudo apt-get clean; # clean up after errors sudo apt-get update; # get latest packages sudo apt-get dist-upgrade; # upgrade to latest packages #the all important step: upgrade to next release sudo do-release-upgrade -f DistUpgradeViewNonInteractive; sudo reboot; # restart machine EOF sleep 120; done
The process might stop if some of the following cases arise:
- A package upgrade is broken due to some unsupported deprecated configuration
- You end up on a LTS (Long Term Support) version
In my case, an old, broken config of Squid caused the upgrade process to complain, but actually did not seem to stop it. You better fix whatever it complains about anyway before continuing. What actually stopped my upgrades was that on some point in my distribution upgrades, I ended up on 12.04, which is a LTS. An LTS wil by default only upgrade to the next LTS, which comes every two years. In my case this was fine – the less hassle upgrading, the better, but if you do want the very latest stable version, you have to edit the file
/etc/update-manager/release-upgrades and uncomment the line where it says
3. Fix configuration files to their previous state
Afterwards you will have to move the backed up config files to their previous location as the upgrade process has put default configurations in their place.
Not wanting just the default answers?
This guy has a way to pre-prepare answers for each prompt, but the downside is that you must know how many prompts there are …