Pages

Introduction to Systemd




Systemd is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic.

How to Add / Remove Static route in a RHEL



List all the current static routes

# route -n

Add a route to the network 192.56.76.x via "eth1"

# route add -net 192.56.76.0 netmask 255.255.255.0 dev eth1

Add a route to a host 192.168.76.10 via "eth1"

How to Remove a LUN online


To remove a LUN on-line follow the below steps 

Identify the LUN that need to be removed

# lsscsi -g
[3:0:0:0]    storage HP       HSV300           1000  -         /dev/sg0
[3:0:0:1]    disk    HP       HSV300           1000  /dev/sda  /dev/sg1
[4:0:0:0]    disk    HP       HSV300           1000  /dev/sdb  /dev/sg2

Or use the Command sg_map ( sg_map is part of optional package sg3utils )

How to set LUN queue depths for Induvidal LUN



There may be having  situation like using luns from two different vendors which may recommend a different queue depths ,In such case you can change this value for individual devices dynamically if the device driver supports it.

# cat < new-depth-value > /sys/block/<sdxx>/device/queue_depth

If the device driver doesn't support you will get the below mentioned message

# echo 1024 > /sys/block/sdx/device/queue_depth
bash: /sys/block/sdx/device/queue_depth: Permission denied

kernel: scsi: host X channel Y id Z lun has a LUN larger than allowed by the host adapter



You gets the below error , because the LUN number  <xxx> is greater than lpfc module parameter lpfc_max_luns , because by default emulex controllers support a maximum of 255 LUNs by default. This may be increased to 65535 ,This issue can be also seen if you have a LUN ID that is greater than 255 even though you have a much fewer number of LUNs than 255.


kernel: scsi: host X channel Y id Z lun<xxx> has a LUN larger than allowed by the host adapter

To check the present lpfc_max_luns value

#cat /sys/module/lpfc/parameters/lpfc_max_luns
255

To change the same follow the below steps

1: Add the following to /etc/modprobe.conf file

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