How to Extract Files from an Oracle Linux RPM Package Without Installing the Package
July 2011
By Lenz Grimmer
This article explains how you can look into an Oracle Linux RPM package and extract files from it without having to install the entire package. This might be handy if you don't have root permissions on a system, but you need to access some files that are contained inside an RPM package.
About the RPM Package Manager
Software and applications on Linux systems are usually organized in the form of "packages" that contain all the relevant parts of an application (for example, binaries, configuration files, and libraries). Oracle Linux uses RPM, the well-known RPM package manager, to facilitate the installation, upgrade, and removal of application packages. On the other hand, Debian Linux and derivatives such as Ubuntu Linux use an alternative packaging format called deb. Although both have their pros and cons and get the job done, I'll focus on RPM in this article.
In addition to referring to the .rpm file format, "RPM" is also the name of a command line tool that keeps track of package versions and the files contained within a package by storing this information in a local Oracle Berkeley DB database. RPM ensures that requirements and dependencies, as well as conflicts between packages, are taken into consideration. It is aware of configuration files and can take care of not overwriting changes made by an administrator during an update. Additionally, RPM is capable of verifying the integrity and authenticity of a package by supporting cryptographic signatures and file checksums.
The oracle-validated
Package
RPM packages are archive files, similar to.zip
or.tar.gz
files. The archiving format used for.rpm
files is cpio
, with some additional metadata attached to it. You can use therpm
command line tool to obtain this information and to look at the contents of a package without installing the package.
In the following examples, I use theoracle-validated
package for illustration purposes, but you can perform the same steps with any other RPM package.
Theoracle-validated
package is very useful for preparing an Oracle Linux system before installing Oracle Database, because it performs many of the required preparations in one step. Among other tasks, this package creates the appropriate user and group accounts, configures various Linux kernel parameters, and ensures that all required libraries and applications are installed.
Theoracle-validated
package is included in the latest Oracle Linux 5 distributions, but you can also download the package separately from oss.oracle.com, as shown in Listing 1.
Listing 1: Downloading the oracle-validated
Package
$ wget http://oss.oracle.com/el5/oracle-validated/oracle-validated-1.1.0-7.el5.x86_64.rpm
--2011-07-27 10:18:27-- http://oss.oracle.com/el5/oracle-validated/oracle-validated-1.1.0-7.el5.x86_64.rpm
Resolving oss.oracle.com... 141.146.12.120
Connecting to oss.oracle.com|141.146.12.120|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23838 (23K) [application/x-rpm]
Saving to: `oracle-validated-1.1.0-7.el5.x86_64.rpm'
100%[======================================>] 23,838 44.1K/s in 0.5s
2011-07-27 10:18:28 (44.1 KB/s) - `oracle-validated-1.1.0-7.el5.x86_64.rpm' saved [23838/23838]
Now you have a local copy of the package, named oracle-validated-1.1.0-7.el5.x86_64.rpm,
in your current directory, as shown in Listing 2.
Listing 2: Verifying You Have a Local Copy of the Package
$ ls -lh oracle-validated-1.1.0-7.el5.x86_64.rpm
-rw-r--r-- 1 lenz lenz 24K Nov 17 2010 oracle-validated-1.1.0-7.el5.x86_64.rpm
Let's first take a look at the package's metadata. RPM packages contain quite a lot of useful information about themselves, which you can obtain without having to install the package, as shown in Listing 3.
Listing 3: Displaying Metadata for a Package
$ rpm -qip oracle-validated-1.1.0-7.el5.x86_64.rpm
warning: oracle-validated-1.1.0-7.el5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 1e5e0159: NOKEY
Name : oracle-validated Relocations: (not relocatable)
Version : 1.1.0 Vendor: Oracle
Release : 7.el5 Build Date: Wed Nov 17 20:03:20 2010
Install Date: (not installed) Build Host: ca-build9.us.oracle.com
Group : Test Environment/Libraries Source RPM: oracle-validated-1.1.0-7.el5.src.rpm
Size : 61204 License: GPL
Signature : DSA/SHA1, Wed Nov 17 20:03:31 2010, Key ID 66ced3de1e5e0159
Summary : Verifies and sets system parameters based on Oracle validated configuration recommendations for OEL5
Description :
This package verifies and sets system parameters based on Oracle validated
configuration recommendations for Oracle Enterprise Linux Release 5
Files affected: /etc/sysctl.conf, /etc/security/limits.conf, /etc/modprobe.conf, /boot/grub/menu.lst.
For changes to modules, this package installation will modify module parameters and re-insert.
We can also look at the files included in the package, as shown in Listing 4.
Listing 4: Listing the Files Included a Package
$ rpm -qlp oracle-validated-1.1.0-7.el5.x86_64.rpm
/etc/rc.d/init.d/oraclevalidated
/etc/sysconfig/oracle-validated/oracle-validated-verify
/etc/sysconfig/oracle-validated/oracle-validated.params
/usr/bin/oracle-validated-verify
Three Ways to Examine Package Files
Let's say we wanted to take a closer look at the init script /etc/rc.d/init.d/oraclevalidated
. How can we do that without having to install the package, which would also drag in a lot of additional software that we don't need at this point? There are actually several ways to achieve this goal. I'll cover three alternatives.
Remember that RPM utilizes CPIO for the actual file archiving. So one option would be to simply extract the files using the cpio
command line utility. However, we first need to strip the RPM metadata from the archive; otherwise, CPIO will complain about the file format.
Most distributions ship with a tool named rpm2cpio
, which extracts the cpio
archive from an RPM package. You can either redirect its output into a local file, or pipe it right into the cpio
command.
So let's start by converting the RPM package into a cpio
archive and letting CPIO list its contents, as shown in Listing 5.
Listing 5: Converting a Package into a cpio Archive
$ rpm2cpio oracle-validated-1.1.0-7.el5.x86_64.rpm | \
cpio -i --list
./etc/rc.d/init.d/oraclevalidated
./etc/sysconfig/oracle-validated/oracle-validated-verify
./etc/sysconfig/oracle-validated/oracle-validated.params
./usr/bin/oracle-validated-verify
122 blocks
The -i
(or --extract
) option can be used to list as well as extract files from an archive. You can provide file names (including wildcards) to restrict the output to matching file name patterns, as shown in Listing 6.
Listing 6: Restricting the Output to Matching File Names
$ rpm2cpio oracle-validated-1.1.0-7.el5.x86_64.rpm | \
cpio --extract --list "*oraclevalidated"
./etc/rc.d/init.d/oraclevalidated
122 blocks
CPIO does not create directories by default. Because we can't (and don't want to) extract the file in question into the "real" /etc/rc.d/init.d
directory, we need to instruct cpio
to create subdirectories when extracting files. Therefore, it' a good idea to create a separate working directory (for example, in /tmp
), as shown in Listing 7, so you don't accidentally clutter your home directory.
Listing 7: Extracting a File into a Temporary Directory
$ mkdir /tmp/rpm2cpio
$ cp oracle-validated-1.1.0-7.el5.x86_64.rpm /tmp/rpm2cpio
$ cd /tmp/rpm2cpio
$ rpm2cpio oracle-validated-1.1.0-7.el5.x86_64.rpm | \
cpio --extract --make-directories --verbose "*oraclevalidated"
./etc/rc.d/init.d/oraclevalidated
122 blocks
There's our file. Now you can now take a look at its content, as shown in Listing 8.
Listing 8: Verifying You Have the Extracted File
$ [lenz@thebe rpm2cpio]% ls -lh etc/rc.d/init.d/oraclevalidated
-rwxr-xr-x 1 lenz lenz 1.3K Jul 27 10:45 etc/rc.d/init.d/oraclevalidated
As an alternative to using the command line, you can use file managers or GUI tools. Many of the Linux-based utilities can read and open RPM packages directly. For example, there is the GNU Midnight Commander, which is a free implementation of the classic Norton Commander utility. You can invoke it from the command line, and it will open an RPM package if you highlight the package name and press Enter, as shown in Figure 1.
Figure 1: Opening an RPM Package Using GNU Midnight Commander
The actual files are contained in the CONTENTS.cpio
file, as shown in Figure 2.
Figure 2: Viewing the Content of an RPM Package Using GNU Midnight Commander
You can navigate the archive's directory structure like any other file system, as shown in Figure 3.
Figure 3: Navigating the Archive's Directory Structure
And you can open a file by highlighting its name and pressing Enter, as shown in Figure 4.
Figure 4: Opening a File
Enter the /etc/rc.d/init.d/
directory and press F3 to view the file in the built-in text viewer, as shown in Figure 5.
Figure 5: Viewing a File
You can exit the viewer by pressing the F10 function key.
If you are using the GNOME desktop, you can simply use File Roller, the GNOME archive manager, to open an RPM package. You invoke File Roller via Nautilus, the GNOME file manager, by right-clicking the RPM file icon and choosing Open With Archive Manager, as shown in Figure 6.
Figure 6: Using File Roller to Open an RPM Package
Alternatively, you can start the archive manager from the command line by passing the RPM package name as an argument, as shown in Listing 9.
Listing 9: Starting File Roller from the Command Line
$ file-roller oracle-validated-1.1.0-7.el5.x86_64.rpm
You can now navigate the RPM package's content like any other archive. Click the dot directory to see the top-level directory structure, as shown in Figure 7.
Figure 7: Viewing the Top-Level Directory Structure
Now you can navigate into the /etc/rc.d/init.d
subdirectory to find the oraclevalidated script. You can then extract it from the archive by using drag and drop, or you can view the file directly by right-clicking it and selecting Open, as shown in Figure 8.
Figure 8: Viewing a File from File Roller
The script is then displayed in the GNOME text editor (or whatever application you associated with displaying text files).
As you can see, there are many options for accessing the content and files of an RPM package without having to install the package.
Resources
Here are resources referenced earlier in this document:
- Oracle Linux: http://www.oracle.com/linux/
- RPM: http://rpm.org/
deb
file format: http://en.wikipedia.org/wiki/Deb_%28file_format%29- Oracle Berkley DB: http://www.oracle.com/database/technologies/related/berkeleydb.html
- CPIO: http://en.wikipedia.org/wiki/Cpio
oracle-validated
package in the Oracle Linux 5 distribution: http://oss.oracle.com/el5/oracle-validated/- GNU Midnight Commander: http://www.midnight-commander.org/