1 The basics
1.1 rpm is adapted by many Linux distributions other than RedHat
Despite its name, rpm has been used on several Linux distributions, such as Suse, CentOS. Its competitor is Debian's dpkg.
1.2 The rpm command options' order is important
rpm -qi and rpm -iq are totally different. The first option determines the meaning of the options followed.
1.3 From where rpm command get information
rpm gets information from two different sources
- the package files ( -p )
- the rpm database files under /var/lib/rpm/
The former is for uninstalled packages, while the latter is used for installed ones.
1.4 yum vs rpm
yum is an advanced packages management tool running on top of rpm. The main function yum provides is downloading and installing package dependencies automatically. Yum does its job by maintaining center packages repos.
2 rpm command examples
# display an uninstalled rpm package's info
$ rpm -qip emacs-26.1-5.el8.x86_64.rpm
# display an installed rpm package's info
# for installed packages, "install Date" is listed.
$ rpm -qi vim-common
# find which package installed certain file
$ rpm -qf /usr/bin/ls
# find the files installed by a package
$ rpm -ql vim-common
# find when a package was installed
$ rpm -qi | grep '^Install Date'
# find when the OS was installed
$ rpm -qi basesystem | grep '^Install Date'
# list all installed packages
$ rpm -qa
# find the top 10 most recently installed packages
$ rpm -qa --last | head -10
3 rpm database backup/restore
Whenever rpm installs a package, it saves the package's metadata and some other information including installation date into a database file, /var/lib/rpm/Packages. To accelerate the search processing, many auxiliary files are created under the same directory based on /var/lib/rpm/Packages. All files under /var/lib/rpm are the rpm database.
All rpm queries fetch data from this database.
So, /var/lib/rpm/Packages is VERY IMPORTANT! If this file is corrupted/removed, there is no way to rebuild the rpm database and the only solution is to reinstall the OS completely.
So it's recommended to backup /var/lib/rpm/Packages before installing/removing/updating any packages. To make restore easier, we can back up the whole folder /var/lib/rpm.
# backup the rpm database
$ tar -czf rpmdb.bk.tgz /var/lib/rpm
As other files under /var/lib/rpm are created based on /var/lib/rpm/Packages, if they are corrupted/missing, we still can regenerate them as long as /var/lib/rpm/Packages is in place.
# regeberate other database files from /var/lib/rpm/Packages
# rpm --rebuilddb
No comments:
Post a Comment