Wednesday, October 07, 2009

Linux: Configure a local repository from ISO image for YUM

yum is an interactive, rpm based, package manager. It can automatically perform system updates, including dependancy analysis and obsolete processing based on "repository" metadata. It can also perform installation of new packages, removal of old packages and perform queries on the installed and/or available packages among many other commands/services (see below). yum is similar to other high level package managers like apt-get and smart.

After install Fedora Core, some default YUM repository is stored in /etc/yum.repos.d.  These repositories are URLs located some where in the Internet. You need an internet connection in order to enjoy the convenient of yum to update your system.  It is rather inconvenient if you have a slow internet connection or you have many machines to update via yum.

A good approach to overcome these problems is setup a local repositories without to avoid grabbing RPM packages via Internet.

Setup a local repository for YUM

First, we need to disable default YUM repository configuration installed by Fedora:

[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls -al
total 28
drwxr-xr-x.  2 root root 4096 2009-10-07 09:16 .
drwxr-xr-x. 56 root root 4096 2009-10-07 09:17 ..
-rw-r--r--.  1 root root 1785 2009-05-12 06:45 fedora-rawhide.repo
-rw-r--r--.  1 root root 1144 2009-05-12 06:45 fedora.repo
-rw-r--r--.  1 root root 1105 2009-05-12 06:45 fedora-updates.repo
-rw-r--r--.  1 root root 1163 2009-05-12 06:45 fedora-updates-testing.repo

To disable these repositories, rename all files to *.repo.old:

[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls -al
total 28
drwxr-xr-x.  2 root root 4096 2009-10-07 09:16 .
drwxr-xr-x. 56 root root 4096 2009-10-07 09:17 ..
-rw-r--r--.  1 root root 1785 2009-05-12 06:45 fedora-rawhide.repo.old
-rw-r--r--.  1 root root 1144 2009-05-12 06:45 fedora.repo.old
-rw-r--r--.  1 root root 1105 2009-05-12 06:45 fedora-updates.repo.old
-rw-r--r--.  1 root root 1163 2009-05-12 06:45 fedora-updates-testing.repo.old

Create local repository

In this example, the local repository is an Fedora Core ISO image mount under /mnt/cdrom.

Create a local repository configuration file it and store in /etc/yum.repos.d:

[root@localhost yum.repos.d]# cat local.repo
[local]
name=ISO
baseurl=file:///mnt/cdrom

You may now start using YUM to install packages as lightning speed:

[root@localhost etc]# yum install samba

Troubleshoot: Public key for lzma-libs-4.32.7-2.fc11.i586.rpm is not installed

If you encounter an error message like “Public key for ***.rpm is not installed” when running “yum install”, you need to import the RPM public key for the local repository into RPM database first.

The RPM public key is usually reside in the root of ISO image:

[root@localhost cdrom]# ls /mnt/cdrom -al
total 453
drwxr-sr-x. 7 root  499   4096 2009-06-03 06:05 .
drwxr-xr-x. 3 root root   4096 2009-10-07 09:11 ..
-rw-r--r--. 1 root  499     37 2009-06-03 06:04 .discinfo
drwxr-xr-x. 3 root root   2048 2009-06-03 06:02 EFI
-rw-r--r--. 2 root root  18363 2007-07-04 06:06 GPL
drwxr-sr-x. 3 root  499   2048 2009-06-03 06:04 images
drwxr-sr-x. 2 root  499   2048 2009-06-03 06:02 isolinux
-rw-r--r--. 1 root  499     95 2009-06-03 06:05 media.repo
drwxr-sr-x. 2 root  499 405504 2009-06-03 05:48 Packages
-rw-r--r--. 2 root root  10581 2009-05-14 12:59 README-BURNING-ISOS-en_US.txt
drwxr-sr-x. 2 root  499   4096 2009-06-03 06:05 repodata
lrwxrwxrwx. 2 root root     29 2009-06-03 05:51 RPM-GPG-KEY-fedora -> RPM-GPG-KEY-fedora-11-primary
-rw-r--r--. 2 root root   1653 2009-05-12 06:45 RPM-GPG-KEY-fedora-11-primary
lrwxrwxrwx. 2 root root     29 2009-06-03 05:51 RPM-GPG-KEY-fedora-i386 -> RPM-GPG-KEY-fedora-11-primary
-rw-r--r--. 2 root root   1694 2009-05-12 06:45 RPM-GPG-KEY-fedora-ia64
lrwxrwxrwx. 2 root root     29 2009-06-03 05:51 RPM-GPG-KEY-fedora-ppc -> RPM-GPG-KEY-fedora-11-primary
lrwxrwxrwx. 2 root root     29 2009-06-03 05:51 RPM-GPG-KEY-fedora-ppc64 -> RPM-GPG-KEY-fedora-11-primary
lrwxrwxrwx. 2 root root     29 2009-06-03 05:51 RPM-GPG-KEY-fedora-x86_64 -> RPM-GPG-KEY-fedora-11-primary
-r--r--r--. 1 root root   4011 2009-06-03 06:05 TRANS.TBL
-rw-r--r--. 1 root  499   1437 2009-06-03 06:04 .treeinfo

To install the public key, try this:

[root@localhost cdrom]# rpm --import RPM-GPG-KEY-fedora

You may proceed to "yum install” as usual now.

No comments: