blog.packagecloud.io Open in urlscan Pro
13.32.98.187  Public Scan

URL: https://blog.packagecloud.io/inspect-extract-contents-rpm-packages/
Submission: On March 16 via manual from BE — Scanned from DE

Form analysis 2 forms found in the DOM

<form class="footer__form" onsubmit="newsletterSubscribe(event)">
  <p class="footer__form-heading">Subscribe to our newsletter</p>
  <input type="email" class="footer__form-input" name="email" id="email" placeholder="Email Address" required="">
  <input type="submit" value="Subscribe" class="footer__form-btn">
  <p class="footer__form-confirm footer__form-confirm">Thank you for subscribing!</p>
</form>

<form class="footer__form" onsubmit="newsletterSubscribe(event)">
  <p class="footer__form-heading">Subscribe to our newsletter</p>
  <input type="email" class="footer__form-input footer__form-input--mobile" name="email" id="email" placeholder="Email Address" required="">
  <input type="submit" value="Subscribe" class="footer__form-btn footer__form-btn--mobile">
  <p class="footer__form-confirm footer__form-confirm">Thank you for subscribing!</p>
</form>

Text Content

 * Products
   PACKAGE MANAGEMENT NPM Repository Debian Repository Maven Repository RPM
   Repository RubyGem Repository Python Repository Helm Repository
   CI INTEGRATIONS CircleCI Travis CI Jenkins Buildkite GitHub Actions
   BUILD TOOL INTEGRATIONS Maven Lein Gradle SBT
 * Plans & Pricing
 * Use Cases
 * Resources
   RESOURCES Docs Blog
 * +1 (888) 301-8247
 * Login
 * Get Started


Fast, reliable, and secure software starts here.
Start Free Trial


INSPECTING AND EXTRACTING RPM PACKAGE CONTENTS

Oct 12, 2015
6 min read
rpm-how-to Joe Damato


TL;DR

This post covers how to list files, show package information and extract the
contents of an RPM package. There will be example commands presented for
extracting RPM package files and showing information for packages that are both
installed, and not-installed on a system.

 


EXTRACT FILES FROM AN RPM (QUICK START)

$ rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm | cpio -idmv

Continue reading this post for more information about listing and extracting
RPMs.


CREATE AN RPM REPOSITORY FOR FREE.





Try Packagecloud


RELATED POST

Inspecting and extracting Debian package contents

 


WHAT IS AN RPM PACKAGE?

An RPM package is simply a header structure on top of a CPIO archive. The
package itself is comprised of four sections: a header with a leading identifier
(magic number) that identifies the file as an RPM package, a signature to verify
the integrity of the package, the header or ‘tagged’ data containing package
information, version numbers, and copyright messaging, and the archive
containing the actual program files.

 


LIST FILES IN AN RPM PACKAGE FILE USING THE RPM COMMAND

The RPM package manager rpm comes with various utilities to interact with
packages. The following command will list all the files inside an RPM package:

$ rpm -qlp ./path/to/test.rpm 

For example:

$ rpm -qlpv ./packagecloud-test-1.1-1.x86_64.rpm

-rwxr-xr-x   1   root    root    8286 Jul 16  2014 /usr/local/bin/packagecloud_hello


In this example, the rpm command is used with the flag -q to specify it as a
query command, -l to list the files in the package, and -p so it knows to query
the uninstalled package file. The -v flag (verbose) just provides additional
information (permissions, owner, etc.) for the sake of this example. As we can
see, the package installs an executable binary
called packagecloud_hello into /usr/local/bin/.

 


LIST FILES IN AN INSTALLED RPM PACKAGE

Use the rpm command with -q and -l flags to list the files from an installed RPM
package:

$ rpm -ql packagecloud-test


NOTE the use of a package’s name in the previous command and not the path to a
specific RPM package.

 


EXTRACT CPIO ARCHIVE FROM RPM PACKAGES

To extract files from an RPM package you must first extract a cpio archive from
the package itself. RedHat provides a utility called rpm2cpio which does exactly
that:

$ rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm


 


EXTRACT FILES FROM AN RPM PACKAGE’S CPIO ARCHIVE

The rpm2cpio command will output (to stdout) a cpio archive from the RPM
package. To extract the package files we’ll use the output from rpm2cpio and
then use the cpio command to extract and create the files we need.

For example:

$ rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm | cpio -idmv
./usr/local/bin/packagecloud_hello
17 blocks


The cpio command copies files to and from archives. In the example above, we
use cpio with the -i flag to extract the files from the archive, -d to create
the leading directories where needed, and -m to preserve the file modification
times when creating files. The -v flag (verbose) is to list the files processed
for the sake of this example.

The result of our previous example is the creation of a ./usr/ folder in our
working directory containing the files from the RPM
package packagecloud-test-1.1-1.x86_64.rpm.

$ file usr/local/bin/packagecloud_hello

usr/local/bin/packagecloud_hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x77fe4f2fa02ee973bf4d74867729e950fcde7107, not stripped


NOTE that simply extracting package files to the root directory
does NOT properly install a package. Use the yum or rpm tools to correctly
install RPM packages.

 


SHOW RPM PACKAGE PREINSTALL AND POSTINSTALL SCRIPTS

To show the scripts that will run when a package is installed or uninstalled
from a system, use the --scripts flag when querying a package using rpm. The
following command will show the scripts for an uninstalled
package test-1.1-1.el6.x86_64.rpm:

$ rpm -qp --scripts ./packagecloud-test-1.1-1.x86_64.rpm


This will output something like:

preinstall scriptlet (using /bin/sh):
# Do something

postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then
    # Do another thing

fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then
    # Do something else

fi
postuninstall scriptlet (using /bin/sh):

# Do things here, too


To view the scriptlets of an already installed package, you can use the
following syntax when using rpm

$ rpm -q --scripts <packagename>


 


VIEW CONTENTS OF RPM PACKAGES ON REMOTE REPOSITORIES USING REPOQUERY

repoquery is provided by the yum-utils package, make sure it’s installed:

$ yum install yum-utils


The repoquery command is used to query information from Yum repositories
installed on the system. By default, the repoquery command will download
the Yum repo metadata and update the cache. To run repoquery entirely from
the Yum cache, use the -C or --cache flag. To list the contents of a package,
pass the --list flag to the repoquery command:

$ repoquery --list <packagename>


For example:

$ repoquery --list packagecloud-test
/usr/local/bin/packagecloud_hello


This can be useful when viewing the contents of packages that aren’t downloaded
or installed on your the system. repoquery will only provide information on
packages avaliable in the configured Yum repositories.


SET UP YOUR OWN PACKAGE REPOSITORY.





Try Packagecloud


CONCLUSION

Understanding how packages interact with the systems they’re installed on can be
helpful in day-to-day operations. By knowing that the RPM package is comprised
of a cpio archive and header data, we can extract the information needed with
already existing tools (rpm2cpio and cpio) and use the RPM toolchain to query,
inspect, and view the contents of an RPM package.



SHARE THIS ARTICLE VIA:




TAKE THE HEADACHE OUT OF DISTRIBUTING PACKAGES.

Fast, reliable, and secure software starts here.



Try Packagecloud
Hungry for more knowledge?


RELATED POSTS

YUM CHEAT SHEET -- COMPREHENSIVE LIST OF YUM COMMANDS AND FLAGS

This YUM cheat sheet includes essential commands that you will use everyday i...

WHAT IS RPM AND HOW DO I USE IT?

This article explains about RPM and how you can use it. Also, you can find th...

WHAT IS A CUSTOM DOMAIN FOR YOUR REPOSITORY?

This article is a guide to help you know how to host your repo on a custom do...

Company
 * About
 * Blog
 * Plans & Pricing

Support
 * Contact
 * Status
 * Community

Package MGMT & Hosting
 * NPM Repository
 * Debian Repository
 * Maven Repository
 * RPM Repository
 * RubyGem Repository
 * Python Repository
 * Helm Repository

CI Integrations
 * CircleCI
 * Travis CI
 * Jenkins
 * Buildkite
 * GitHub Actions

Build Tool Integrations
 * Maven
 * Leiningen
 * Gradle
 * SBT

Legal
 * Terms of Service
 * Privacy Policy
 * Security & Compliance



© 2023 Packagecloud. All trademarks and
registered marks belong to their respective owners.

Subscribe to our newsletter

Thank you for subscribing!

STATUS

Subscribe to our newsletter

Thank you for subscribing!

Company
 * About
 * Blog
 * Plans & Pricing

Support
 * Contact
 * Status
 * Community

Package MGMT & Hosting
 * NPM Repository
 * Debian Repository
 * Maven Repository
 * RPM Repository
 * RubyGem Repository
 * Python Repository
 * Helm Repository

CI Integrations
 * CircleCI
 * Travis CI
 * Jenkins
 * Buildkite
 * GitHub Actions

Build Tool Integrations
 * Maven
 * Leiningen
 * Gradle
 * SBT

Legal
 * Terms of Service
 * Privacy Policy
 * Security & Compliance

STATUS


© 2023 Packagecloud. All trademarks and registered marks belong to their
respective owners.

Try Packagecloud