Thursday, September 2, 2010

Live migrating Ubuntu to Debian - howto

0. Prerequisites
You'll need:
- unlocked root acount,
- about 4 GB of disk space,
- pen and paper to take notes about things that failed and need to be repaired later,
- ability to ignore warnings and error messages, some of them pretty serious
- about 6 hours, excluding download time (I have a Debian mirror next room, so dowloads are almost instantenous)
1. Logout from your desktop environment
Switch to console (Alt-Ctrl-F1). Login as root.
The idea is to run as few apps as possible, but don't switch to single user mode - you might need virtual terminals.
2. Remove some software
This kind of migration is tough on your package manager. Some packages are newer in Debian, some are older. Some apps are divided between several packages in a different way. Files belong to another package. There's no way Apt will get everything right. To make its life easier I removed several apps. The point is to remove only a few apps (you'll have to reinstall them later) with lots of dependencies.
My choice was:
- KDE apps - I use Gnome and only a handful of KDE apps - by removing them I got rid of dozens of KDE libs
- build-essential and dkms - this removed all compilers and development libraries
- texmaker - it removed all the LaTeX stuff that I rarely use anyway
- chromium, firefox, openoffice.org, gimp
- gdm - depends on Ubuntu-specific packages
- Ubuntu-specific software: apport, software-center, indicator, usb-creator-gtk, plymouth, everything with ubuntu in its name.
Note that I couldn't remove all these at one point - some of the apps would remove too much. If that's your case, skip it and try again later.
3. Remove dependencies
Get rid of unnecesary libraries with:
apt-get autoremove
orphaner
If the latter gives "command not found", apt-get install deborphan.
4. Change /etc/apt/sources.list
Add Debian Squeeze repositories (choose a mirror close to you) and whatever you may need, I added unnoficial Multimedia repo:
deb http://www.debian-multimedia.org/ squeeze main non-free
5. Install Debian package signing keys
Apt will complain about untrusted packages. Start by:
apt-get update
apt-get install debian-archive-keyring debian-multimedia-keyring
For some reasons it wasn't enough on my box, I had to install the key manually:
gpg --recv-keys 9AA38DCD55BE302B --keyserver subkeys.pgp.net
gpg --export 9AA38DCD55BE302B | apt-key add -
6. First Big Cycle - upgrade packages that are newer in Debian
There's no way you'll get all the packages reinstalled in one try. My way was to reinstall some packages, fix errors, remove unneeded dependencies, try again. The cycle looks like this:
- [upgrade command]
- apt-get -f install
- [manual fix]
- apt-get autoremove
- orphaner
 What's an upgrade command? There's a subtle difference in the way apt-get and aptitude resolve dependencies. I did apt-get upgrade first. It only deals with easy cases, so it'll upgrade a few packages in one cycle. When it can't find anything to upgrade, switch to apt-get dist-upgrade. Try it for a few cycles, than do aptitude dist-upgrade.
 After installing a few packages, upgrade command will fail. First try automatic repair with apt-get -f install. If it still doesn't work, see what the problem is. Usually a package tries to overwrite a file that's also present in another package. Install it manually, using dpkg and full path to the package file:
dpkg -i --force-all /var/cache/apt/archives/package-name.deb
You can also remove Ubuntu version and install the Debian package next. Again, use dpkg instead of apt-get, --remove packagename will remove the software, but leave the config files intact, --purge will also remove configuration and often works better. See also fixes for specific packages at the end of this howto. Write down any problems, maybe the best way is to remove the package and reinstall later.
If there are no partially installed packages, remove crud with apt and orhpaner and upgrade some more. You might run apt-get clean at the end of the cycle if you're low on disk space.
7. Prepare for downgrade
Edit /etc/apt/preferences, create the file if it doesn't exist.
Package: *
Pin: release o=Debian
Pin-Priority: 1001
Package: *
Pin: release o=Ubuntu
Pin-Priority: 600
Package: *
Pin: release o=Unknown
Pin-Priority: 600
Exact numbers don't matter, just keep Debian priority higher than 1000, it means that matching packages will be installed even if it means downgrading.
7. Second Big Cycle - downgrade packages
This works the same as the first cycle, only now the upgrade command will do a downgrade. Don't forget apt-get autoremove and orphaner.
8. Check if all packages have been replaced
apt-get install apt-show versions
apt-show-versions | grep -v squeeze
This will show all packages that don't come from Debian Squeeze. There might be some claiming to belong to Lenny, that's OK.
9. Make sure your system will boot.
See if grub and init scripts upgraded correctly. Only then reboot to Debian.
10. Fix your system.
Check config files, install back packages that you removed. Remember that Firefox was renamed to Iceweasel in Debian.
Appendix - problems with specific packages
Locales
Got loads of messages about unsupported locale. Solution:
locale-gen
dpkg-reconfigure locales
mysql-client, sane-utils, python-gnomecanvas, grub-pc
Remove and install back.
Printing system
apt-get remove cups ghostscript
dpkg --purge cups-pdf
Install back later.
Unusuable X
At first X wouldn't start at all, than I got locked keyboard. I purged and installed back many packages before I got it to work. Only some of them were needed, also I attempted to remove some multiple times (won't hurt to remove a package that's not installed), that's the essence I got from my .bash_history:
dpkg --purge --force-all hal dbus udev xserver-xorg
aptitude --purge remove x11-apps x11-session-utils x11-server-utils xauth xbase-clients xinit xorg
dpkg --purge --force-all dbus dbus-x11 hal udev desktop-base hardinfo libx11-data x11-common x11-utils x11-xfs-utils x11-xkb-utils x11-xserver-utils xfonts-utils xinput xkb
-data xscreensaver-data xserver-common xserver-xorg xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-synaptics xserver-xorg-video-all xs
erver-xorg-video-intel xserver-xorg-video-nouveau xserver-xorg-video-nv gconf2 gconf2-common libice6 libx11-6 libxklavier16 libxrandr2 libxrender1 libxres1 libxt6 libxv1
aptitude install hal dbus udev xserver-xorg xorg xserver-xorg-video-intel xserver-xorg-input-all
Syslog
Didn't work.
dpkg --purge rsyslog
aptitude install rsyslog
Init scripts and networking system
Get rid of upstart first. I had problems with sysv-rc and needed to force reconfiguration. Some init scripts were installed with "dpkg-new" in the name, I had to rename them. As with X, I tried few solutions, this is distilled but stil redundant version:
dpkg-reconfigure sysv-rc
cd /etc/init.d
mv acpid.dpkg-new acpid
mv anacron.dpkg-new anacron
mv atd.dpkg-new atd
mv cron.dpkg-new cron
mv dbus.dpkg-new dbus
mv module-init-tools.dpkg-new module-init-tools
mv procps.dpkg-new procps
mv rsyslog.dpkg-new rsyslog
mv udev-mtab udev
dpkg --purge --force-all base-files ifupdown initscripts netbase sysv-rc sysvinit sysvinit-utils
apt-get --reinstall install base-files ifupdown initscripts netbase sysv-rc sysvinit sysvinit-utils
At one point, dpkg started complaining about missing '/sbin/update-rc.d'. I couldn't install anything until I did:
touch /sbin/update-rc.d
chmod +x /sbin/update-rc.d

3 comments:

  1. Thx for interesting post. Might be usefull in future.

    ReplyDelete
  2. And then when you are done, you are left with some kind of frankendebian that neither the debian community nor the ubuntu community will want to support.

    ReplyDelete