Linux RPM to the rescue!

RedHat and its variants e.g CentOS, Fedora use RPM packages. Apart from simply installing and upgrading an RPM package, RPM command can be very very handy while troubleshooting.

Below are some interesting scenarios where RPM command does a nifty job.

1. You have an RPM file and you do not know any thing about it other than just the name and version number of it. Want to know more about the package? Try the below command:

# rpm -qip kernel-2.6*.rpm
warning: kernel-2.6.32-220.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID

fd431d51: NOKEY
Name        : kernel                       Relocations: (not relocatable)
Version     : 2.6.32                            Vendor: Red Hat, Inc.
Release     : 220.el6                       Build Date: Wed 09 Nov 2011 07:39:52 PM

IST
Install Date: (not installed)               Build Host: x86-004.build.bos.redhat.com
Group       : System Environment/Kernel     Source RPM: kernel-2.6.32-220.el6.src.rpm
Size        : 117131326                        License: GPLv2
Signature   : RSA/8, Thu 10 Nov 2011 12:33:33 AM IST, Key ID 199e2f91fd431d51
Packager    : Red Hat, Inc.
URL         : http://www.kernel.org/
Summary     : The Linux kernel
Description :
The kernel package contains the Linux kernel (vmlinuz), the core of any
Linux operating system.  The kernel handles the basic functions
of the operating system: memory allocation, process allocation, device
input and output, etc.

2. Some times you really need to know the files that could be overwritten by a package update/upgrade, so that you can take a backup of them before hand. You can list down the files provided by an RPM package and then the similar files which are already in the system from a previous installation can go to your backup. To list down the files provided by an RPM package:

# rpm -qlp kernel-2.6*.rpm

3. Admins are not Einstein. We cannot remember each and everything ( oh come on! Even Einstein used to forget way to hist own house!! ). But, admins belong to that species which can always find a way around. Suppose, one day you are struggling to remember the location of the config file for samba. Google is your friend, but we are too lazy to bring up even a web browser. With the below command, you can see the config files for samba

# rpm -qc samba
/etc/logrotate.d/samba
/etc/pam.d/samba
/etc/samba/smbusers

4. What could be worse than one day your junior admits that he deleted some package related files and he does not remember what exact files he deleted. How will you restore them? It’s easy if you have a good backup, but what if backup team is too busy doing other things and you are left alone? As far as the files are from an RPM, you can always restore them (well almost!)

First, check what files are missing:

rpm -Va       (takes really long time)

Then, once you confirm what exact files are missing, you can find what package provides that

rpm -qf /path/to/the/file

Now, freshen the package

rpm -Fvh package-name.rpm

You should get the fresh files now.

5. As you may know, RPM actually keeps databases of what packages are installed and when etc. Sometimes the rpm db gets corrupted and you get a warning message every time you try to install/upgrade an RPM package. How to solve this? Simple.

# rm -f /vaar/lib/rpm/__db.*
# rpm -vv –rebuilddb

6. There are many reasons you may want to know the packages which were installed on the system recently. RPM provides a way to have that information too along with the time stamp when that package was installed.

# rpm -qa –last | head
samba-3.5.10-114.el6                          Tue 17 Jul 2012 01:02:26 PM IST
mysql-server-5.1.52-1.el6_0.1                 Tue 10 Jul 2012 12:21:58 PM IST
perl-DBD-MySQL-4.013-3.el6                    Tue 10 Jul 2012 12:21:55 PM IST
mysql-5.1.52-1.el6_0.1                        Tue 10 Jul 2012 12:21:54 PM IST
setroubleshoot-server-3.0.38-2.1.el6          Wed 04 Jul 2012 12:55:03 PM IST
setroubleshoot-plugins-3.0.16-1.el6           Wed 04 Jul 2012 12:55:02 PM IST
python-slip-dbus-0.2.11-1.el6                 Wed 04 Jul 2012 12:55:01 PM IST
python-slip-0.2.11-1.el6                      Wed 04 Jul 2012 12:55:01 PM IST
python-decorator-3.0.1-3.1.el6                Wed 04 Jul 2012 12:55:00 PM IST

7. Have you ever wondered what an RPM file is? Well, it’s basically a special archived file. You can extract the contents of the RPM package in the current directory without even installing it.

# rpm2cpio kernel-*.rpm | cpio -idmv

Isn’t RPM amazing?

Advertisements

About admin_xor

Un*x/Linux junkie, loves to program, automate, automate and automate
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s