Using CentOS Repositories on RHEL Machines

CentOS adds value to their rebuild of RHEL through several repositories, such as CentOS-Plus and Extras. There are also third-party Repositories that are useful on RHEL systems. The problem is that up2date doesn't handle yum repos extremely well, and with the transition in RHEL5 to yum, many folks would like to use yum to manage their RHEL 3 and 4 systems. To do this, there are a couple of things that need to happen:

  1. Install yum on RHEL. We will use the yum package from CentOS, and make adjustments to work with RHEL.
  2. Allow yum access to RHEL repositories. Since Red Hat doesn't make repositories publicly available, a mirror will have to be created. For the purposes of this document, Dag Wieers' mrepo tool will be used to accomplish this.

  3. Add additional repositories. Repositories are generally managed from the /etc/yum.repos.d directory through .repo files.

Bootstrapping Yum

The following RPMs from CentOS 4 will be needed, available from http://mirror.centos.org/centos/:

/!\ The version of yum in CentOS 3 does not have all of the dependencies that CentOS 4 does, so ignore any on this list that do not exist in CentOS 3

In order to install these packages, there must be a package installed which provides "yumconf". In CentOS, this is provided by the centos-release RPM. We can't use this RPM on RHEL, since it would overwrite /etc/redhat-release among other things. To work around it, create a new RPM which contains the appropriate files. The rpm provided below does just that. The spec file for this RPM ( redhat-yumconf-4-4.8.el4.nosrc.rpm ) contains:

Summary: RHEL-4 Yum configuration.
Name: redhat-yumconf
Version: 4
Release: 4.8.el4
Copyright: GPL
Group: System Environment/Base
Source0: CentOS-Base.repo
Source1: RHEL-Base.repo
NoSource: 1
BuildArch: noarch
BuildRoot: %{_tmppath}/redhat-yumconf-root
Provides: yumconf
Conflicts: centos-release
%description
Repo files for yum on RHEL 4
%install
mkdir -p $RPM_BUILD_ROOT/etc
mkdir -p $RPM_BUILD_ROOT/etc/yum.repos.d
cp -f %{SOURCE0} $RPM_BUILD_ROOT/etc/yum.repos.d
cp -f %{SOURCE1} $RPM_BUILD_ROOT/etc/yum.repos.d
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(0644,root,root)
%config(noreplace) /etc/yum.repos.d/CentOS-Base.repo
%config(noreplace) /etc/yum.repos.d/RHEL-Base.repo

You will notice that the RHEL-Base.repo file is listed as a NoSource file. Since you must create your own repository, there is no way to know what server this repository will live on, etc. It is suggested that you use the CentOS-Base.repo file as a template and create a RHEL-Base.repo file appropriate for your environment. Once you have created this file, put it in the SOURCES directory of your rpm build path (see YumAndRPM for help), and rebuild the SRPM redhat-yumconf-4-4.8.el4.nosrc.rpm.

(!) If you are not sure where the repository will end up, you could create RHEL-Base.repo as an empty file for now and modify it after you have created your mirror.

Once this RPM is created and installed, the necessary yum RPMs and dependencies can be installed. The script below ( yum-bootstrap.sh ) will help bootstrap this process.

#!/bin/sh
# Check that the prerequisite of yumconf is installed
rpm -q --whatprovides yumconf 2>&1 >/dev/null
if [ $? != 0 ]; then
        echo "You must have a package installed that provides yumconf."
        echo "See http://wiki.centos.org/HowTos/PackageManagement/YumOnRHEL"
        echo "for more details on how to accomplish this."
        exit 1;
fi
export ARCH=`uname -i`
export BSDIR=/tmp/yum-bootstrap
export SOURCE=http://mirror.centos.org/centos/4/os/$ARCH/CentOS/RPMS
mkdir $BSDIR
wget -P $BSDIR -nH $SOURCE/yum-2.4.3-4.el4.centos.noarch.rpm
wget -P $BSDIR -nH $SOURCE/yum-metadata-parser-1.0-8.el4.centos.$ARCH.rpm
wget -P $BSDIR -nH $SOURCE/python-urlgrabber-2.9.8-2.noarch.rpm
wget -P $BSDIR -nH $SOURCE/python-elementtree-1.2.6-5.el4.centos.$ARCH.rpm
wget -P $BSDIR -nH $SOURCE/python-sqlite-1.1.7-1.2.1.$ARCH.rpm
wget -P $BSDIR -nH $SOURCE/sqlite-3.3.6-2.$ARCH.rpm
rpm -Uvh $BSDIR/yum* $BSDIR/python* $BSDIR/sqlite*
if [ $? -eq 0 ]; then
        rm -rf $BSDIR
fi
# Fix the release package, otherwise $releasever is set to null
sed -i "s/centos-release/redhat-release/" /etc/yum.conf

Creating a RHEL Mirror

As mentioned above, it is necessary to build a mirror of the RHEL binary RPMs to use yum directly. Start by installing mrepo. The easiest way to do this is to add in the RPMForge Repository (see Repositories). From RPMForge, install mrepo, createrepo, and hardlink++.

  1. Create the directory where you would like to store the mirror. mkdir /var/mrepo/rhel4as-x86_64

  2. Copy the systemid file from /etc/sysconfig/rhn to your new directory. cp /etc/sysconfig/rhn/systemid /var/mrepo/rhel4as-x86_64

  3. Modify the included /etc/mrepo.conf file to match your environment. Configure the appropriate directories, arch, and mailto. You can leave the rhnlogin line commented out, since it is only needed when subscribing to channels. Since an existing systemid is being used, it is unlikely to need the password, but will prompt for one if it is needed (e.g. a channel is configured that the system is not already subscribed to).

  4. Next, create a file in /etc/mrepo.conf.d for your distribution. The example below is for RHEL4 with Extras and Fastrack. For other channel paths, look on the RHN website. The Details page for each channel has a Label field (after Summary and Description). This is what you put after rhns:///.

  5. Now populate the mrepo repository by running mrepo -uv rhel4as-x86_64.

/etc/mrepo.conf.d/rhel4as-x86_64.conf:

[rhel4as-x86_64]
name = Red Hat Advanced Server $release ($arch)
release = 4
arch = x86_64
updates = rhns:///rhel-x86_64-as-4
extras = rhns:///rhel-x86_64-as-4-extras
fastrack = rhns:///rhel-x86_64-as-4-fastrack

It is likely desirable to create a cron job that will run mrepo -gu rhel4as-x86_64 to keep the repository up-to-date as updates are released. This is usually once a week for RHEL, but a nightly job would probably be a good cycle, especially if there are Fastrack updates to pick up or security issues.

{i} mrepo has many more uses than simply downloading updates from RHN. See the mrepo Website for more configuration options.

/!\ If you are using a non-RHEL machine (e.g. CentOS) to run mrepo, there are a couple of caveats to be aware of:

  1. There is an up2date setting needed in /etc/sysconfig/rhn/sources, mentioned on http://svn.rpmforge.net/svn/trunk/tools/mrepo/docs/redhat-network.txt - you must uncomment the line containing up2date default.

Configuring Repositories

At this point, yum should be installed. To add additional repositories, simply add .repo files to the /etc/yum.repos.d directory. There is more information on how to do this at Repositories. One caveat to watch for, at least in RHEL 4, is that most third party repositories use /4/ as the releasever, however RHEL4 reports releasever as /4XX/, where XX is either WS, ES, or AS - depending upon the release. The easiest way to fix this is to replace all references to $releasever in .repo files with 4.

/!\ By using the redhat-yumconf RPM above, the CentOS base and update repositories are enabled, but restricted to yum and dependencies. All of the other CentOS repositories are available, but disabled by default. It is possible to override this on the command line with the --enablerepo option, or edit the CentOS-Base.repo file to enable the other repositories. This provides access to the Value Added packages, without converting from a RHEL machine to a CentOS machine unwittingly. All of the CentOS repositories are prefixed with c4- at the beginning of the name (e.g. c4-updates) so as to not conflict with similarly named repos in your RHEL-Base.repo. This is also convenient to do things like yum --enablerepo=c4-\* ....

HowTos/PackageManagement/YumOnRHEL (last edited 2008-05-29 13:59:12 by MatthewHyclak)