Linux Software Package Management: RPM

1

Overview

In our daily development and operations work, we encounter various software packages; software packages can be broadly divided into two categories: binary files, such as (exe, rpm, bin, etc.); the other category is source files (various tarballs). This article will introduce the most commonly used RPM software package in Linux systems, discussing the definition of RPM packages, the functions of RPM packages, the data format of RPM packages, and how to create a simple RPM package in four aspects.

2

Definition of RPM

A package manager, initially known as the Red Hat Package Manager, is designed for Red Hat systems; currently, RPM is an important component of many Linux distributions, such as Red Hat, Fedora, SUSE, openSUSE, CentOS, etc.

RPM is based on the GPL rules and is free software.

For system administrators, using RPM for software installation and operations has the following advantages: simplicity, uniformity, automation without manual intervention.

The naming convention for RPM packages is:

name-version-release.arch.rpm

e.g.: gnome-desktop-2.28.2-11.el6.x86_64.rpm

3

Functions of RPM Software Packages

☛ Data Compression Storage

It supports common compression algorithms such as bz2 and gzip.

☛ File Installation

Installs files from the package onto the target operating system.

☛ Configuration File Generation

Configuration files can be statically installed to specified directories or dynamically generated based on system-related information.

☛ System Service Registration

When installing some packages, files will be installed in system-specified directories, serving as system service commands. For example, after installing the package vsftpd *.rpm, it will be installed in the /etc/init.d/ directory, allowing the use of system commands to start or stop the service.

☛ Software Dependency Check

The RPM package provides a software dependency check function, laying the foundation for using the yum tool to automatically install packages.

4

Data Format of RPM Packages

The data packet format of RPM packages differs between versions. The RPM data format described below is based on version 3, and each RPM contains four areas, as shown in the image:

Linux Software Package Management: RPM

☛ Lead Section:

The first section of RPM data is the lead section, which contains a structure used to record some simple information, such as file type and version information. However, due to the poor extensibility of the structure, a new structure called “header structure” was later introduced. Its structure is as follows:

Linux Software Package Management: RPM

✔ Header: 16 bytes

[8e ad e8|version 1|reserved 4|number 4|size 4]

3 bytes for magic number, 1 byte for version number, 4 bytes reserved, 4 bytes for the number of indexes, and 4 bytes for the size of the header structure.

✔ Index: 16 bytes

[tag 4|type 4|offset 4|count 4]

4 bytes for the integer variable tag, 4 bytes for the type, 4 bytes for the offset of data storage, and 4 bytes for the number of data elements pointed to by the index.

The index part of the header structure consists of zero or more index entries, each of which is 16 bytes long.

✔ Store: N bytes

The store is where the header structure stores data. Depending on the type value in the index, the following three points must be noted regarding the stored data:

a. STRING type data is null-terminated.

b. INT type data is stored according to its natural boundary.

c. All data is stored in network byte order.

The following signature section and header section are both based on the “header structure” implementation.

☛ Signature Section:

The signature section is implemented based on the “header structure” and stores the verification information of the RPM package, such as sha1 value, md5sum, etc., used to verify the integrity and consistency of the RPM package.

☛ Header Section:

The header section is also implemented based on the “header structure” and stores all relevant descriptive information of the RPM package, such as file name, version number, and file list, but does not contain data.

☛ Archive Section:

The archive section stores the content of all files in the RPM package and is stored using gzip compression.

5

Creating an RPM Package

After understanding the basic knowledge of RPM, how do we create an RPM? Next, we will illustrate the RPM package creation process through a simple example:

First, we need to prepare the “raw materials” as follows:

☛ Source code files and build tools (such as gmake).

For example, a simple test program: test_build_rpm.cpp

Linux Software Package Management: RPM

Makefile:

Linux Software Package Management: RPM

☛ Set up the directory structure according to rpmbuild specifications, with the following directory structure to be set up.

Linux Software Package Management: RPM

Note: This directory should be placed under the $HOME path.

☛ Package the source program, configuration files, documentation, etc. into a tarball and place it in the SOURCES directory.

☛ Create a configuration file ending with .spec; the spec is a text file with special syntax used in generating the RPM package.

Linux Software Package Management: RPM

Configuration item description:

%description: Software description, overview.

%setup: Unpack the source program.

%build: Compile the build program.

%install: Run make install to install to the target path.

%clean: Clean up some temporary files.

%files: Write the files to be installed here.

%changelog: Record the modification history of the software.

Format: * followed by date, modifier, email, version information

– followed by detailed modification instructions.

☛ Place the created configuration file in the SPECS directory.

☛ Run the command

rpmbuild -v -bb –clean SPECS/*.spec, which will generate the required RPM package in the RPMS directory.

Parameter description:

-v displays detailed information about the generation process

–clean deletes the build tree after generating the package

-bb generates only the RPM package; -ba generates both the RPM package and the SRPM package.

Common commands for RPM packages

Installation commands:

rpm –i *.rpm

rpm –ihv *.rpm

rpm –ihv http://xx

Parameter option descriptions:

-v displays the installation information interface

-h displays the installation progress

-i install

Query commands:

rpm –q *rpm (query a specific RPM package)

rpm –qa (query all installed packages)

rpm –qf executable filename (query which software package this executable file belongs to)

Update command:

rpm –vUh *rpm

rpm –vFh *rpm

Option descriptions:

-U if the software package is not installed, it will be installed directly; if it is installed, it will be upgraded to the latest version.

-F this software package can only be updated if it has been installed.

Linux Software Package Management: RPM
Linux Software Package Management: RPM

Leave a Comment