six demon bag

Wind, fire, all that kind of thing!

2014-02-16

Create a Local Yum Repository

When setting up RedHat Enterprise Linux (RHEL) or CentOS systems I always find it handy to have a local repository with the RPMs from the install media. On hosts without Internet connection it saves me the trouble of having to shuffle install media around whenever I need to install an additional package after the system was initially set up. Even if the host is configured to use an online repository, keeping a local repository doesn't hurt except for a little extra disk space, which is cheap enough these days.


First create a directory for the new repository (e.g. /srv/repo/dvd) with a subdirectory repodata and switch to the repository directory:

mkdir -p /srv/repo/dvd/repodata
cd /srv/repo/dvd

Mount the RHEL CD or DVD, copy the RPMs to the repository directory and create a copy of the comps XML file in the repodata subdirectory:

mount /dev/sr0 /mnt
cp -a /mnt/Packages/*.rpm .
cp /mnt/repodata/*comps*.xml ./repodata/comps.xml
umount /mnt

Import the GPG key:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

For createing the local repository you need the createrepo command. If it isn't already installed, you can install it from the RPMs you just copied to the repository directory:

rpm -i deltarpm-*.rpm
rpm -i python-deltarpm-*.rpm
rpm -i createrepo-*.rpm

Next use the following command to create the repository:

createrepo -g repodata/comps.xml .

The command output should look somewhat like this:

Spawning worker 0 with 3720 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

Create a file /etc/yum.repos.d/dvd.repo with the following content:

[RHEL6-Server-DVD]
name=Red Hat Enterprise Linux $releasever - $basearch (DVD)
baseurl=file:///srv/repo/dvd
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

After cleaning up the Yum cache the command yum repolist should show the new local repository:

root@copernicum:~ # yum clean all
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use
subscription-manager to register.
Cleaning repos: RHEL6-Server-DVD
Cleaning up Everything

root@copernicum:~ # yum repolist
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use
subscription-manager to register.
RHEL6-Server-DVD                                         | 3.6 kB     00:00 ...
RHEL6-Server-DVD/primary_db                              | 3.1 MB     00:00 ...
repo id              repo name                                            status
RHEL6-Server-DVD     Red Hat Enterprise Linux 6Server - x86_64 (DVD)      3,720
repolist: 3,720

Posted 16:30 [permalink]