Quick HOWTO: dracut fails in Linux

Issue:  dracut fails when you trying to create initramfs image file.

[root@linux_server1 boot]# dracut -f /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img 2.6.39-400.298.2
E: Failed to install /etc/system-fips

[root@linux_server1 boot]# ls -l /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img

ls: cannot access /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img: No such file or directory

Fix / Solution: Touch /etc/system-fips and try again.

[root@linux_server1 boot]# touch /etc/system-fips
[root@linux_server1 boot]# dracut -f /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img 2.6.39-400.298.2.el6uek.x86_64
[root@linux_server1 boot]# ls -l /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img
-rw------- 1 root root 31035863 May 21 03:06 /boot/initramfs-2.6.39-400.298.2.el6uek.x86_64.img 

Hope this helps..!

Quick HOWTO: Run SSH sessions in Parallel


 You often used "for loop" in shell script to gather an information from large number of your Linux / Unix infrastructure servers. However if your server count is more, it may take lot of time to finish the task. Do you think it will be good if the ssh sessions to remote servers run in parallel? Since the modern day servers having multi-core CPU's we can utilize the real parallel and multi processing of them. 

xargs is your friend here to accomplish your this.

Here is the example to run the SSH sessions in parallel:

xrags -a -n1 -P50 -I{} sh -c "ssh -q {} 'df -Ph /var' "


In this example,

-a --  Takes the input from the file instead of STDIN

-P -- number to processes to execute in parallel. In our example we are starting 50 processes in parallel.

-I -- Used to specify a name to the variable passing to the command we are executing. In our example, we have used {}. For example, You can specify like -I"server" instead of I{}.

Another example:

xrags -a -n1 -P50 -I"server" sh -c "scp server:/tmp/"



One disadvantage in xargs is the output will not be in a order. you need to make your script writes to a log with clear host identification to gather a report from multiple hosts.

Not only SSH and SCP, you can run any process / task which you want to start and run in parallel. Alternatively you can download and use "parallel" tool which is slightly better than xargs.




Quick HOWTO: View contents of RPM without installing it

In Linux, You may wonder what are the files inside a rpm package and you may want to check them before installing it.

You can do this with the below rpm commands:

If the rpm file available locally:
[root@linux_server1 ~]# rpm -qlp telnet-0.17-48.el6.x86_64.rpm
/usr/bin/telnet
/usr/share/man/man1/telnet.1.gz
[root@linux_server1 ~]#

[root@linux_server1 ~]# rpm -q -filesbypkg -p numactl-devel-2.0.9-2.el6.x86_64.rpm
numactl-devel             /usr/include/numa.h
numactl-devel             /usr/include/numacompat1.h
numactl-devel             /usr/include/numaif.h
numactl-devel             /usr/lib64/libnuma.a
numactl-devel             /usr/lib64/libnuma.so
[root@linux_server1 ~]#

If you want to check the contents of a rpm located in a remote repository:
[root@linux_server1 ~]# repoquery --list telnet
/usr/bin/telnet
/usr/share/man/man1/telnet.1.gz
[root@linux_server1 ~]#

If you want to check the pre installation and post installation scripts which runs while you installing a rpm package.
[root@linux_server1 ~]# rpm -qp --scripts sysstat-9.0.4-33.el6.x86_64.rpm
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add sysstat
preuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ]; then
  # Remove sa logs if removing sysstat completely
  rm -f /var/log/sa/*
  # Remove service
  /sbin/chkconfig --del sysstat
fi
[root@linux_server1 ~]#

If the rpm is already installed, you can use same commands without passing the arguement "-p".

Example:
rpm -ql sysstat-9.0.4-33.el6.x86_64
rpm -q --scripts sysstat-9.0.4-33.el6.x86_64


If you want to extract the rpm contents without installing it.
root@linux_server1~]# rpm2cpio telnet-0.17-48.el6.x86_64.rpm | cpio -idmv
./usr/bin/telnet
./usr/share/man/man1/telnet.1.gz
220 blocks

Quick HOWTO: Pacemaker Cluster on Redhat Linux - Enable Web GUI Interface

  
You will notice that your PCS web interface is not working after your pacemaker cluster installation. Because it is not enabled by default. Here is the steps to enable it.

cd /usr/lib/pcsd
vi pcsd.rb
search for "DISABLE_GUI=true"
edit that line to "DISABLE_GUI=false"
service pcsd restart

Now you will be able to access the pacemaker web interface as below:

https://<yourpacemakerclusterserver>:2224

Quick HOWTO: Change I/O Scheduler in Linux



I/O schedulers in Linux


noop - It can be helpful for devices that do I/O scheduling themselves, as intelligent storage, or devices that do not depend on mechanical movement
cfq - A fairness-oriented scheduler. It tries to maintain system-wide fairness of I/O bandwidth
deadline - A latency-oriented I/O scheduler. Each I/O request has got a deadline assigned.
as (anticipatory) - conceptually similar to deadline, but with more heuristics to improve performance (It may decrease performance in some cases)

Here is the procedure to change the default I/O scheduler in Linux.


Dynamically setting the default I/O scheduler to a Particular Disk:

Example: 
echo "scheduler_name" > /sys/block/<Disk_Name>/queue/scheduler

To set I/O scheduler to all the Disk drives on the Linux server:

for disk in `ls -1 /sys/block |egrep '^emc|^sd'`;
do
echo "deadline" > /sys/block/$disk/queue/scheduler;
done

To verify the settings:
for dsk in `ls -1 /sys/block |egrep '^emc|^sd'`;
do
echo -e "$i\t\c";
cat /sys/block/${dsk}/queue/scheduler;
done
Permanently set the default I/O scheduler in Linux via Grub menu:

Implement permanent setting by adding “elevator=noop” to the default stanza in the /boot/grub/menu.lst file

1. Create backup 
cp -p /boot/grub/menu.lst /boot/grub/menu.lst-backup
2. Update menu.lst 

Example:
kernel /vmlinuz-2.6.16.60-0.91.1-smp root=/dev/sysvg/root splash=silent splash=off showopts elevator=noop

Quick HOWTO: Reduce SWAP Partition Online without reboot in Linux

Recently I had a request to reduce the swap space and allocate that space to some other LV in one of our server.  Below is what I followed and it perfectly worked for me.  :)

Make sure you have enough physical memory to hold the swap contents. 

Now, turn the swap off:
# sync
# swapoff <YOUR_SWAP_PARTITION>
Now check the status
# swapon -s 

Then, Use fdisk command:
# fdisk <YOUR_HARDDISK_Where_SWAP_Resides>
List partitions with "p" commandFind Delete your partition with "d" commandCreate a smaller Linux-Swap partition with "n" commandMake sure it is a Linux-Swap partition (type 82) (Change with "t" command)Write partition table with "w" command


Run "partprobe" to update Filesystem table to kernel. (It is very important before proceeding further)

Then,
mkswap <YOUR_NEW_SWAP_PARTITION>
swapon <YOUR_NEW_SWAP_PARTITION> 
check to make sure swap is turned on
swapon -s 
Now you can use your free space to increase space for other Logical volumes (LV). 

Use fdisk command to create new partition, then 

# partprobe
# pvcreate <NEW_PARTITION_YOU_CREATED>
# vgextend <VG_TO_INCREASE> <YOUR_NEW_PV>
# lvextend -L  +SIZE_TO_INCREASE <LV_NAME> 

Note: It is extreme importance of syncing and turning the swap off before you change any partitions. If you FORGET TO DO THIS, YOU WILL LOST_DATA!!