Pages

How to take Backup of RPM Database

The RPM database is located in /var/lib/rpm directory. Files in this directory are binary files which hold the installed package information. These files can be backed up safely using tar .Before backing up any file in this directory, confirm that no process is currently using any file within this directory.

# lsof | grep /var/lib/rpm


Remove any stale lock files. Lock files are left behind by processes attempting to access the rpm database. Lock files begin with double underscore character followed by db ( __db )

Explore the " rpm " Command Operations - Part II


How to backup  currently installed rpm package before upgrading 

# rpm -Fvh --repackage httpd-2.0.46-32.ent.3.i386.rpm 

The above command takes a backup of old package and install the new package , The backed up rpm can be found in the location /var/spool/repackage

Explore the " rpm " Command Operations - Part I

How to Install an rpm package 

# rpm -ivh  httpd-2.0.46-32.ent.3.i386.rpm

The above command will upgrade the httpd package

How to Upgrade a package

#rpm -Uvh httpd-2.0.46-32.ent.3.i386.rpm

The above command upgrade the http package

How to Un-install a rpm package

#rpm -e httpd-2.0.46-32.ent.3.i386.rpm

The above command removes the http package


How to remove the rpm from the rpm database

#rpm -e --justdb package-name

The above command will remove the entry of the package from the rpm database without  removing the package or any of the files associated with the package. after executing above command, you won't be able to execute any rpm/yum/zypper commands over the package 


How to Unpack / Install rpm in Custom Location

How to modify and repack an initrd image file

Create a temporary Directory 

#mkdir /root/initrd
#cd /root/initrd

Then uncompress and extract the initrd

#zcat /boot/initrd-2.6.18-164.6.1.el5.img | cpio -idmv

Modify the initrd and repack the intrd as new image

# find . | cpio -o -c | gzip -9 > /boot/test.img


For Redhat-7 use the below mentioned Procedure

Create a temporary Directory 

#mkdir /root/initrd
#cd /root/initrd

Then uncompress and extract the initrd

# xz -dc < initrd.img | cpio --quiet -i --make-directories

Modify the initrd and repack the intrd as new image

find . 2>/dev/null | cpio --quiet -c -o | xz -9 --format=lzma >"new-initrd.img"


How to Find Which Process is using Swap Space

To find which process is Using the swap space use the below Script to find the top 10 Process using Swap

----------------------------------------------------------------------------------------------------------------------------------------------------
ps ax | sed "s/^ *//" > /tmp/ps_ax.output
for x in $(grep Swap /proc/[1-9]*/smaps | grep -v '\W0 kB' | tr -s ' ' | cut -d' ' -f-2 | sort -t' ' -k2 -n | tr -d ' ' | tail -10); do
swapusage=$(echo $x | cut -d: -f3)
pid=$(echo $x | cut -d/ -f3)
procname=$(cat /tmp/ps_ax.output | grep ^$pid)
echo "============================"
echo "Process   : $procname"
echo "Swap usage: $swapusage kB"; done
-------------------------------------------------------------------------------------------------------------------------------------------------------