Convert Debian to Ubuntu




Convert Debian to Ubuntu

Convert an existing Debian installation to Ubuntu without reinstalling from scratch.

While the usual approach to switching Linux distributions is to erase your disk and reinstall from scratch, Ubuntu is based on Debian, so it's possible to switch directly from one to the otherprovided you're willing to spend time tweaking and fixing obscure problems. It's even possible to have your computer track both Debian and Ubuntu simultaneously and install packages from one or the other at will.

Perform the Conversion

The naive solution to converting an existing Debian system to Ubuntu is to just edit your /etc/apt/sources.list to switch all the Debian archive references to the equivalent Ubuntu archives and then upgrade all packages. That's a good start, but unfortunately it will most likely leave you with a fairly broken system because many of the libraries in Debian will have newer versions than their equivalents in Ubuntu, so it's necessary to do a bit more work to end up with a usable system.

Edit your /etc/apt/sources.list to comment out all the Debian archives and add entries for the Ubuntu archives. If you need to generate an Ubuntu sources.list file, you can use the "source-o-matic" tool available online at http://www.ubuntulinux.nl/source-o-matic, or you can just put in some basic entries as a starting point:

deb http://archive.ubuntu.com/ubuntu dapper main restricted
deb http://security.ubuntu.com/ubuntu dapper-security main restricted

Then update the package list and install sudo if you don't already have it installed:

# apt-get update
# apt-get install sudo
            

Since Ubuntu relies so much on the primary user having sudo privileges, it's also a good idea to edit your /etc/sudoers by running visudo and adding a line like this:

%admin  ALL=(ALL) ALL

Then place your primary user into the admin group, replacing username with your actual username:

# usermod 
               
                  username
                
               -g admin
            

As a first step to getting all the installed packages in order, you can manually force a reinstall of every package on your system to the specific version available in Ubuntu, but since a typical Debian system has over a thousand packages installed, that can be rather tedious. You can save yourself some time by writing a little script like this:

#!/bin/sh
for name in \Qdpkg --get-selections | grep '[[:space:]]install$' \\
  | awk '{print $1}'\Q
do
   sudo apt-get install --assume-yes ${name}=\Qapt-cache show $name \\
     | grep '^Version' | awk '{print $2}'\Q
done

It's highly likely that some packages you have previously installed from the Debian archives won't "cross-grade" cleanly to the version available in Ubuntu, and you may have to manually uninstall some packages to allow the process to complete. Depending on how your system is set up, you may need to do a lot of poking and prodding to get to the point where:

$ sudo apt-get update
$ sudo apt-get dist-upgrade
            

can execute cleanly.

Once you have your existing packages converted to the Ubuntu versions, it's time to pull in the core Ubuntu packages:

$ sudo apt-get install ubuntu-standard ubuntu-desktop
            

The result won't be perfect, but you should then have a system that is a reasonable approximation of a full Ubuntu install.

Mix Ubuntu and Debian

If you want to be able to install packages from either Debian or Ubuntu at will, you can make use of a package-management feature called pinning, which is designed to allow you to lock packages to specific versions while other packages are upgraded.

Start by adding some basic Debian archive entries to /etc/apt/sources.list:

deb http://ftp.us.debian.org/debian sarge main non-free contrib
deb http://non-us.debian.org/debian-non-US sarge/non-US main contrib non-free

If you don't have one already, create a file called /etc/apt/preferences and put in these entries:

Package: *
Pin: release a=dapper
Pin-Priority: 700

Package: *
Pin: release a=sarge
Pin-Priority: 600

What this does is give the packages in Dapper a higher priority than the packages in Sarge, so if you apt-get install foo a package, the system will try to install the Dapper version of a package if it's available and fall back to using Debian packages if necessary. In reality, the algorithm for determining package priority is rather more complex than a simple priority, and to fully understand it, you should read the apt_preferences manpage (man apt_preferences).

Because apt in Ubuntu uses a new security infrastructure to check package signatures, you will also need to install the Debian archive key, or your system will complain every time it tries to install a package from the Debian archives. The Debian archive keys are replaced every year but are located at an address like http://ftp-master.debian.org/ziyi_key_<year>.asc, where <year> is the current year. Use wget to retrieve the current key, import it into your GPG keyring, and then check the fingerprint:

$ wget http://ftp-master.debian.org/ziyi_key_2006.asc
$ gpg --import ziyi_key_2006.asc
gpg: key 2D230C5F: public key "Debian Archive Automatic Signing Key (2006) <ftpmaster@debian.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1
$ gpg --fingerprint 2D230C5F
pub   1024D/2D230C5F 2006-01-03 [expires: 2007-02-07]
      Key fingerprint = 0847 50FC 01A6 D388 A643  D869 0109 0831 2D23 0C5F
uid          Debian Archive Automatic Signing Key (2006) <ftpmaster@debian.org>

If you want to be really careful, you can then use this fingerprint to prove the authenticity of the key via Debian's web of trust.

Now install the key into apt so that it will trust packages signed by it:

$ gpg --armor --export 2D230C5F | sudo apt-key add -
            

You're now ready to install packages from either Ubuntu or Debian. Any packages you want to specifically pull from the Debian archive can be accessed by adding a -t (target release) flag to apt:

$ sudo apt-get install -t sarge 
               
                  myprogram