Create a Repo

Creating Custom Repositories

Creating your own Repositories in RHEL


When you install RHEL (Red Hat Enterprise Linux) you generally have a 30 day trial period where you can download updates - patches etc.. After this period you will no longer have access to any repositories unless you sign up to the Red Hat Network (RHN). If you wanted to use RHEL for evaluation purposes, then you can create your own repository for installing software. This repository is based on the rpm packages that came with the installation media. The following steps need to be run as the "root" user.

The process of creating your own repo is as follows:

Create a directory for your repo
Mount your installation media or (Insert DVD)
Navigate to the location where the rpm packages are located
Copy these package files to your custom directory
Install createrepo package and its dependencies
Issue the createrepo command against your custom directory
Display your repos with the yum repolist command



Step 1 - Create a directory for your repository in the root filesystem



# mkdir /myrepo

Step 2 - Mount your installation media


Display currently mounted filesystems using the "mount" command. We can see from the output below that our "cdrom" is not currently mounted. If you are using the graphical interface, your DVD should be automatically mounted. In the example below, we are working from the command line.



[root@rhel02 ~]# cd /
[root@rhel02 /]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

Locate your cdrom device. This can be done by simply running the command "ls -l /dev | grep -i cdrom"



[root@rhel02 /]# ls -l /dev | grep -i cdrom
lrwxrwxrwx. 1 root root           3 Mar 19 09:28 cdrom -> sr0
crw-rw----. 1 root cdrom    21,   0 Mar 19 09:19 sg0
brw-rw----. 1 root cdrom    11,   0 Mar 19 09:28 sr0

Next we must mount the cdrom to an existing directory /media



[root@rhel02 /]# mount /dev/cdrom /media
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@rhel02 /]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /media type iso9660 (ro)

After issuing the mount command, we can see that our cdrom is now mounted (/dev/sr0 on /media type iso9660 (ro)

At this point we have no repositories defined, we can confirm this by running the "yum repolist" command:



[root@rhel02 media]# yum repolist
Loaded plugins: product-id, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
repolist: 0

Step 3 - Navigate to your mounted DVD


To navigate to our mounted device, we need to use the "cd" command. This will take us to the area where the rpm packages are held.



[root@rhel02 /]# cd /media/Packages

Step 4 - Copy rpm files to /myrepo directory


Next we issue the command "cp * /myrepo/". This command copies the rpm packages to the "/myrepo" directory we created earlier in step 1.

This process may take several minutes as the contents of the rpm files can be quite large. Please note, you will need around 3Gb of space available.



[root@rhel02 Packages]# cp * /myrepo/

Step 5 - Install createrepo package and its dependencies


First navigate to the /myrepo directory with the command "cd /myrepo/":



[root@rhel02 /]# cd /myrepo/

Now we issue the commands: rpm -ihv deltarpm[TAB] (Press the TAB key to auto-complete the name of the package)



[root@rhel02 myrepo]# rpm -ihv deltarpm-3.5-0.5.20090913git.el6.i686.rpm 
warning: deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:deltarpm               ########################################### [100%]


Now we issue the commands: rpm -ihv python-deltarpm[TAB] (Press the TAB key to auto-complete the name of the package)



[root@rhel02 myrepo]# rpm -ihv python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm 
warning: python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:python-deltarpm        ########################################### [100%]

Now we issue the commands: rpm -ihv createrepo[TAB] (Press the TAB key to auto-complete the name of the package)



[root@rhel02 myrepo]# rpm -ihv createrepo-0.9.8-5.el6.noarch.rpm 
warning: createrepo-0.9.8-5.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:createrepo             ########################################### [100%]

step 6 - Create Repository with the createrepo command


Issue the command "createrepo" followed by the name of the directory we created:



[root@rhel02 myrepo]# createrepo /myrepo
2842/2842 - setroubleshoot-3.0.47-2.el6.i686.rpm                                
Saving Primary metadata
Saving file lists metadata
Saving other metadata

Create repository entry in /etc/yum.repos.d


Before we can use the repository, an entry has to be added in the /etc/yum.repos.d directory. This entry tells your server where it can found the new repository.

First we need to navigate to this location. There will probably already be an entry called "rhel.source.repo". This is a default entry.:



[root@rhel02 myrepo]# cd /etc/yum.repos.d
[root@rhel02 yum.repos.d]# ls
rhel-source.repo

Now create an entry called "/etc/yum.repos.d/myrepo.repo". This can be done with the editor of your choice. In the example I have used the "vi" editor": (As we are already in the location /etc/yum.repos.d, I simply issue "vi myrepo.repo"



[root@rhel02 yum.repos.d]# vi myrepo.repo

Now add the following lines into this file and save your changes.



[myrepo]
name=myrepo
baseurl=file:///myrepo
gpgcheck=0

Now when we issue the "yum repolist" command we should see output similar to the following:



[root@rhel02 yum.repos.d]# yum repolist
Loaded plugins: product-id, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
myrepo                                                   | 1.3 kB     00:00 ... 
myrepo/primary                                           | 1.3 MB     00:00 ... 
myrepo                                                                2842/2842
repo id                              repo name                            status
myrepo                               myrepo                               2,842
repolist: 2,842

You should now be able to install software from this repository.