Debian Migration
 
 

Converting Red Hat installation to Debian

Field notes


How easy is it to convert one GNU/Linux distribution to the other? Is it at all possible on a live system?

Well, it is possible. It has been done. There are ways. It is tricky. It may be dangerous. No I do not guarantee it will work for you. It may actually not work big time, causing your system to not boot. Worse yet, if you are doing it remotely, the system may loose network connection.

YOU HAVE BEEN WARNED. If you still want to do it -- read on.

0. What is Debian?

To quote the web site [1]:

"Debian is a free operating system (OS) for your computer. An operating system is the set of basic programs and utilities that make your computer run. At the core of an operating system is the kernel. The kernel is the most fundamental program on the computer, does all the basic housekeeping and lets you start other programs. Debian is kernel independent. It currently uses the Linux kernel but work is in progress to provide Debian for other kernels, using the Hurd."

For the purpose of this little paper, I am refering to Debian GNU/Linux distribution.

OTOH, if you are looking at this, you're likely to know what Debian is anyway. And you sure do know what Linux is. If neither of the latter is true, you probably are wasting your time, then.

1.Why converting?

Why would one want to change a distro? There may be several reasons:

  • You don't like what the previous admin has done and how he has done it. On top of that, he installed a distribution X, which you are not as familiar if as Y.
  • You installed the X because it was the only CD lying around at the time. You don't like what you've done and want to change it.
  • You have a weekend to kill.

My case is more or less #2: there was no Debian CD around and the network connection was way too slow to try and performa network install. There was, however, an A-Bit [2] Gentus Linux [3] CD. So, for the lack of a better choice, it was installed.

Gentus is, in essence, a Red Hat with a few A-Bit specific add-ons. They are good for you if you are running an A-Bit mobo, especially a notorious BP6 [4]. They are useless if your machine is an oldish AMD, basically put together from whatever was left around.

Actually, it does not really matter whether you want to convert a Red Hat, SuSE, Mandrake or Slackware to Debian. General outline will be the same. Converting a package-based distribution is a bit easier, since the cleaning stage is simplified.

My experience is somewhat extreme: I was doing it remotely, without physical access to the machine. It would certainly be easier if you're sitting next to it. But, hey, if you've got physical access to the machine you may as well just install another distribution anew!

There are a few obvious dangers of remote installation: you may loose connection, your converted installation may not be as well secured as the old one and can be compromised as you have to be online, you may not want to reboot the machine -- it may not come back online.

So, as I said before: you have been WARNED. This is YOUR DECISION.

2. Game plan

There are 4 stages to the process: preparation, clean-up, installation and post-installation clean-up:

  1. Preparation
    1. Get the list of installed RPMs on your current system
    2. Analyse it and sort into 3 groups:
      • things that must stay
      • things that will go
      • things you are not so sure about
    3. Backup your system configs (/etc) as well as any other data you're afraid to loose
    4. Get dpkg binary
    5. Get Debian base system .debs
  2. Clean-up
    1. Remove all packages in 2.b
    2. Try removing 2.c, if any 2.a depend on them, leave them
  3. Installation
    1. Install dpkg
    2. Install Debian base
    3. apt-get the remaining parts of the system
  4. Post-installation clean-up
    1. Remove remaining Red Hat cruft

If all went well, you may be able to reboot now. However, if you have customized the kernel before, you may want to check your /etc/lilo.conf before doing so. Alternatively, you may want to rebuild your kernel and modules, and then restart.

In any case, I would recommend to have somebody next to the machine when you try rebooting, just so that they could at least tell you what sort of boot messages were flashing, in case the machine does not come back alive.

3. The process

3.1. Preparation

Before converting your system, you need to get try and slim down the existing installation as much as possible. This will make the post-installation clean-up much easier, as well as save you a few file location and versioning problems both during and after installation.

Unfortunately, despite the FHS [5], different distros hava bit of a different view as to what goes where. While you can expect that there will be certain things in certain places (like system-wide configs in /etc), the exact structure may differ. For example, while both Debian and Red Hat use SysV-style inits, the structure is different: Debian places links to /etc/init.d/* into /etc/rc[123456S].d, while Redhat uses separate /etc/rc.d heirearchy under which all runlevel-dependant directories reside.

However, before removing anything with something like (herin after `#' is a root prompt, `$' is a regular user prompt, and `>' is a continuation prompt):

       # rm -rf /

consider looking through the RPM list and removing anything that is not in Base installation.

Get the list with

       $ rpm -qia > rpm_all_list.txt

or, if you want to be a little more sophisticated:

       $ for i in `rpm -qa`\
> do\
> rpm -qi $i\
> echo "<<< divider >>>"
> done > rpm_all_list.txt

Go through through this list, put together a list of what you are sure you don't need, what you think you don't need, what you think you must have.

In my case I ended up with some 150 packages, but it was more than I really needed.

Before going any further and to save ourselves nerve tissue, let us back up all important config files. A simple

       # tar cvzf ~/etc.tar.gz /etc

will work just fine.

Once this is done, it is time to get all the new stuff that we will be installing. Debian installation will be done in two steps: we will first install the base system manually, then we install all the missing components with apt/dselect.

First, let us get The Tool. Create a separate directory in your $HOME where all the preparatory work would go. Fetch the dpkg binary [6] from Debian ftp site and set it aside.

Next, download the Debian base system [7]. Set it aside for a little while. The base system will sufficient to allow you to have your machine running and accessing the network, which is how we will be installing the rest of the system. But before, we need to do a little bit of cleaning.

3.2. Clean-up

Removing is easy:

       # rpm -e <package name>

The good thing is that it will obviously check the dependencies and tell you if you're breaking something. You can force it to ignore all dependencies:

       # rpm -e --nodeps <package name>

but I would not recommend it unless you absolutely certain what you are doing.

Start with the obvious: X, emacs, ppp (unless this is how your box is hooked up with the rest of the world), *-devel, databases (except for libgdbm and possibly libdb2), mail clients (pine, elm, mutt, but leave mailx just in case), MTA (sendmail, qmail, smail, postfix -- whatever you have), docs, apache, Red Hat user guides, instalation manual, etc.

Then move onto development tools: yacc, flex, bison, bc, gcc/eggcs, cpp, etc. Remove man and man pages, groff/troff/nroff, kernel headers, kernel source, etc., etc., etc.

Then move onto less obvious stuff. See if removing a package breaks your base system, i.e. if it affects the list of packages included into the base system. If it does not -- go ahead and remove it.

In general, the following things should pretty much stay:

  • libc (dpkg depends on libc6/glibc2 and libstc++2, but it is linked statically, it will work even without libc, but other things won't)
  • shell (whichever you like best, but there must be sh, whether itself or a symlink to bash)
  • basic GNU tools: grep, sed, tar, gzip, find, [mg]awk, file, etc.
  • working kernel and kernel modules
  • a simple editor (vi/nvi/vim/elvis/ae)
  • ??

In my case, I shrank the installation more then twice in terms of package count and about 40% volume-wise. YMMV. Needless to say, all of the above will be performed as root (unless you had sudoi setup on your system and you left it on).

Do keep in mind that if you are accessing the box from afar, it would make total sense to leave telnet, ftp, ssh working, unless you want to suddenly loose it.

3.3. Installation

Time to install The Tool:

       # cd /
# tar xzf ~/dpkg_<version>_i386.nondebbin.tar.gz

Check if it is working:

       # dpkg --help
...
<long output>
...

Before installing anything else, check to make sure that you have /var/lib/dpkg/status file and it contains the entry about dpkg. If it does not, add the following:

        new debian package, version 2.0.
size 713548 bytes: control archive= 4120 bytes.
683 bytes, 18 lines control
5510 bytes, 234 lines * postinst #!/bin/sh
2423 bytes, 86 lines * preinst #!/bin/sh
442 bytes, 20 lines * prerm #!/bin/sh
Package: dpkg
Version: <version>
Architecture: i386
Essential: yes
Pre-Depends: libc6 (>= 2.1.2), libncurses5, libstdc++2.10
Replaces: dpkg-doc-ja
Installed-Size: 1821
Maintainer: Wichert Akkerman <wakkerma@debian.org>
Description: Package maintenance system for Debian
This package contains the programs which handle the installation and
removal of packages on your system.
.
The primary interface for the dpkg suite is the `dselect' program;
a more low-level and less user-friendly interface is available in
the form of the `dpkg' command.
.
In order to unpack and build Debian source packages you will need to
install the developers' package `dpkg-dev' as well as this one.

Keep it exactly the same, only provide the proper version information.

This is a quick-fix approach, it is not perfect and dpkg will complain about a few things (it would not know what files it owns, etc.), but we will rectify it once we install an updated dpkg from the base.

Now you are ready to start installing your base system. We should start with the .debs that are not dependant on any other package and then gradually move up the dependency ladder.

This quick perl script (provided you kept perl :) will help you:

        #!/usr/bin/perl -w
# dpkg_dep.pl
# A quick way to check .deb dependencies
# Usage: dpkg -I | dpkg_dep.pl

$package = "";
@depends = [];
$firstline = 1;

while ( <> ) {
if ( $firstline ) {
$firstline = 0; # skip the first line
next;
}
if ( /^\sPackage\:\s(\w+)$/ && !$depends ) {
$package = $1;
} elsif ( /^\sDepends\:\s(\w.*)$/ || /^\sPre\-Depends\:\s(\w.*)$/ && $package) {
@depends = split(/\,\s/, $1);
#shift(@depends);
print $package . ": ";
foreach (@depends) {
print;
print " ";
}
print "\n";
$package = "";
@depends = [];
} elsif ( /^\snew\sdebian\spackage/ && ($package && !$depends)) {
print "Package $package has no dependencies...\n";
$package = "";
}
}

Save it, chmod u+x, and run it as follows:

      # cd <wherever your base .debs are>
# dpkg -I `ls *.deb` | dpkg_dep.pl

You can obviously filter the output any way you like.

To cut the long story short, the following packages are not dependant on anything else:

  • ldso
  • mbr
  • ncurses-base

ldso is also the only prerequisite for libc6, which is, in turn is a prerequisite for the new dpkg (along with libstc++).

To install a package do:

      # dpkg -i <package_file.deb>

For example, at the time of this writing, the following packages depended solely on libc6:

  • bsdutils
  • debianutils
  • diff
  • e2fsprogs: libc6 (>= 2.1.2)
  • fdflush: libc6 (>= 2.1.2)
  • fileutils: libc6 (>= 2.1.2)
  • findutils: libc6 (>= 2.1.2)
  • grep: libc6 (>= 2.1.2)
  • ... many other

You then should start climibing the dependency ladder from one package to the other. However, once you install ldso, libc6, ncurses-base, libncurses5 and libstc++ (in that order), you can install an updated dpkg. Do so.

After that, continue installing packages that are only libc6 dependant -- you'll cover most of the base. Once those are done, you can try and install remaining in one gulp: just list them all on dpkg command line. A good idea is to create a subdir in your base directory, say `installed', to which you could move a package once it was successfully installed and configured. In this case to install all remaining packages you could just

      # dpkg -i `ls *.deb`

It's likely that not everything went perfectly fine. In particular, I had a problem with Red Hat's install-info program: it was in the beginning of my path, while the version installed by dpkg was not. A few things failed to configure this way untill I removed the conflicting install-info.

To check whether you have packages that failed to install or configure you can issue the following command:

      # dpkg -C

It will list packages that are not configured or fully installed. After that you can do

      # dpkg --configure <package>
or
      # dpkg --configure --pending

to configure all unconfigured packages.

Once all of the base packages are safely and happily installed, we can move onto the next phase: bringing our Debian system up to speed, or rather to the same type of configuration as your older installation.

Remember that RPM list we had? Well, we can use it a bit more now -- it is a fair basis for identifying what packages you need to install on your new Debian system. Obviously, you don't have to repeat the same config (it may have been installed as a default set if you were in a very big rush, why installing all the unnecessary crap?).

In my case I pretty much new what I needed on top of the base:

  • perl (all of it)
  • python
  • MTA (I prefer postfix [8] for its security)
  • a decent editor
  • mutt
  • fetchmail (in case I need to fetch mail from other hosts)

At a later time I will get a few more things, especially kernel related (kernel-package, kernel-source*, gcc, libc6-dev, ncurses-dev, bin86, etc.

  • see a README in /usr/share/doc/kernel-package, after you installed it.) to be able to re-compile the kernel. But that's later, when I have a trusted guy nest to the box to see if it works at all.

One other thing I would highly recommend installing right there and then is cruft. cruft uses dpkg file database and searches your file system for things that are not regestered by dpkg. Aside from /home /usr/local and/or /opt hierarchies, all other files should be present in dpkg files database. Things that aren't are cruft. This will help you with the next stage.

3.4. Post-installation clean-up

If you installed cruft -- so much easier for you. Otherwise it may be a long and tedious process (but you can scriptify it, I guess). What you basically need is to remove any remaining binaries, config files and other cruft remaining after the previous installation. You could perform some additional removals while installing base Debian (e.g. do rpm -e sed before doing dpkg -i sed<version>.deb), but once you installed it -- removing an RPM will likely remove some (or all) of your Debian-installed files as well.

So, at this stage plain rm is your better friend. With cruft, get the list of "alien" files (but do read the README before to see how some of the hierarchies could be exluded) and rm them (if your're very brave, you could just pipe cruft to rm -rf, but I would not do that).

If you don't have cruft installed, you can do something like this:

      #!/bin/sh
cd /
for i in `find / *`
do
p = (dpkg -S $i | grep "not found")
echo $p
done

Yeah, this one is very lame, more over it is VERY slow. You're better off getting cruft and using that instead.

This should more or less clean up your installation. Be careful -- you can erase something vital by accident. To be on a safe side, run debsums after this to check if all md5 sums on the registered files are Okay.

4. Aftermath

So, now your box is in a good shape, working as before. Your users may have noticed a little interruption in a few services (mail, ftp, http, probably telnet), but other than that nothing is different for them.

For you, however, there remains the task of actually making sure that all the config options you had before are the same as they are now. You'd need to to check and update a few things in /etc -- but that should not be news for you, right?

What you've gotten for your self now, is a distribution that will be much easier to manage remotely (at least in terms of security updates, new software installations, etc.).

5. Links, thanks, etc.

References

  1. Debian GNU/Linux web site: http://www.debian.org/
  2. A-Bit: http://www.abit.com.tw/
  3. A-Bit Gentus Linux web site: http://www.gentus.com/
  4. A-Bit BP6 forum: http://www.bp6.com/
  5. Filesystem Hierarchy Standard (FHS) http://www.pathname.com/fhs/
  6. dpkg for non-debian distributions: http://ftp.debian.org/project/experimental/ look for dpkg_*_i386.nondebbin.tar.gz, the latest version.
  7. Debian GNU/Linux base system: http://ftp.debian.org/dists/stable/main/binary-i386/base/
  8. Postfix home page: http://www.postfix.org/

Thanks & hellos

This document was converted from a plain ASCII file with txt2html. Thanks, Seth! There was a bit of .txt2html.dict tweaking and it was then "massaged" a bit to fit the toll.