Sunday, February 14, 2010

Restoring RPM and YUM on RedHat after an accidental yum remove rpm

You can restore rpm using the following procedure:

Download the OS related RPM installer file at your local machine using wget.

Suppose for RedHat I download the file "rpm-4.1.1-1.7x.i386.rpm" from the link:

http://ftp.freshrpms.net/pub/freshrpms/redhat/testing/7.3/rpm-4.1.1/

Now make a folder suppose "RPM_test" at your local machine. Extract the rpm it that folder using the following commands.

rpm2cpio rpm-4.1.1-1.7x.i386.rpm | cpio -idmv
It will create the following folders inside your RPM_test directory.

------------------
kanchan rpm > ls -al
drwx------ 2 kanchan games 512 Feb 13 20:08 bin
drwx------ 5 kanchan games 512 Feb 13 20:08 etc
drwx------ 5 kanchan games 512 Feb 13 20:08 usr
drwx------ 4 kanchan games 512 Feb 13 20:08 var
kanchan rpm >
-----------------

Now copy the folder RPM_test using SCP or RSYNC command.

At the server enter into the directory "RPM_test/bin", you will get the following binary.

-------------------------------------------------
-rwxr-xr-x 1 kanchan games 2179291 Jul 23 2003 .rpm
-------------------------------------------------

Use the binary to restore your original rpm like

=================
./bin/rpm -vUh --nodeps --force rpm-4.1.1-1.8x.i386.rpm
=================

Your work done here.


If you want to install YUM just install all the files at the following link (It's for redhat for other version use corresponding repository):

-------------
http://ftp.freshrpms.net/pub/freshrpms/redhat/testing/7.3/rpm-4.1.1/
-------------

You can use the following script to download it in a temporary directory :

---------------
#!/bin/bash

for file in \

librpm404-4.0.5-1.7x.i386.rpm \
librpm404-4.0.5-1.7x.src.rpm \
librpm404-devel-4.0.5-1.7x.i386.rpm \
popt-1.7.1-1.7x.i386.rpm \
rpm-4.1.1-1.7x.src.rpm \
rpm-build-4.1.1-1.7x.i386.rpm \
rpm-devel-4.1.1-1.7x.i386.rpm \
rpm-python-4.1.1-1.7x.i386.rpm \
rpm404-python-4.0.5-1.7x.i386.rpm \
yum-2.0.3-0.rh7.rh.fr.i386.rpm \
yum-2.0.3-0.rh7.rh.fr.src.rpm \
do
wget http://ftp.freshrpms.net/pub/freshrpms/redhat/testing/7.3/rpm-4.1.1/$file;
done

---------------
Then install it using the following command:

==============
rpm -vUh --nodeps --force *.rpm
==============

You are done here.

For others OS distribution please view the links:

----------------------------
http://www.lazyhacker.com/blog/index.php/2009/12/28/restoring-rpm-and-yum-on-fedora-after-an-accidental-yum-remove-rpm
http://www.cyberciti.biz/tips/how-to-extract-an-rpm-package-without-installing-it.html


http://www.fedoralegacy.org/docs/yum-rh8.php
http://wiki.centos.org/HowTos/PackageManagement/YumOnRHEL
http://eric.lubow.org/2008/misc/adding-yum-to-centos-5/
http://www.electrictoolbox.com/install-yum-with-rpm-on-centos/
http://upstre.am/2009/04/30/installing-yum-on-centos-53/
http://kb.in2net.net/questions/118/Installing+Yum
----------------------------

1 comment:

 Linux Interview  Linux booting process EXT4 XFS file system runlevel scan disk hba driver systool -c fc_host lspci -nn | grep -i hba single...