How to upgrade anybody's instance of Ubuntu with little pain


To be an advocate of open-source may require you to also be one's technician. You may know what you are doing as an administrator on your own machine, but you may not know what to do with a newbie's machine when you established a LUG between your friends and family a few years back.

This is for people who need to upgrade other people's machines, and want to do so with as little teeth-grittting and nail-biting as possible. If you are just getting into a consultant role commercially, this is also handy information to know so whatever necessary changes can be made before return to a customer.


What to do before beginning

While it is not recommended for the average user to do this. since you will not know the user's password (nor should they share it), you should advise them, if they are trusting you with their data, to unlock access of the system via root. Whenever possible, attempt to gain access of the root user account by use of the passwd command as demonstrated:

:heavy_dollar_sign: In x-terminal-emulator:

sudo passwd root

Once the user enters their account password (no peeking), that is when you should enter your own password, so you can act as root with implied consent. If a user is concerned about data privacy, they're always free to learn about how to handle it themselves, but if you're a close friend consent shouldn't be difficult to acquire.

:hash: From hereon, it is assumed you will be signed in and using root to perform all actions below, hence the exclusion of sudo. If you are following this guide yourself as a regular user, append commands with sudo and if you cock up, sudo !! should work to revise failed commands.

Knowing what to keep

There are many packages which make up a Debian-based Linux system, and a lot of these libraries will be kept or upgraded during the update process to the newest version of Ubuntu. However, there are some packages you will be unable to keep or upgrade during this process because of lacking maintenance or age of software.

:pencil2: Anything shown with a greater-than (>) symbol is entirely up to you. FIlenames shown are expressly for examples shown.

Before committing to the update process, a couple things should be done to ensure once the machine is upgraded, it is returned exactly as they left it, aside from a new Ubuntu version.

Finding held packages
When upgrading, held packages are your worst enemy. Just so the output isn't lost, do this to show all held packages if there are any:

:heavy_dollar_sign: In x-terminal-emulator:

apt-mark showhold > ~/heldpkgs

To remove them, they must first have their hold cancelled. While you can get around this using apt with --allow-change-held-packages there's really no reason why you can't unhold first:

:heavy_dollar_sign: In x-terminal-emulator:

xargs -a ~/heldpkgs apt-mark unhold

:terminal: While -a isn't strictly necessary for xargs now, it will be later on.

Once all holds are released, all held packages (and dependencies) can then be removed as shown:

:heavy_dollar_sign: In x-terminal-emulator:

xargs -a ~/heldpkgs apt remove
apt autoremove

Listing sources
Before continuing, you should have on-hand whatever third-party sources were used for the software on the machine. To retrieve this information, use of tail as a hack to print output of all files in sources.list.d serves this need perfectly;

:heavy_dollar_sign: In x-terminal-emulator:

tail -n +1 /etc/apt/sources.list.d/*.list > ~/3rdpartylist

In case you need it, also get only the list of sources. This can better aid people who think the output of the above is just a bit too cluttered;

:heavy_dollar_sign: In x-terminal-emulator:

ls /etc/apt/sources.list.d/*.list > ~/3rdpartydirs

You should not need anything else — So long you are able to boot into the system and log in as root, you will have everything you need for restoring the intended functionality of somebody else's machine.

Upgrading the system

Typical stuff. But there are some things I do personally as part of my upgrade routine. This is more to just have as few things running as possible during the upgrade process. After logging off;

:heavy_dollar_sign: In a TTY:

service lightdm stop

:x: If do-release-upgrade fails out, try appending -d to the command, which is a hacky way to force an upgrade should a newer release of Ubuntu be available.


Remember that list of held packages? Yeah, you can't use those quite yet, you'll need to open each .list file in /etc/apt/sources.list.d or edit sources using software-properties-gtk. Run apt update to cycle through and make sure all sources are working, and if not then try to figure it out as best you can. You want to eventually get to a point where this can be done to reinstall everything previously on-hold;

:heavy_dollar_sign: In x-terminal-emulator:

xargs -a ~/heldpkgs apt install
xargs -a ~/heldpkgs apt-mark hold

Make sure everything the user wants to run is working. If you absolutely have to, create another user account and sign into that to emulate a regular user. Don't forget to delete the account and all files therein afterward. Once finished, clean up, lock root and get out;

:heavy_dollar_sign: In x-terminal-emulator:

rm -rf ~/heldpkgs ~/3rdparty*
passwd root -ld
systemctl poweroff

:information_source: Information sources

Getting root access:

Build and execute command lines from standard input:

Use of tail to print output at a single file, with headings per-file:

How to upgrade when upgrading isn't an option: