Preparing An Ubuntu Machine For Upgrade

The Debian / Ubuntu upgrade mechanism is a wonderful piece of software. When the new release comes out, just follow the instructions given by the update manager and the upgrade will be done almost automatically. Sometimes Ubuntu asks for your help when you made other changes than the upgrade program itself wants to make. This howto gives a few tips on how to make your Ubuntu installation more upgrade-friendly. I tested it on Ubuntu installations, but the mechanisms in this howto should not be different for Debian.


Before the Upgrade

When starting the upgrade, take a pen and a piece of paper. For some packages, you are asked to choose between the original settings file or the package maintainer's version. In that case, write down the name of that file and choose "replace with the package maintainer's version". This is a safe thing to do, as the upgrade program will make a backup of the old file. During the upgrade process, the system is in a half working state, so your favourite diff editor may not work at all. Therefore, we let the upgrade program complete its job first and repair our own settings later.

If you do not already have a favourite diff editor, it is good to install one before starting the upgrade. Personally, I like meld.


Flexible Settings Mechanisms

Some packages come with a settings mechanism that can include a file or a directory. Examples are apache, PHP, gdm and MySQL.
For example, you can put a file in /etc/mysql/conf.d/ to hold the overrides for /etc/mysql/my.cnf. Such a file should contain only the settings that you really want to enforce. So if you just want to run MySQL in another server mode, this file could contain:

# The MySQL database server configuration file, overrides.
# Added myself to make the development environment as strict and talkative as possible:

For MySQL, the overrides file must have the extension .cnf. This can be seen in the installed settings file /etc/mysql/my.cnf. In general, when you are changing a configuration file, read the comments and see if it mentions including other files.

If you work with settings override files, your configuration is split into a "basic" setup that is installed by the package manager and a "detailed" section that hold your own settings. The upgrade program will only touch the basic settings and not your overrides. With this mechanism, the upgrade program does not need to ask you which settings to use.


Programs Unknown to the Package System

Compiling or installing programs that are unknown to the package management system usually poses no problem. But if that software satisfies dependencies for other programs, your package management system may try to force its alternatives on you.
For example, I have The Abyss webserver installed, which did come with an installer, but not as a Debian or Ubuntu package. You can install a lot of packages just fine with a different web server, but some packages are marked as dependent on one and try to install apache with them. And especially since Ubuntu marked recommended packages as dependencies, it has become even harder to keep the default alternatives off your system.

Most programs you install or compile are not alternatives for system services that other packages depend on, so use the following only to keep alternatives from conflicting with your Ubuntu-strange program.

There is a way to let the package manager know you satisfied a dependency with an unknown program. To do this, install the equivs package from the normal repository.

You can use equivs to make a package that has no content, other than dependency information for the package manager. We can make a package that tells the package manager that there is a web server. To do that, open a terminal and make a configuration file:

equivs-control webserver.txt

You now have a configuration file webserver.txt that can be edited to build a .deb package later. A web server is called "httpd" in the package manager, so what must be in the file is at least "Provides: httpd". fill in the other necessary and useful info (the package name and description and your name so you can recognize it immediately), and build a package with:

equivs-build webserver.txt

This will result in a .deb file that you can install using gdebi. Note that the package itself is still not connected with the web server itself. So if you uninstall my web server, you should uninstall the package as well. The package created above is only meant to inform the package manager of a dependency.


After the Upgrade

After the upgrade job has completed, you are asked to restart the computer. This is the time to use your diff editor to merge your own settings with the new defaults. The old files usually get an extension, like .dist-upgrade or .ucf-old. For example, if you use meld as your diff editor and want to repair /etc/samba/smb.conf, go to its directory and start the diff editor with the two files:

cd /etc/samba/
sudo meld smb.conf smb.conf.ucf-dist

You will then see the two files side-by-side with the differences highlighted and the possibility to edit them. Once you have repaired all the settings files you wrote down, it is time to follow your machine's advice and reboot it.


When Things Go Wrong

Normally, the upgrade just takes a while to complete, sometimes asking you to decide about settings files. But occasionally things can go wrong. If your machine stops in the middle of a distribution upgrade, you have no choice but to shut down your computer. This is a scary thing to do, as the system is now in a half-working state: some libraries are installed and upgraded, and some are not. When you reboot your computer after a failed upgrade, the first thing to do is to finish the upgrade. Fortunately, apt-get is very clear in its error messages and will guide you through the rest of the upgrade process. To make apt-get check its state and guide you through the rest of the upgrade, just start a terminal and type:

sudo apt-get update

If you follow the above tips where applicable, you have a system that asks less questions during an upgrade and does not force unwanted alternatives on you for Ubuntu-strange software. Enjoy the next Ubuntu version!

Share this page:

2 Comment(s)