Tuesday, February 27, 2007

Configuring Yum in RHEL5 for DVD source

In my last article I explained the problem I faced with the installation of software in RHEL5 Beta2. I tried system-config-packages and the old "rpm" command but nothing worked as it used to in earlier days. So I thought to dig into this thing and tried to find the possible cause and solution to this problem.

So I went on to GNU/Linx community and put up this question. Okay I got some inputs some directions and finally I got what I wanted. First of all let me tell you the scenario once more so that you can better get what I want to say.

Suppose you have installed a RHEL5 system and now after the installation is complete you want to install a package (which is not installed). You put in the DVD and mount it. Go to the said directory and try to install the package via the well old "rpm" command. But to your surprise you found that it failed due to dependency problems. Okay no problem. We all know how to deal with it. We use the "--aid" switch with our "rpm" command that will automatically install the dependency rpm first then the said rpm. Well we try that but it again failed with the same error message. That means it's not finding the dependency rpm. But wait. The dependency rpm and the rpm we want to install both are in the same directory then why is the "rpm" command failing.

Well that's because in RHEL5 (as in Fedora Core 6) all the things are controlled by "yum". I read somethings about "yum" and quickly found that it had problem with dvd sources. But I didn't found any thing on how to disable "yum" completely and go through the well old command line way of installing packages. But I found a way out by which "yum" can access DVD sources and if that happens we can install/un-install packages easily either via graphical tool(system-config-packages) or the command line via "yum" command.

Okay so let's start this.I inserted the RHEL5 Client DVD and mounted it on /media/dvd/


mkdir -p /media/dvd
mount /dev/dvd /media/dvd


Then I created a ISO file for this DVD using the "mkisofs" command.

mkisofs -o /opt/RHEL5.iso -r /media/dvd/

The above command took sometime as I was creating a image file for my DVD (approx 3.6GB). Well after sometime it finished. Now was the time to do the real job. There was no use of the DVD so i unmounted and ejected it.


umount /media/dvd/
eject


Now I created a directory which will act as mount point for the ISO file I created earlier.


mkdir -p /dvd/actual


Now I mounted the ISO file onto the above mount point. Note that to mount the ISO file we need to use special options. So let's see what is the command.


mount -r -o loop -t iso9660 /opt/RHEL5.iso /dvd/actual


The above command mounted the RHEL5 ISO on /dvd/actual. Now I went to the mount point directory and installed a rpm called "createrepo".


cd /dvd
rpm -Uvh actual/Client/creatrepo*


The need for this RPM arises because the DVD of RHEL5 (also of FC6) has "media:" written in it's metadata that creates problem with "yum". Now by using this createrepo I will create a copy of my own for the repodata that will not be having the "media:" thing and that will help me use the repodata with "yum" and hence the software using "yum" too like "system-config-packages" or "pirut".

Now it's time to create the repodata. This is how I did that (note: I didn't changed my current directory. Was where I was previously).


createrepo .


Above command indexed around 2239 Packages and created a repodata/ directory in the current directory of around 8.1 MB. This directory had the repomod.xml and other metadata files. Actually what it did was it indexed all the RPM's present in the current directory, that was "/dvd". So I had rpm's in

/dvd/actual/Client, /dvd/actual/VT, /dvd/actual/Workstation

All got indexed and the metadata was created.

I also copied the GPG key files to my hard disk (to tell yum to use them later).


cp /dvd/actual/*GPG* /opt


There were around 4-5 GPG files they got copied to /opt. Later we will see that we can make "yum" to read these GPG key files and verify a package before installing.

Now finally came the time to tell yum to use this repo to for my installations. That was done by creating a repo file in /etc/yum.repos.d/. This is how it was done:


cd /etc/yum.repos.d/
vi dvd.repo


Inside this file I wrote the following:


[dvd]
name=RHEL5DVD
baseurl=file:///dvd
enabled=1
gpgcheck=1
gpgkey=file:///opt/RPM-GPG-KEY file:///opt/RPM-GPG-KEY-beta file:///opt/RPM-GPG-KEY-fedora file:///opt/RPM-GPG-KEY-fedora-test


Saved the /etc/yum.repos.d/dvd.repo file. Now I thought of disabling the plugins for RHN and "InstallOnly Packages". So I went to /etc/yum/pluginconf.d/ and opened the configuration file for each plugin and made "enabled=1" to "enabled=0".

Now finally I updated my "yum" so that it reads the new repo and other settings once again. For that I did:


yum clean all
yum update


Voila.It's finally done. But hey wait.When I install a package from where will it select the package rpm.It will do that from the mounted ISO.That means I need to mount the ISO everytime.

Well I can use fstab for that.So I created a entry in /etc/fstab so that my ISO gets mounted automatically on boot.

Here was the entry I made in /etc/fstab:


/opt/RHEL5.iso /dvd/actual iso9660 defaults,ro,loop 0 0


Now I ran system-config-packages and search, browse, install and un-install RPM's easily. Now the GUI Package manager can search for installed as well as not installed rpm's. That's great. But the most important thing is that it if install a RPM which needs a dependency RPM (which is not installed) the Package manager will tell us that there is a dependency and will install it automatically.Great !. Same goes for un-installation of packages.If some package is acting as a dependency for some other package and we try to remove it then it will show a message and will ask us what to do.

For command line lovers "yum" command will work. Now they can search package via yum search or if they don't remember the name they can see the large list using yum list command.For installing yum install.This will handle the dependencies too.

Okay so I finally managed to find a way out. But it was a real pain.
But as they say "No Pain No Gain".

Meanwhile I have not formatted my RHEL5 but instead of that in my Vista partition I have installed Ubuntu 7.04 Herd 4. So now I have two Linux RHEL5 Beta2 (Client) and Ubuntu 7.04 Herd 4. Well I kept RHEL5 so that I can learn some more new things.

All in all Package management in RHEL/Fedora needs a great improvement.Today I call upon the developers to come together and help the Redhat guys to improve the "yum","pirut" and "system-config-packages".

14 comments:

Tom said...

That helped. I installed RHEL5 from scratch and the system-config-packages "Browse" tab was blank. I don't know why (maybe it's because I didn't register the machine yet with RedHat??). But your instructions were helpful.

One additional thing I had to do was find the comps.xml file and pass that to "createrepo" like this:

createrepo –g comps-rhel5-server-core.xml .

Jorgen van der Meulen said...

Fine article! Please note that adding an extra "-l" to mkisofs command keeps you from falling back to the 8.3 filename standard while mounting the created DVD image.
The command including all options looks like this:
mkisofs -o /opt/RHEL5.iso -l -r /media/dvd/

Tri Toan said...

That's great. It help me understand why I couldn't see any thing in Tab Browes in pirut. Thank you very much.
But one question: Could I use DVD/CD source instead of local source? (in the case don't have enough HDD space.
Thanks.

Gurbax said...

after creating a folder (dvd) im not able to complete the following command: and getting the following error:
===========================
[root@localhost dvd]# rpm -Uvh actual/client/createrepo*
error: File not found by glob: actual/client/createrepo*
=============================

please tell me what to do now

Gurbax Singh
Punjab Agricultural University, Ludhiana (INDIA)

Mrs Travel said...

Hi :D

If many thanks. This is one of the best articles I've read about RHEL.

For the other guy, there was a small syntax error the right command is rpm -Uvh ./actual/Server/createrepo*

Once again,
Thanks
Mrs Travel

Jadi said...

i got this error anyone plese help
GPG key retrieval failed: [Errno 5] OSError: [Errno 2] No such file or directory: '/opt/RPM-GPG-KEY'

rini said...

This is one of the very useful articles on rhel5. I ran into problems installing rpm's off of dvd. Thanks to you, i am able to do it now. Keep up the good work.

Mohsin said...

I'm getting the error same as Jadi anyone plz help us with this error...

GPG key retrieval failed: [Errno 5] OSError: [Errno 2] No such file or directory: '/opt/RPM-GPG-KEY'

Ralph said...

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Ruth

http://systemmemory.info

Surya said...

As moshin said i am too getting this error
I'm getting the error same as Jadi anyone plz help us with this error...

GPG key retrieval failed: [Errno 5] OSError: [Errno 2] No such file or directory: '/opt/RPM-GPG-KEY'

wilson said...

Hi Deependra Singh,

This is really great! It help me to solve one long-last problem which I need to add an application package after the OS is alreay installed.

I encountered the rpm dependency hell problem, and it looks cannot get through.

Luckly you suggestion works. I can copy all rpms into hard disk and re-run yum following your way and problem solved.

Thank you very much

wilson said...
This comment has been removed by the author.
pberg said...

For RHEL 5.3 at least, I noticed a few discrepancies:

#1 "createrepo" is referred to as "createre":

rpm -Uvh actual/client/creatre

#2 the GPG file on disk is called "rpm_gpg_" (notice the lower-case "gpg")

#3 after you make the modifications, if you try and install a package through yum, you might encounter a situation where yum is in use. check this via

ps -ef | egrep 'rpm|yum' | grep -v 'grep'

this will sometimes show yum-updatesd still running. kill it. then try installing the package again.

#4 import the gpg key in "rpm_gpg_" like this:

rpm --import /opt/rpm_gpg_

princefarhaan said...

Missed the "." after createrepo. Would be great if you can highlight this, Createrepo was asking the directory to be writable and I was trying to chchmod the dvd directory to make sure it "writable". Great post, thanks.