Ubuntu to Debian
The Problem
Let’s say you have a server running Ubuntu 16.04 and you want to migrate it to a recent Debian release.
And you don’t have physical access, an ILO/IPMI or any other system to reinstall it from scratch.
I wouldn’t recommend doing this on production systems, but if you want to give it a try, here we go:
What to do
First make a backup, you will need it.
Then reboot to see if the system is actually working (better to know if it is broken before you touch it).
Now choose a Debian version that is slightly newer than the Ubuntu version you have installed: https://wiki.debian.org/DebianReleases
For me, I want to migrate from Ubuntu 16.04, so I chose Debian Stretch. I am sure you can go straight to the latest release, but I prefer to change everything in smaller steps to limit possible points of failure.
Add the Debian repos to the sources.list while keeping the Ubuntu sources:
deb http://archive.debian.org/debian/ stretch main contrib non-free
(in this case there is no security and updates repo because it is an archived version, please upgrade to a newer Debian version after this and don’t forget to add the security and updates repos)
Add a /etc/apt/preferences.d/1-ubuntu-to-debian-migration
that deprioritizes the ubuntu packages
Package: *
Pin: release o=Ubuntu
Pin-Priority: -1
(According to man 5 apt_preferences
: “A priority lower than 0 prevents the version from being installed”)
Install the debian-keyring and debian-archive-keyring packages manually by downloading them from here:
- https://packages.debian.org/search?keywords=debian-keyring
- https://packages.debian.org/search?keywords=debian-archive-keyring
Time to run apt update
and then apt full-upgrade
.
Ubuntu packages with higher versions (if any) should get downgraded as necessary and any package that has an equivalent in Debian should get replaced.
During the upgrade you may need to manually remove packages and re-run the upgrade process until all conflicts are resolved.
Remove ubuntu repos from /etc/apt/souces.list
, remove the /etc/apt/preferences.d/1-ubuntu-to-debian-migration
.
Run an apt update
and apt full-upgrade
again to make sure there are no issues.
Now we need to make sure the correct kernel is installed, and grub is updated:
apt install linux-image-amd64
update-grub2
Now you can reboot and everything should come back up.
Cleanup
After this reboot, you will probably need to do some cleanup:
- Remove packages that are not in the Debian repository with
apt purge "~o""
. - Check if any services failed to start due to configuration changes:
systemctl list-units --failed
. - Recompile anything you have compiled yourself.
- Check your python venvs, as there is a good chance that your python version has changed.
After that you should be good to go.
Good luck, you will need it!