cpio and rpm2cpio howto

Thursday, June 18th, 2009

To extract a cpio file:

cpio -iv < cpio_file

To list the contents of a cpio file:

cpio -itv < cpio_file

To create a cpio file with all files in the current directory:

ls | cpio -o > cpio_file

To extract all files from an RPM:

rpm2cpio RPM_file | cpio -idv

To extract individual file(s) from an RPM:

rpm2cpio RPM_file | cpio -id individual_file(s)

e.g. Extracting libcrypto.so.0.9.7a and libssl.so.0.9.7a from openssl-0.9.7a-2.i386.rpm:

rpm2cpio openssl-0.9.7a-2.i386.rpm | cpio -it egrep “libcrypto.so.0.9.7a|libssl.so.0.9.7a”

-rwxr-xr-x 1 root root 992092 Feb 27 12:10 ./lib/libcrypto.so.0.9.7a
-rwxr-xr-x 1 root root 216004 Feb 27 12:10 ./lib/libssl.so.0.9.7a

rpm2cpio openssl-0.9.7a-2.i386.rpm | cpio -idv ./lib/libssl.so.0.9.7a ./lib/libcrypto.so.0.9.7a

This will extract the two files from the RPM into a ./lib subdirectory.

Multiple gcc versions

Thursday, June 18th, 2009

Lets say you have this package from FC11:

[root@localhost ~]# rpm -q gcc
gcc-4.4.0-4.i586

But you have an source code that needs gcc-4.3 to compile or something lower.

So download lets say this: gcc-4.3.2-7.i386.rpm then:

mkdir newgcc && cd newgcc
download http://pathtogcc/gcc-4.3.2-7.i386.rpm
rpm2cpio gcc-4.3.2-7.i386.rpm | cpio -idv

Now you should have in newgcc/usr/bin/gcc.

Or download the gcc package you need from ftp://ftp.gnu.org and compile it with –prefix=$HOME/newgcc