Saturday, August 25, 2012

Finding the device-name associated with a file-system label

We might have came across a situation where a Device associated with a file-system label is missing and due to which we will get an error on boot-up saying file-system can't be found for the Label=[labelname]. To resolve this, we have to find the corresponding Device name associated with the file-system label (set by using the command 'e2label') and fix the problem with it by running 'fsck' or by changing the Label to other alternative disk.
'findfs' is the handy command for it; this is like a reverse case of 'e2label' command.

Below given is a self-explanatory illustration of it:

[root@linuxhost ~]# e2label /dev/sda1
[root@linuxhost ~]# e2label /dev/sda1 Test
[root@linuxhost ~]# e2label /dev/sda1

[root@linuxhost ~]# findfs LABEL="Test"
[root@linuxhost ~]# 

[root@linuxhost ~]# cd /dev/disk/by-label/
[root@linuxhost ~]# ls -l
total 0
lrwxrwxrwx 1 root root 10 Aug 16 08:56 Test -> ../../sda1
[root@linuxhost ~]#

Thursday, August 23, 2012

Total number of 'D' processes

Executing this command-set will display you the total number of uninterruptable sleep (D) processes on the server:

# ps aux | awk '{if ($8 == "D") {print; count++} } END {print "Total No. of uninterruptable Sleep Processes: "count}'

Monday, August 20, 2012

Checking the progress of 'dd' command execution

Start the 'dd' command in back-ground:
[root@hostxyz ~]# dd if=/dev/sda of=/dev/sandisk1 &
[1] <PID>

Execute either of  following while statement against the PID captured in the previous command:
[root@hostxyz ~] # while true; do kill -10 <PID>; sleep 10; clear; done
root@hostxyz ~] # while true; do kill -USR1 <PID>; sleep 10; clear; done


[root@hostxyz ~]# dd if=/dev/zero of=/dev/sdf1 &
[1] 2069
[root@hostxyz ~]# while true; do kill -10 2069; sleep 5; clear; done
14207400+0 records in
14207400+0 records out
7274188800 bytes (7.3 GB) copied, 38.1668 s, 191 MB/s
15276232+0 records in
15276232+0 records out
7821430784 bytes (7.8 GB) copied, 43.1825 s, 181 MB/s
17829523+0 records in
17829523+0 records out
9128715776 bytes (9.1 GB) copied, 48.1945 s, 189 MB/s
18739498+0 records in
18739498+0 records out
<so on>

Sunday, August 19, 2012

Environment variables in Linux

On a Linux system, we can view the Environment variables that are set and exported using 3 built-in commands: 
'set', 'env' & 'export -p'.

Ever wondered how can we see the other 'unset' environment variables belongs to Bash shell or some command or tool ?

The technique that I follow is to look in 2 places: One in the Binaries of the program which the application uses and other in the MAN page.

To view all the printable strings in a Bash shell:  # strings /bin/bash | grep -P '[A-Z]+'
In this output, there will be a lot of additional stuff and you will have to look for environment variables carefully

To print all the ENV variables related to 'history' command:

# man bash | sed 's/[[:cntrl:]].//g' | egrep -x ' +HIST[[:alpha:]]*'

A URL that contains all the Bash variables explaining each:

Saturday, August 18, 2012

Improving Read performance of Disks using 'blockdev'

The Read performance of a Disk can be improved by increasing a parameter called "Read+Ahead" using 'blockdev' command. By default the Linux OS will read 128 KB of data in advance so that it is already in Memory cache before the program needs it. This value can be increased so as to get better Read Performance.

Steps to check and increase the Read-Ahead value:

To check the current 'blockdev' status of all block device:   # blockdev --report
[root@linuxserver ~]# blockdev --report
RO    RA   SSZ   BSZ   StartSec     Size    Device
rw 16384   512  4096          0   14680064  /dev/sda
rw 16384   512  1024         63     208782  /dev/sda1
rw 16384   512   512     208845   10265535  /dev/sda2
rw 16384   512  4096          0 2147483648  /dev/sdb
rw 16384   512  4096          0   35651584  /dev/sdc
rw 16384   512  2048         63   35648172  /dev/sdc1
rw 16384   512  4096          0  104857600  /dev/sdd

To check the 'Read-Ahead' value of an individual disk (let's take sda)
# blockdev --getra /dev/sda
# cat /sys/block/sda/queue/read_ahead_kb

To change the 'Read-Ahead' value to 8 MB (16384 times of 512 bytes blocks).
# blockdev --setra 16384 /dev/sda

To make it permanent upon system reboot, just add this command entry in /etc/rc.local.

Friday, August 17, 2012

Tweaking 'ps' command to display full user-name

By default, the UID column in ‘ps’ output has a character length of 8. If the user name exceeds 8 characters, it will convert the User-name to its corresponding UID and displays it. This might cause inconvenience when we want to check the process list run by a user-account with more than 8 characters. 'ps' command has an option to display full user-name.

Normal 'ps' command:

[longusername@hostxyz ~]$ id longusername
uid=55062(longusername) gid=55062(longusername) groups=55062(longusername)
[longusername@ora-prod-inf-d2 ~]$
ps -ef | grep tail

55062    11708 11470  0 02:11 pts/2    00:00:00 tailf a
55062    11739 11470  0 02:11 pts/2    00:00:00 tailf b
55062    11754 11470  0 02:11 pts/2    00:00:00 tailf c
55062    20637 11470  0 02:33 pts/2    00:00:00 grep tail

A tweaked ‘ps’ output with User column set as 20 characters 

[longusername@hostxyz ~]$ ps -o user:20,pid,ppid,c,stime,tty,cmd | grep tail
longusername         11708 11470  0 02:11 pts/2    tailf a
longusername         11739 11470  0 02:11 pts/2    tailf b
longusername         11754 11470  0 02:11 pts/2    tailf c
longusername         20641 11470  0 02:33 pts/2    grep tail
[longusername@hostxyz ~]$
In this you can see the full user-name getting displayed.