How to create a YUM repository from an ISO image or mounted CD

Every time I work on YUM,  I can visualize this picture, Yamdoot - the messenger of death. Haha...

The Yellowdog Updater, Modified (YUM) is an open-source command-line package-management utility for RPM-compatible Linux operating systems. Many times a user want's to install a particular version of RPM or upgrade an existing RPM installation, but this may not be as simple as just installing a .rpm file. This may require resolving the dependencies of a RPM and then deploying the actual RPM. Inorder to avoid this mess, one can use YUM tool/command.

Lot of RPM packages come bundled with the CD/DVD or ISO image.  We can point the yum tool to the mounted CD/DVD/ISO image and let it figure out the required dependencies and installation of required RPMs.

Here's and example of dependencies:

[root@localhost Packages]# yum install compat-libstdc++-33 pam.i686
Loaded plugins: product-id, refresh-packagekit, subscription-manager
Updating Red Hat repositories.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package compat-libstdc++-33.x86_64 0:3.2.3-69.el6 will be installed
---> Package pam.i686 0:1.1.1-8.el6 will be installed
--> Processing Dependency: for package: pam-1.1.1-8.el6.i686
--> Processing Dependency: for package: pam-1.1.1-8.el6.i686
--> Processing Dependency: for package: pam-1.1.1-8.el6.i686
--> Running transaction check
---> Package audit-libs.i686 0:2.1-5.el6 will be installed
---> Package cracklib.i686 0:2.8.16-4.el6 will be installed
---> Package libselinux.i686 0:2.0.94-5.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package                    Arch          Version               Repository
 compat-libstdc++-33        x86_64        3.2.3-69.el6          cd        183 k
 pam                        i686          1.1.1-8.el6           cd        659 k
Installing for dependencies:
 audit-libs                 i686          2.1-5.el6             cd         58 k
 cracklib                   i686          2.8.16-4.el6          cd         70 k
 libselinux                 i686          2.0.94-5.el6          cd        107 k

Transaction Summary
Install       5 Package(s)

Total download size: 1.1 M
Installed size: 3.3 M
Is this ok [y/N]:
As you can see, inorder to install compat-libstdc++-33 and pam.i686,  we need to first install audit-libs, cracklib and libselinux RPMs. This dependency resolution is done by yum to based on the metadata of the RPM to be installed.

Configuring YUM:

First make sure that the installation media is available. If you installed from a CD/DVD then reinserting the media in the drive should result in it being mounted automatically.

If you are using vmware or other virtualization technology, mounting the media or iso should have the same effect. If it does not, it will be necessary to manually mount the media. You should be able to use a command like:

# mount –ro /dev/sr0 /mount
The contents of the CD will then be available in the /mount directory.
To verify the location of the installation media with the device mounted, run the command

# df -k
You should see the media in the list of file systems, e.g.
/dev/sr0 3516418 3516418 0 100% /media/RHEL_6.1 x86_64 Disc 1

To allow yum to use the media as a repository for installation you will need to add configuration info to yum pointing to the install media. Use the following command:
# vi /etc/yum.repos.d/cd.repo
Now type in the following text:

baseurl=file:"///media/RHEL_6.1 x86_64 Disc 1"
The value for baseurl should match the value of the location of the install media in your file system. If the location string does not contain spaces as does my example, you can omit the quotes. To verify that the data is correct and that the install media is now available for use with yum, at the linux
command line prompt type:
# yum repolist
You should see an entry for repo id "cd" in the output.

Now cd  to the packages directory and install the required package/RPM.

# cd  "/media/RHEL_6.1 x86_64 Disc 1/Packages"
# yum install compat-libstdc++-33 pam.i686

Yum will perform a pre-requisites check and ask you if you want to proceed with the install of the package and any prerequisites. You should enter y to continue. When the install has complete you will get a message to that effect.