Bootstrapping Centos or Fedora from Debian or Ubuntu

Here are some notes about bootstrapping a Centos or Fedora chroot from Debian. It should also work from Ubuntu with minor changes, but I haven’t checked. The following should really be done in a chroot, since some commands will install files in your /etc or elsewhere, ignoring the --installroot passed to yum. The following instructions are for Centos, but replacing all occurences of centos with fedora should work.

  • apt-get install yum rpm python-m2crypto. If at some point, you get error messages about rpmlib(BuiltinLuaScripts), you need to install a newer rpm package (from Debian unstable, for example).
  • mkdir -p /tmp/centos/var/lib/rpm
  • rpm --root /tmp/centos --initdb
  • Go to http://rpm.pbone.net or http://www.rpmfind.net, search for centos-release or fedora-release, and download the rpm for the version you want.
  • rpm -ivh --force-debian --nodeps --root /tmp/centos centos-release*rpm (that populates /tmp/centos/etc with information about the centos repositories)
  • yum --installroot /tmp/centos/ install yum . That fails because of missing GPG information in /etc/pki. Do ln -s /tmp/centos/etc/pki /etc/pki, then again yum --installroot /tmp/centos/ install yum.
  • mount -t proc foo /tmp/centos/proc
  • mount -t sysfs foo /tmp/centos/sys
  • chroot /tmp/centos /bin/bash --login

If you get errors about different DB versions between Debian’s RPM and CentOS’ RPM, you can try, in the CentOS chroot:

  • cd /var/lib/rpm && rm * (simplest way to avoid problems between db versions for Debian’s RPM and centos’ RPM)
  • rpm --initdb
  • yum install yum (again, to restore the rpm db)
  • yum install vim-minimal less
  • That’s all!

Update: Jaldhar Vyas pointed me to mach, and Paul Wise to mock. Both packages are available in Debian, but use config files for each release shipped in the package. Unfortunately, both packages are out of date, and don’t include Fedora 9 or newer. Also, mock doesn’t support Centos.
Anyway, both packages could use a new maintainer. Don’t hesitate to jump in!

10 thoughts on “Bootstrapping Centos or Fedora from Debian or Ubuntu

  1. That’s exactly what I needed today! :-))

    But I get some problems:

    > http://www.rpmfind.net

    I can’t find there “centos-release”, rpm.pbone.net works.

    > rpm -ivh –force-debian

    Are you sure?

    > yum –installroot /tmp/centos/ install yum

    I get the error:

    GPG key retrieval failed: [Errno 5] OSError: [Errno 2] No such file or directory: ‘/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5’

    Copying /tmp/centos/etc/pki to /etc/ doesn’t make it happy:

    Is this ok [y/N]: y
    Traceback (most recent call last):
    File “/usr/bin/yum”, line 29, in
    yummain.user_main(sys.argv[1:], exit_code=True)
    File “/usr/share/yum-cli/yummain.py”, line 236, in user_main
    errcode = main(args)
    File “/usr/share/yum-cli/yummain.py”, line 188, in main
    base.doTransaction()
    File “/usr/share/yum-cli/cli.py”, line 364, in doTransaction
    if self.gpgsigcheck(downloadpkgs) != 0:
    File “/usr/share/yum-cli/cli.py”, line 464, in gpgsigcheck
    self.getKeyForPackage(po, lambda x, y, z: self.userconfirm())
    File “/var/lib/python-support/python2.5/yum/__init__.py”, line 2571, in getKeyForPackage
    misc.import_key_to_pubring(rawkey, po.repo.cachedir)
    File “/var/lib/python-support/python2.5/yum/misc.py”, line 278, in import_key_to_pubring
    ctx = gpgme.Context()
    AttributeError: ‘module’ object has no attribute ‘Context’Is this ok [y/N]: y
    Traceback (most recent call last):
    File “/usr/bin/yum”, line 29, in
    yummain.user_main(sys.argv[1:], exit_code=True)
    File “/usr/share/yum-cli/yummain.py”, line 236, in user_main
    errcode = main(args)
    File “/usr/share/yum-cli/yummain.py”, line 188, in main
    base.doTransaction()
    File “/usr/share/yum-cli/cli.py”, line 364, in doTransaction
    if self.gpgsigcheck(downloadpkgs) != 0:
    File “/usr/share/yum-cli/cli.py”, line 464, in gpgsigcheck
    self.getKeyForPackage(po, lambda x, y, z: self.userconfirm())
    File “/var/lib/python-support/python2.5/yum/__init__.py”, line 2571, in getKeyForPackage
    misc.import_key_to_pubring(rawkey, po.repo.cachedir)
    File “/var/lib/python-support/python2.5/yum/misc.py”, line 278, in import_key_to_pubring
    ctx = gpgme.Context()
    AttributeError: ‘module’ object has no attribute ‘Context’

    And here I don’t know what to do …

  2. rpmfind works fine for fedora. I’ve changed the order in the blog so people try pbone.net first.

    –force-debian: Yes, because the rpm debian package won’t let you install packages even if you use –installroot (if I remember correctly).

    pki problem: oops, I missed one step when copying from my notes. post updated. You need to answer “no”, to copy or to create a symlink, and then to start yum again.

  3. Wish I would have had this last year when I had to work on a CentOS based distro for a company I was working for. I had to figure this out from picking pieces from here and there all over the tubes. Should have wrote something up then, but I was obviously to lazy :) Groovy write up!

  4. Hi,

    Could you consider posting this on the wiki, so other people can contribute directly,

    Thanks,

    Franklin

  5. I just when through this – worked great, thanks! Just had to run this after the chroot:

    echo “nameserver 4.2.2.1” > /etc/resolv.conf

  6. Hi Lucas,
    I agree with you about mock, it needs some care in debian.
    In the meantime I’ve managed to have a Fedora 11 chroot on
    debian using mock from git. I’m adding the steps here as a
    comment, maybe they can help someone..

    aptitude install -t experimental rpm
    aptitude install yum rpm python-peak.util

    groupadd -r mock

    git clone git://git.fedorahosted.org/git/mock.git mock
    cd mock
    ./autogen.sh
    ./configure
    make
    make install

    mock -r fedora-11-x86_64 –init

Comments are closed.