2012년 10월 19일 금요일

Make local YUM repository

Operating Systems based on RPM like Redhat, CentOS and Fedora have YUM (Yellow dog Updater, Modified) for providing system automatic update and package installer / uninstaller. 

Usually, YUM has repositories which have various package information and locations on the Internet. The repository also is placed on NFS or local storage for the purpose of security. Basically, lots of companies don't allow outgoing and incoming traffics except for really needed ports. As part of the security policy, I had to make a CentOS yum repository on local storage.

I created a CentOS 6.2 VM and attached the 1st installation DVD. I checked state of CD-ROM drive. When a VM is created on VMware, CD-ROM path is /dev/sr0 not /dev/cdrom. 
$ ls -al /dev/cdrom
lrwxrwxrwx. 1 root root 3 Oct 18 14:10 /dev/cdrom -> sr0
$ ls -al /dev/sr0
brw-rw----. 1 root cdrom 11, 0 Oct 18 14:10 /dev/sr0

I made a directory that will be used for mounting point and executed 'mount' command.
$ mkdir /mnt/cdrom
$ mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: no medium found on /dev/sr0 

But I failed to mount because CD-ROM drive was not connected to the VM. 
I had made the drive connected  via VI client. It should enabled the check-box "Connected"

$ mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only

I unmounted the DVDs to convert them into iso files.
$ umount /mnt/cdrom
$ dd if=/dev/sr0 of=/iso/CentOS-x86_64-6.2.iso
8638924+0 records in
8638924+0 records out
4423129088 bytes (4.4 GB) copied, 226.128 s, 19.6 MB/s

# change to CentOS' the second CD 
$ dd if=/dev/sr0 of=/iso/CentOS-x86_64-6.2-2.iso
2574156+0 records in
2574156+0 records out
1317967872 bytes (1.3 GB) copied, 46.7755 s, 28.2 MB/s

I made the directories which are the location of repository.
$ mkdir -p /mnt/iso/{1,2}

# mounted iso files.
$ mount -o loop /iso/CentOS-x86_64-6.2.iso /mnt/iso/1/
$ mount -o loop /iso/CentOS-x86_64-6.2-2.iso /mnt/iso/2/

# find 'createrepo' command 
$ find /mnt/iso -name 'createrepo*'
/mnt/iso/1/Packages/createrepo-0.9.8-4.el6.noarch.rpm

# install createrepo
$ rpm -Uvh /mnt/iso/1/Packages/createrepo-0.9.8-4.el6.noarch.rpm
warning: /mnt/iso/1/Packages/createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
        deltarpm is needed by createrepo-0.9.8-4.el6.noarch
        libxml2-python is needed by createrepo-0.9.8-4.el6.noarch
        python-deltarpm is needed by createrepo-0.9.8-4.el6.noarch

# solving dependencies. 
$ rpm -ivh /mnt/iso/1/Packages/deltarpm-**.el6.x86_64.rpm /mnt/iso/1/Package
s/python-deltarpm-**.el6.x86_64.rpm /mnt/iso/1/Packages/libxml2-python-**.el6.x86_64.rpm /mnt/iso/1/Packages/createrepo-**.rpm
warning: /mnt/iso/1/Packages/deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing...     ################################# [100%]
   1:deltarpm   ################################# [ 25%]
   2:python-deltarpm  ############################ [ 50%]
   3:libxml2-python    ############################ [ 75%]
   4:createrepo   ############################### [100%]

# run 'createrepo' to create repomd (xml-rpm-metadata)
$ cd /mnt/iso
$ createrepo .
466/6294 - 1/Packages/system-config-date-docs-1.0.9-1.el6.noarch.rpm
iso-8859-1 encoding on Ville Skytt? - 2.8.2-2
6294/6294 - 2/Packages/zsh-html-4.3.10-4.1.el6.x86_64.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata

The repo data was created.
$ ls -al /mnt/iso
total 10
drwxr-xr-x. 7 root root 4096 Dec 16  2011 1
drwxr-xr-x. 3 root root 2048 Dec 16  2011 2
drwxr-xr-x. 2 root root 4096 Oct 18 14:39 repodata

The remaining step is that create *.repo file to let CentOS use it as yum repository.
$ vi /etc/yum.repos.d/local.repo
[local]
name=Local CentOS ISO Repo
baseurl=file:///mnt/iso/
enabled=1
gpgcheck=0

$ yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras local updates
Cleaning up Everything
$ yum list
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot find a valid baseurl for repo: base

I remove all default repository information files.
$ mv /etc/yum.repo.d/Cent* /etc/

$ yum list
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
local                                                                  | 1.3 kB     00:00 ...
local/primary                                                      | 1.9 MB     00:00 ...
local                                                                               6294/6294
Installed Packages
ConsoleKit.x86_64                   0.4.1-3.el6                           @anaconda-CentOS-201112091719.x86_64/6.2
ConsoleKit-libs.x86_64             0.4.1-3.el6                           @anaconda-CentOS-201112091719.x86_64/6.2
.....
.....

댓글 없음:

댓글 쓰기