Back to basics – Providing a local yum or dnf repository

Posted on Posted in Uncategorized

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;

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

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.

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

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.

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

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

</p>
<p>[root@rhc-server yum.repos.d]# cat</p>
<p>[baselocal]<br />
name=CentOS-$releasever - Base - Local<br />
baseurl=file:///software/centos7/<br />
gpgcheck=1<br />
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7<br />
enabled=1</p>
<p>

And a quick test proves that it works…

</p>
<p>[root@rhc-server yum.repos.d]# yum install bind<br />
Loaded plugins: fastestmirror<br />
Loading mirror speeds from cached hostfile<br />
Resolving Dependencies<br />
--&gt; Running transaction check<br />
---&gt; Package bind.x86_64 32:9.9.4-14.el7 will be installed<br />
--&gt; Processing Dependency: bind-libs = 32:9.9.4-14.el7 for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-9.9.4-14.el7.x86_64<br />
--&gt; Running transaction check<br />
---&gt; Package bind-libs.x86_64 32:9.9.4-14.el7 will be installed<br />
--&gt; Finished Dependency Resolution</p>
<p>Dependencies Resolved</p>
<p>============================================================================================================================================<br />
Package                         Arch                         Version                                 Repository                       Size<br />
============================================================================================================================================<br />
Installing:<br />
bind                            x86_64                       32:9.9.4-14.el7                         baselocal                       1.8 M<br />
Installing for dependencies:<br />
bind-libs                       x86_64                       32:9.9.4-14.el7                         baselocal                       1.0 M</p>
<p>Transaction Summary<br />
============================================================================================================================================<br />
Install  1 Package (+1 Dependent package)</p>
<p>Total download size: 2.7 M<br />
Installed size: 6.8 M<br />
Is this ok [y/d/N]: y<br />
Downloading packages:<br />
warning: /software/centos7/Packages/bind-9.9.4-14.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY<br />
Public key for bind-9.9.4-14.el7.x86_64.rpm is not installed<br />
--------------------------------------------------------------------------------------------------------------------------------------------<br />
Total                                                                                                        24 MB/s | 2.7 MB  00:00:00<br />
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7<br />
Importing GPG key 0xF4A80EB5:<br />
Userid     : &quot;CentOS-7 Key (CentOS 7 Official Signing Key) &lt;security@centos.org&gt;&quot;<br />
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5<br />
Package    : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@anaconda)<br />
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7<br />
Is this ok [y/N]: y<br />
Running transaction check<br />
Running transaction test<br />
Transaction test succeeded<br />
Running transaction<br />
Installing : 32:bind-libs-9.9.4-14.el7.x86_64                                                                                         1/2<br />
Installing : 32:bind-9.9.4-14.el7.x86_64                                                                                              2/2<br />
Verifying  : 32:bind-9.9.4-14.el7.x86_64                                                                                              1/2<br />
Verifying  : 32:bind-libs-9.9.4-14.el7.x86_64                                                                                         2/2</p>
<p>Installed:<br />
bind.x86_64 32:9.9.4-14.el7</p>
<p>Dependency Installed:<br />
bind-libs.x86_64 32:9.9.4-14.el7</p>
<p>Complete!</p>
<p>

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.