Reinstall RPM Removed in CentOS


RPM Package Manager (RPM) (Red Hat Package Manager) is a powerful command line driven package management system capable of installing, uninstalling, verifying, querying, and updating computer software packages and a core component of many Linux distributions, such as Red Hat Enterprise Linux, the Fedora Project, SUSE Linux Enterprise, openSUSE, CentOS, Tizen, Mageia and many others.

Overview

Simply put, RPM, similar to DEB in Ubuntu/Debian, set out to solve the software management problem by packaging metadata, which includes the info of package, the files, scripts and dependencies.

If you delete the rpm by mistake, following this tutorial to recover it.

There are two way to reinstall rpm. The one is compile and install rpm using gcc, that isn’t installed in new linux server commonly.

The other one is copy the related files from a normal machine with the same architecture and Linux distribution. As we known, in Linux System, everything is file. If the missing program is a standalone software or a static binary file, which can run independently without extra library, it will work well by directly copy and run. Otherwise, to coordinate with the related files, you may cost lots of time.

It’s hard to find out all the sparsely related files of rpm in a normal server. However, all the related files are contained in the package of rpm. A rpm package can be partly considered as compressed file, extracted by the rpm2cpio.

Operations

Check the architecture and version of target server

Here, I will use Centos 6.8 x86_64 for a example. You should change them in the following steps.

Install a normal server

Running the container images will be faster than creating the traditional virtual machine in another server.

pulling a base library image with the same architecture and version of target server from the mirror repositories for the higher speed.

Create a new Dockerfile to run a simple container.

Build the image from Dockerfile and run in the backgound.

Copy the rpm2cpio

Enter the inside of the running container.

Transfer a rpm2cpio from the normal server to our target server through the Secure copy protocol.

Ctrl+P+Q to return to the normal server. Change to the target server, make the copied rpm2cpio executable.

Reinstall the RPM

Download the rpm package from http://vault.centos.org, choose the correct one for yours.

Extract the files, change the permission and move to root directory.


SHELL NOTE:
the symbol {} expands to the filename of each file or directory found with find. The find command means find the directory of the current path and give them 755 permission one by one.
the symbol means stdout, and the tar command means compress three directory to stdout, move to root directory and decompress the three directory from stdout.


Rebuild the cache of package lists and install the rpm.

Reference

  1. https://deadlockprocess.wordpress.com/2010/07/18/how-to-reinstall-rpm-and-yum-without-rpm-and-yum-in-centosrhel/amp/
  2. https://www.linuxquestions.org/questions/linux-general-1/tar-tar-cvf-%7C-cd-root-%3B-tar-xvf-353132/
  3. https://superuser.com/questions/794963/in-a-linux-shell-why-does-backslash-newline-not-introduce-whitespace
  4. https://en.wikipedia.org/wiki/Static_build
  5. https://en.wikipedia.org/wiki/Everything_is_a_file
  6. https://unix.stackexchange.com/questions/195939/what-is-meaning-of-in-finds-exec-command

Leave a Reply

Your email address will not be published. Required fields are marked *