✦ For everyone, free.

Practical knowledge for real and everyday life

Home

RPM Transactions

RPM Transactions manage package installations, upgrades, and removals in Linux, ensuring system stability through atomic, recoverable operations.

RPM Transactions represent the sequence of operations performed by the RPM Package Manager to modify the system's installed packages database and files on disk. Each transaction consists of multiple steps, including package installation, upgrade, removal, or verification, executed in a controlled and atomic manner to ensure system integrity and consistency.


Definition and Purpose of RPM Transactions

An RPM Transaction is a logical unit of work that groups together one or more package management actions such as installing, upgrading, erasing, or verifying RPM packages. The transaction ensures that these actions are executed in the correct order and that the system remains in a consistent state before and after the operations.

Transactions provide atomicity: either all operations within the transaction complete successfully, or none are applied, preventing partial changes that could corrupt the package database or leave the system in an inconsistent state.


Components of an RPM Transaction

Transaction Elements

  • Packages: The RPM packages involved in the transaction. These may be new packages to install, existing packages to upgrade, or packages to remove.
  • Actions: The specific actions to perform on each package, such as install, upgrade, erase, or verify.
  • Dependencies: The transaction resolves package dependencies to ensure that all required packages and compatible versions are included.

Transaction States

An RPM Transaction goes through several internal states:

  • Preparation: The transaction is constructed by resolving dependencies and verifying package integrity.
  • Installation/Execution: Packages are installed, upgraded, or removed as specified.
  • Verification: After the execution phase, the transaction verifies that the changes have been applied correctly.
  • Completion: The transaction either commits the changes or rolls back in case of failure.

Transaction Processing Workflow

1. Transaction Setup

When a user initiates a package management command (e.g., rpm -i, rpm -U, rpm -e), RPM creates a transaction object. It collects the list of packages to process along with the intended actions.

2. Dependency Resolution and Validation

RPM analyzes the requested packages and their dependencies. It ensures all required dependencies are met within the transaction or are already satisfied by the system. It also checks for conflicts, file overlaps, and signature verification.

3. Transaction Execution

Once the transaction is validated, RPM performs the requested operations sequentially:

  • Package Installation: Unpacks package files to the filesystem, runs pre-install scripts, and updates the RPM database.
  • Package Upgrade: Compares version information, removes or replaces older package files, and installs new ones.
  • Package Removal: Runs pre-uninstall scripts, removes files, and deletes package metadata from the database.

During execution, RPM may run associated scriptlets (pre-install, post-install, pre-uninstall, post-uninstall) to complete setup or cleanup tasks.

4. Transaction Commit or Rollback

If all steps succeed, the transaction commits, making the changes permanent. If any error occurs, RPM attempts to roll back all changes made during the transaction to preserve system stability.


Transaction Metadata and Logging

Each transaction is recorded in the RPM database with metadata including:

  • Transaction ID
  • Timestamp
  • Type of operation (install, upgrade, erase)
  • Packages affected
  • Scripts executed
  • Transaction result (success or failure)

This metadata enables auditing, rollback, and history tracking of package management activities.


Atomicity and Consistency Guarantees

RPM Transactions maintain the consistency of the system package database and file system by:

  • Ensuring that either all changes are applied or none at all.
  • Preventing partial package installations or removals.
  • Using temporary files and transaction journals during execution.
  • Verifying package signatures and metadata before execution.

These guarantees reduce the risk of broken dependencies or corrupted packages that could destabilize the system.


Interaction with Other Package Management Tools

While RPM itself manages transactions internally, higher-level tools like yum or dnf use RPM Transactions to perform complex package operations involving multiple packages and repositories. These tools build and optimize transaction sets before passing them to RPM for execution.


Examples of RPM Transaction Usage

# Install a package (creates an install transaction)
rpm -i example-package.rpm

# Upgrade a package (creates an upgrade transaction)
rpm -U example-package.rpm

# Remove a package (creates an erase transaction)
rpm -e example-package

Each command triggers the creation of an RPM Transaction encapsulating the steps necessary to complete the requested operation safely.


Internal Transaction Data Structures

RPM Transactions are managed through internal data structures that track:

  • The list of packages and their states
  • Dependency graphs
  • Scripts and triggers to run
  • File lists and checksums
  • Transaction progress and rollback information

These structures enable RPM to track progress, handle errors, and enforce transactional integrity.


Summary of Transaction Types

Transaction TypeDescription
InstallAdds new packages to the system
UpgradeReplaces older package versions with newer ones
EraseRemoves packages and their associated files
VerifyChecks installed packages for consistency

Each type corresponds to a distinct transaction process with specific steps and validations.


Error Handling and Recovery

When a transaction encounters errors, such as missing dependencies or file conflicts, RPM aborts the transaction and attempts to roll back all changes to the previous stable state. This rollback includes:

  • Removing newly installed files
  • Restoring deleted files if possible
  • Reverting database updates

This mechanism prevents partial failures from leaving the system in an unstable condition.


Conclusion

RPM Transactions are fundamental to the RPM Package Manager's ability to safely and reliably manage package installations, upgrades, removals, and verifications. They provide atomicity, consistency, and error recovery, ensuring the system package database and file system remain coherent throughout package management operations.