Back to basics – Providing a local yum or dnf repository

A new project I am working on is to create a complete lab environment where I can quickly build fully configured virtual servers from scratch.

For this I plan on using KVM as the virtualisation layer and CentOS as the distribution of choice for the virtual machines.

After a minimal installation of CentOS 7, I needed to be able to install additional packages to provide the numerous services I intend to use, such as DNS, DHCP, PXE pre boot, cobbler for automated installation of CentOS, NFS and maybe a little LDAP based authentication.

I had decided that although I could have had direct access to the internet and therefore rely on downloading all the additional packages required (and their associated dependencies), it would be more fun to create everything from scratch within a self contained environment.

First things first, getting the additional packages installed and dependencies.  Via the Virtual Machine Manager I had attached the CentOS 7 installation media which contained everything I needed.

Lets get started

Logged in as root;


# mkdir /media/dvd
# mount -t iso9660 /dev/cdrom /media/dvd
# mkdir -p /software/centos7
# cp -R /media/dvd/* /software/centos7

Note.  I could have just got away with copying the contents of the Packages directory to the /software/centos7 directory I created, however, this would not have copied across the metadata needed for the local yum repository I intend to create.

Now time to create the yum repository configuration file

CentOS 7 comes with a number of repository configuration files even with the minimal installation.  By default these are all disabled.


[root@rhc-server ~]# cd /etc/yum.repos.d/
[root@rhc-server yum.repos.d]# ll
-rw-r--r--. 1 root root 1612 Jul  4  2014 CentOS-Base.repo
-rw-r--r--. 1 root root  640 Jul  4  2014 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 1331 Jul  4  2014 CentOS-Sources.repo
-rw-r--r--. 1 root root  156 Jul  4  2014 CentOS-Vault.repo
[root@rhc-server yum.repos.d]# grep -i enabled *
CentOS-Base.repo:enabled=0
CentOS-Debuginfo.repo:enabled=0
CentOS-Sources.repo:enabled=0
CentOS-Sources.repo:enabled=0
CentOS-Sources.repo:enabled=0
CentOS-Sources.repo:enabled=0

Rather than re-invent the wheel, I will make a modified version of the CentOS-Base.repo file.  In addition I will also rename the existing repo files so they are not called upon, which would be a waste of time given my sand boxed environment.  The other option would be to include a “enabled=0” option in each repo file, but that seems more time consuming.


[root@rhc-server yum.repos.d]# cp CentOS-Base.repo CentOS-Base-Local.repo
[root@rhc-server yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.old
[root@rhc-server yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.old
[root@rhc-server yum.repos.d]# mv CentOS-Sources.repo CentOS-Sources.repo.old
[root@rhc-server yum.repos.d]# mv CentOS-Vault.repo CentOS-Vault.repo.old

The new CentOS-Base-Local.repo looks like this;


[root@rhc-server yum.repos.d]# cat

[baselocal]
name=CentOS-$releasever - Base - Local
baseurl=file:///software/centos7/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

And a quick test proves that it works…


[root@rhc-server yum.repos.d]# yum install bind
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-14.el7 will be installed
--> Processing Dependency: bind-libs = 32:9.9.4-14.el7 for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64
--> Running transaction check
---> Package bind-libs.x86_64 32:9.9.4-14.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================
Package                         Arch                         Version                                 Repository                       Size
============================================================================================================================================
Installing:
bind                            x86_64                       32:9.9.4-14.el7                         baselocal                       1.8 M
Installing for dependencies:
bind-libs                       x86_64                       32:9.9.4-14.el7                         baselocal                       1.0 M

Transaction Summary
============================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 2.7 M
Installed size: 6.8 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /software/centos7/Packages/bind-9.9.4-14.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for bind-9.9.4-14.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                        24 MB/s | 2.7 MB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package    : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@anaconda)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 32:bind-libs-9.9.4-14.el7.x86_64                                                                                         1/2
Installing : 32:bind-9.9.4-14.el7.x86_64                                                                                              2/2
Verifying  : 32:bind-9.9.4-14.el7.x86_64                                                                                              1/2
Verifying  : 32:bind-libs-9.9.4-14.el7.x86_64                                                                                         2/2

Installed:
bind.x86_64 32:9.9.4-14.el7

Dependency Installed:
bind-libs.x86_64 32:9.9.4-14.el7

Complete!

And there we have it, I can now begin the next phase of preparing my build and infrastructure services server.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.