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
-------------------------------------------------------------------------------------------------------------------------------------------------------

How to clear the buffer and pagecache

Run "sync" command first to flush pending data out to disk

# sync

To free pagecache

# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes

# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes

# echo 3 > /proc/sys/vm/drop_caches


How to start autofs in debug mode

To start autofs with the debug option. Configure the parameter as defined below depending on Redhat version to the configuration file /etc/sysconfig/autofs 

Red Hat Enterprise Linux 4

DAEMONOPTIONS="--debug"

Red Hat Enterprise Linux 5

LOGGING="debug"
or
DEFAULT_LOGGING="debug"

Red Hat Enterprise Linux 6

OPTIONS="--debug"

Restart Autofs

# /sbin/service autofs restart

How to increase number of open files limit in Linux

file-max ==> This is the number of concurrently open file descriptors allowed by the kernel. The default is 8192

.............................................
# vi /etc/sysctl.conf
  fs.file-max = XXXXX
.............................................

For applying above changes run

# sysctl -p

You can verify the current value of the max-open-files limit by


# cat /proc/sys/fs/file-max
or
# sysctl -a | grep fs.file-max