Linux RPM package files to extract (cpio Command) Comments

Before explaining how to extract files from an RPM package, the first to learn about the system cpio command.

cpio command into the package from the archive file read and, in other words, may be extracted cpio command file (or directory) from the archive, the archive may be copied to the package file (or directory).

The archive, library files can also be called, in fact, tar or cpio file format, the file contains other files as well as some relevant information (file name, access rights, etc.). The archive can be both disk file or a tape or pipe.

cpio command can be seen as a backup or restore command, because it can be data (files) backed up to cpio archive library, you can also use cpio document library for data recovery.

Use cpio command to back up or restore data, note the following:

  • When using the backup data if cpio using absolute path, then automatically reverts to restore data at an absolute path; Similarly, if the backup data using a relative path, then the data is restored to the relative path.
  • cpio command themselves unable to specify a backup (or restore) files, you need the full path of the target file (or directory) can read the success, so this command is often used in conjunction with the find command.
  • cpio command does not automatically overwrite the same file when restoring data, it will not create directories (directly extract to the current folder).


cpio command mainly in the following three basic modes:

  1. "-O" mode: refers to a copy-out mode, is to back up data to a database file, the command format is as follows:

    [Root @ localhost ~] # cpio -o [vcB]> [File Shu Device]

    Meaning of each option are as follows:
    • -o: copy-out mode, the backup;
    • -v: displays the backup process;
    • -c: the use of newer portable format storage;
    • -B: setting input / output block 5120Bytes, instead 512Bytes mode;

    For example, using backup data cpio command follows:

    [root @ localhost ~] #find / etc -print | cpio -ocvB> /root/etc.cpio
    # specifies the use of the find command to back up / etc / directory, use> Export to etc.cpio file
    [root @ localhost ~] # -H etc.cpio II
    -rw - R & lt - R & lt -.. 1. 6 dated the root the root 21M 12:29 etc.cpio. 5
    # file generating etc.cpio

  2. "-I" mode: refers to the copy-in mode, is to recover data from a file repository, the command format is as follows:

    [Root @ localhost ~] # cpio -i [vcdu] <[file | device]

    The meaning of each option are as follows:
    • -i: copy-in mode, reduction;
    • -v: display reduction process;
    • -c: Newer portable format storage;
    • -d: New directory automatically restore;
    • -u: automatically use the newer file overwrites older files;

    For example, using the data backed up before cpio restore command as follows:

    [root @ localhost ~] # cpio -idvcu </root/etc.cpio
    # restore backup etc
    # If we look at the current directory / root /, you will find no generation / etc / directory. This is because when the backup / etc / directory using the absolute path, so the data is directly restored to / etc / directory system, but is not generated in the / root / etc / directory

  3. "-p" mode: refers to the copy mode, use the -p mode can read all files from a directory, but does not back them up to cpio library, but directly copied to another file.

    For example, the use of -p / boot / copied to / test / boot directory execute the following command:

    [root @ localhost ~] # cd / tmp /
    # into the / tmp / directory
    [root @ localhost tmp] -rf * #rm
    all data # Delete / tmp / directory
    [root @ localhost tmp] # mkdir the Test
    # create a backup directory
    [root @ localhost tmp] # the Find / boot / -print | cpio -p / tmp / the Test
    # backup / boot / directory to / tmp / test / directory
    [root @ localhost tmp] # LS the Test / the Boot
    # in / tmp / test / directory backup the / boot / directory

Use cpio command to extract the RPM package in the specified file

In the use of the server process, if the system file is accidentally deleted or modified by mistake, consider using cpio extracted commands of raw RPM package file system, the source file is to repair the malfunction.

RPM package allows the package file to extract one by one, the command format is as follows:

[Root @ localhost ~] # rpm2cpio package full name | cpio -idv absolute file path.

The command, that is, the RPM rpm2cpio packets into cpio command format, can be extracted from the specified library file cpio files cpio command.

For example, suppose we are not careful the / bin / ls command deleted, usually 2 ways to repair:

  1. The coreutils-8.4-19.el6.i686 package (RPM package comprising ls command) and then install it by -force option;
  2. Use cpio command extracted from the package coreutils-8.4-19.el6.i686 / bin / ls file and then copy it to the appropriate location;


Here we choose the first two ways. Some readers may ask, How do I know that the ls command is part of the RPM package it? Very simple to use  rpm -qf command to, as follows:

[root @ localhost ~] # -qf RPM / bin / ls
coreutils-8.4-19.el6.i686
# ls view files belong to which package

On this basis, we simply use the RPM package from cpio extracted commands ls command file and then copy it to a corresponding position to achieve the following command:

[root @ localhost ~] # mv / bin / ls / root /
# to / bin / ls command to move to the next / root / directory, create the illusion of accidentally deleted
[root @ localhost ~] # LS
-bash: LS: not the Command found
# ls command at this time, the system will report "command not found" error
[root @ localhost ~] # rpm2cpio /mnt/cdrom/Packages/coreutils-8.4-19.el6.i686.rpm
| cpio -idv ./bin / ls
# extract the ls command files to the current directory
[root @ localhost ~] # cp / root / bin / ls / bin /
# copy the extracted ls command file to the / bin / directory
[root @ localhost ~] # LS
Anaconda-ks.cfg bin inittab install.log install.log.syslog LS
# can see, ls command and can be properly used

example:

  1. First use the command rpm display a list of files contained
rpm2cpio your.rpm | cpio -t
  1. Then find the lists displayed files you need, execute the following command:
rpm2cpio your.rpm | cpio -id your-file

Guess you like

Origin www.cnblogs.com/life-Meer/p/11407228.html