Quantcast
Channel: GoLinuxHub
Viewing all 392 articles
Browse latest View live

8 examples to help you understand top command usage in Unix/Linux

$
0
0
top is one of my favorite tool for monitoring system usage and also to make any change for improving system
performance.

Let me show you some examples on the usage of top command

Intro:
The  top  program  provides a dynamic real-time view of a running system.  It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.  The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that  configuration can be made persistent across restarts.

1. Without any arguments

[deepak@server1 ~]$ top
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1960 deepak  15   0 30452 3220 1540 R  2.3  0.0   0:00.78 top
 2457 root      11  -5     0    0    0 S  2.3  0.0  11:36.93 kacpid
 2493 pmartprd  16   0 1397m 289m 9.8m S  0.3  0.1  18:36.07 pmrepagent
 4639 pmartprd  15   0  787m  54m 4080 S  0.3  0.0   5:19.55 pmserver
14402 root      RT   0  151m 5256 2872 S  0.3  0.0   1:41.40 multipathd
17886 root      10  -5     0    0    0 S  0.3  0.0   0:07.41 kondemand/11

Generally I use top without any arguments, but the magic is mostly done from the top command line which must of us skip. Well before taking you to that part let me explain you the various system related features which are shown by top command

NOTE: You can enable or disable the marked blue line by pressing "l" once top is running
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached
Explanation: This line tells you about the uptime of your system along with load average value.

NOTE: You can enable/disable the marked blue line by pressing "t"
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached
Explanation:  This line gives us a brief detail of all the tasks running/sleeping/stopped currently in the system along with the CPU Usage

NOTE: You can enable/disable the marked blue line by pressing "m"
top - 17:51:07 up 1 day,  2:56, 27 users,  load average: 5.33, 29.71, 28.33
Tasks: 1470 total,   1 running, 1469 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 253006956k used, 11107468k free,    66964k buffers
Swap: 33554424k total,     3260k used, 33551164k free, 245826024k cached
Explanation:  The next line shows your memory(RAM and swap) usage and capacity.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13916 stmprd    18   0  903m 129m 9936 S 51.4  0.1   3:07.01 java
13921 stmprd    18   0  901m 128m 9936 S 49.8  0.0   3:02.92 java
13825 stmprd    18   0  951m 190m 9932 S 49.5  0.1   3:07.13 java
13856 stmprd    20   0  978m 197m 9936 S 49.2  0.1   3:05.89 java
13853 stmprd    18   0  921m 150m 9932 S 48.5  0.1   3:09.14 java
13875 stmprd    18   0  907m 132m 9940 S 48.5  0.1   3:09.49 java
13937 stmprd    25   0  926m 165m 9936 S 48.2  0.1   3:10.31 java
13919 stmprd    18   0  917m 153m 9936 S 47.5  0.1   3:05.92 java
13879 stmprd    25   0  921m 160m 9936 S 47.2  0.1   3:08.43 java
13908 stmprd    25   0  901m 131m 9932 S 47.2  0.1   3:12.23 java
13905 stmprd    25   0  907m 137m 9932 S 46.6  0.1   2:59.85 java


The left sections shows you the details of the process running along with the below details
Fields/Column
Description
PID
Process Id
USER
The effective user name of the task's owner
PR
The priority of the task
NI
The nice value of the task.  A negative nice value means higher priority, whereas a positive nice value means lower priority.  Zero in this field simply means priority will not be adjusted in determining a task's dispatchability
%CPU
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
%MEM
A task's currently used share of available physical memory
TIME+
Total CPU time the task has used since it started
S
The status of the task which can be one of:
             'D' = uninterruptible sleep
             'R' = running
             'S' = sleeping
             'T' = traced or stopped
             'Z' = zombie
RES
The non-swapped physical memory a task has used
SHR
The amount of shared memory used by a task
Command
Display the command line used to start a task or the name of the associated program

2. Arrange Tasks with High to Low CPU Usage


Press "P" or "shift+p" once top is running to arrange all the tasks with High to Low CPU Usage as shown below
top - 18:03:00 up 1 day,  3:08, 27 users,  load average: 12.54, 32.34, 32.75
Tasks: 1485 total,   3 running, 1482 sleeping,   0 stopped,   0 zombie
Cpu(s): 41.2%us,  0.8%sy,  0.0%ni, 56.6%id,  1.4%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 258863028k used,  5251396k free,    76308k buffers
Swap: 33554424k total,     3256k used, 33551168k free, 250950544k cached

  PID USER      PR  NI  VIRT  RES  SHR S
%CPU %MEM    TIME+  COMMAND
 9663 stmprd    22   0  902m 301m 9888 S 2578.3 0.1   2:27.04 java
32117 etlprd    18  -1 32416 5908 1716 R  6.2 0.0   0:04.84 cleanup_dirfile
10053 root      18  -1 27100 1936 1460 S  4.9 0.0   0:00.15 ps
 5456 pmartprd  16   0 1182m 130m 8560 S  3.9 0.1  38:39.72 pmserver
17492 deepak  16   0 30592 3388 1544 R  3.6 0.0   0:17.11 top
 2843 pmartprd  15   0  730m  48m 4052 S  3.3 0.0   4:40.33 pmserver
 2457 root      11  -5     0    0    0 S  2.9 0.0  11:42.39 kacpid
 3731 tdmsprd   15   0  370m  49m  32m S  2.3 0.0   0:00.64 pmdtm.orig
 

3. Arrange Tasks with High to Low Memory Usage


Press "M" or "shift+m"once top is running to arrange all the tasks with High to Low Memory Usage as shown below
top - 18:04:26 up 1 day,  3:09, 27 users,  load average: 37.12, 34.56, 33.44
Tasks: 1676 total,   1 running, 1675 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.3%us, 76.7%sy,  0.0%ni, 19.7%id,  1.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  264114424k total, 262605184k used,  1509240k free,    77924k buffers
Swap: 33554424k total,     3256k used, 33551168k free, 252198368k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU
%MEM   TIME+  COMMAND
 1852 pmartprd  18   0 2005m 319m 4776 S  6.9  4.1 28:34.32 java
 2493 pmartprd  16   0 1397m 289m 9.8m S  0.0  4.0 18:37.79 pmrepagent
20557 etlprd    15   0  911m 201m 3024 S  0.0  3.0 17:09.02 pmdtm.orig
18778 root      RT   0  286m 188m 156m S  0.0  2.1 13:24.98 aisexec
 5456 pmartprd  15   0 1182m 130m 8560 S  6.2  1.1 38:40.58 pmserver
16004 etlprd    14  -1  179m  83m 2636 S  0.0  0.1  9:41.36 db2bp
11272 stmprd    25   0  906m  67m 9736 S 99.7  0.0  0:48.11 java

4. Change the nice value (priority) of any task

To understand what is nice value follow the below link
Change priority of process using renice

Press "r" when top is running on the terminal. You should get a prompt as shown below in blue color
top - 18:08:38 up 115 days,  8:44,  4 users,  load average: 0.03, 0.03, 0.00
Tasks: 325 total,   2 running, 323 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  6.4%sy,  0.0%ni, 93.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063848k used, 47368880k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297572k cached
PID to renice:1308 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      39  19     0    0    0 R 100.1  0.0   9431:35 kipmi0
 1308 deepak  16   0 29492 2292 1512 S  0.7  0.0   0:00.33 top
 6116 root      15   0  369m  30m  11m S  0.7  0.1  77:24.97 cimserver

Give the PID whose nice value has to be changed and hit "Enter". Then give the nice value for the PID
top - 18:08:38 up 115 days,  8:44,  4 users,  load average: 0.03, 0.03, 0.00
Tasks: 325 total,   2 running, 323 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  6.4%sy,  0.0%ni, 93.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063848k used, 47368880k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297572k cached
Renice PID 1308 to value:-1 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      39  19     0    0    0 R 100.1  0.0   9431:35 kipmi0
 1308 deepak  16   0 29492 2292 1512 S  0.7  0.0   0:00.33 top
 6116 root      15   0  369m  30m  11m S  0.7  0.1  77:24.97 cimserver

Verify the changes
top - 18:09:06 up 115 days,  8:45,  4 users,  load average: 0.13, 0.06, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063276k used, 47369452k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297588k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 
1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.42 top
 5359 root      34  19     0    0    0 S  0.7  0.0   9431:42 kipmi0
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/

5. Kill any task

Press "k" on the terminal when top is running. You should get a prompt as shown below in blue color
top - 18:09:31 up 115 days,  8:45,  4 users,  load average: 0.08, 0.05, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062036k used, 47370692k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297596k cached
PID to kill:1308
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.3  0.0   9431:42 kipmi0
 6460 root      24   0  179m  30m 3976 S  1.0  0.1  79:04.77 java
 1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.49 top
 1434 root      15   0 29492 2288 1516 R  0.7  0.0   0:00.13 top

top - 18:09:31 up 115 days,  8:45,  4 users,  load average: 0.08, 0.05, 0.01
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062036k used, 47370692k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297596k cached
Kill PID 1308 with signal [15]: [Hit Enter for default]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.3  0.0   9431:42 kipmi0
 6460 root      24   0  179m  30m 3976 S  1.0  0.1  79:04.77 java
 1308 deepak  15  -1 29492 2292 1512 S  0.7  0.0   0:00.49 top

6. View all the processes running by a user

Press "u" on the terminal when top is running. You should get a prompt as shown below in blue color
top - 18:12:24 up 115 days,  8:48,  4 users,  load average: 0.06, 0.05, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.4%sy,  0.0%ni, 99.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063268k used, 47369460k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297660k cached
Which user (blank for all):deepak [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1729 root      15   0 29488 2196 1432 R  2.0  0.0   0:00.01 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

top - 18:12:41 up 115 days,  8:48,  4 users,  load average: 0.04, 0.05, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2062356k used, 47370372k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297672k cached

  PID USER     PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1561 deepak  17   0  3984  780  468 S  0.0  0.0   0:00.00 man
 1564 deepak  19   0  8704  964  816 S  0.0  0.0   0:00.00 sh
 1566 deepak  23   0  8704  464  316 S  0.0  0.0   0:00.00 sh
 1571 deepak  16   0  8452  892  712 S  0.0  0.0   0:00.01 less
31328 deepak  15   0  110m 2348 1264 S  0.0  0.0   0:00.20 sshd
31329 deepak  16   0 27676 2564 1816 S  0.0  0.0   0:00.02 bash
31422 deepak  15   0  109m 2360 1260 S  0.0  0.0   0:00.14 sshd
31423 deepak  15   0 27548 2500 1784 S  0.0  0.0   0:00.02 bash

7. Change delay between terminal refresh

By default the top terminal is set for auto refresh after every 3 seconds but if you want you can change it as per your requirement
Press "d" when top is running. You should get a prompt as shown below in blue color
top - 18:14:55 up 115 days,  8:50,  4 users,  load average: 0.01, 0.04, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063828k used, 47368900k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297728k cached
Change delay from 3.0 to:2.0 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  0.7  0.0   9431:58 kipmi0
 1795 root      15   0 29492 2300 1524 R  0.3  0.0   0:00.20 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init

Verify the changes. You must see the screen buffer getting refresh much earlier or just to verify you can provide a higher value of delay and observer the refresh rate on the terminal

8. No. of task to be displayed

By default this option is set to unlimited that is the reason your terminal is fully covered with list of tasks when you run the top command. Any how you can list the no of tasks to be visible once you run top command

Press "n"when top is running. You should get a prompt as shown below in blue color
top - 18:18:07 up 115 days,  8:54,  4 users,  load average: 0.01, 0.03, 0.00
Tasks: 328 total,   1 running, 327 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.7%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2063348k used, 47369380k free,   310072k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1297804k cached
Maximum tasks = 0, change to (0 is unlimited): 2 [Hit Enter]
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  2.3  0.0   9432:08 kipmi0
 1795 root      15   0 29492 2304 1528 R  0.7  0.0   0:00.65 top
    1 root      15   0 10352  692  580 S  0.0  0.0   0:02.16 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:02.37 migration/0

top - 14:48:40 up 116 days,  5:24,  3 users,  load average: 0.05, 0.04, 0.00
Tasks: 318 total,   1 running, 317 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  49432728k total,  2051952k used, 47380776k free,   310176k buffers
Swap:  2097144k total,        0k used,  2097144k free,  1293800k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 5359 root      34  19     0    0    0 S  1.0  0.0   9502:15 kipmi0
25009 prasadee  15   0 29492 2280 1516 R  0.3  0.0   0:01.88 top

I hope the tutorial was useful.

References:
top man page for Linux

Related articles
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
7 Commands to read or view the contents of a file using CLI in Linux


How to configure Private Network in VMware Workstation

$
0
0

Scenario:

We have 3 machines each with different IP range as shown below

Machine 1 (Windows Host) - Connected to Internet
IP Address - 192.168.1.xx
Gateway - 192.168.1.1
Netmask - 255.255.255.0

Machine 2 (Linux 1)
LAN 1 - 172.168.0.0/24
LAN 2 - 10.10.10.0/24
LAN 3 - Connected to Internet - 192.168.1.0/24

Machine 3 (Linux 2)
LAN 1 - 172.168.0.0/24
LAN 2 - 10.10.10.0/24
LAN 3 - Connected to Internet - 192.168.1.0/24


By the end of this article you should be able to do the following

  • Linux 1 and Linux 2 should be inter connected to private network for 172.168.0.0/24 and 10.10.10.0/24
  • Linux 1 and Linux 2 should be connected to Internet
  • 10.10.10.0/24 and 172.168.0.0/24 would be able to transmit/receive packets to each other
I am going to demonstrate you above using VMware Workstation 10.  In my case I have created two virtual machines (Linux) to do the same.

To start with you need to add 3 NIC card to both your vm as shown below.

1. Add Network Adapter

Open the settings windows for the vm. (Make sure the vm is powered off)

Click on Add

Select Network Adapter from all the available option

You can choose any of the Network Connection as it does not matters. You will have to change those in steps ahead. Just make sure you check the box with "Connect at power on"

Click on Finish once done.

Follow the same step to add 1 more NIC to the VM.

2. Create LAN Segments

Once done it is time to create LAN Segments and add it to your virtual machines. 

Select any of the Network Adapter as shown below. You should see a Network Connection Type as "LAN Segments". Once you click on it a different window will pop up

In this window you will have to create 2 LAN Segments namely LAN 1 and LAN 2 as shown below. Click on Add to create the same and once done click on OK to save the changes.

Now you need to select Network Connection Type for all the 3 Network Adapter you created.

3. Assign Network Connection Type

For Network Adapter select LAN 1 as shown below. 

NOTE: Next click on Advanced and view the MAC Address of this NIC and save it in a notepad as you would need it in steps ahead
MAC Address: 00:0C:29:A3:F5:E6

For Network Adapter 2 select LAN 2 as shown below.
MAC Address: 00:0C:29:A3:F5:F0

For Network Adapter 3 select LAN 3 as shown below.
MAC Address: 00:0C:29:A3:F5:FA


Repeat the same above steps for Machine 2 as shown below

For Network Adapter select LAN 1 as shown below. 
MAC Address: 00:0C:29:51:AA:CD

For Network Adapter 2 select LAN 2 as shown below. 
MAC Address: 00:0C:29:51:AA:D7

For Network Adapter 3 select LAN 3 as shown below. 
MAC Address: 00:0C:29:51:AA:E1

So we are set now to move to next step.

4. Assign IP Address

Check the IP of your Windows Machine which is connected to Internet. As you see our IP Address details are
IP Address: 192.168.1.xx
Netmask=255.255.255.0
Gateway = 192.168.1.1

Linux 1
Login to your Linux 1 box and verify if it contains 3 NIC as we had added
[root@test ~]# ifconfig
eth0     Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:E6
          inet6 addr: fe80::20c:29ff:fea3:f5e6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:756 errors:0 dropped:0 overruns:0 frame:0
          TX packets:831 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:71519 (69.8 KiB)  TX bytes:63525 (62.0 KiB)
          Interrupt:19 Base address:0x2024

eth1      Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:F0
          inet6 addr: fe80::20c:29ff:fea3:f5f0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33 errors:0 dropped:0 overruns:0 frame:0
          TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5981 (5.8 KiB)  TX bytes:11003 (10.7 KiB)
          Interrupt:16 Base address:0x20a4

eth2     Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:FA
          inet6 addr: fe80::20c:29ff:fea3:f5fa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:964 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1205 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:80476 (78.5 KiB)  TX bytes:61790 (60.3 KiB)
          Interrupt:17 Base address:0x2424

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:649 errors:0 dropped:0 overruns:0 frame:0
          TX packets:649 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:56376 (55.0 KiB)  TX bytes:56376 (55.0 KiB)
So as you see all the 3 NIC are visible. Now you can match each Network Adapter you added with the MAC Address before you start assigning IP Address to each NIC

For Network Adapter -- LAN 1 (172.168.0.0/24)
MAC Address: 00:0C:29:A3:F5:E6
[root@test ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0C:29:A3:F5:E6
TYPE=Ethernet
BOOTPROTO=none
IPADDR=172.168.0.2
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
USERCTL=no
PEERDNS=yes

[root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth2

For Network Adapter 2 -- LAN 2 (10.10.10.0.0/24)
MAC Address: 00:0C:29:A3:F5:F0
[root@test network-scripts]# vi ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=
00:0C:29:A3:F5:F0
TYPE=Ethernet
BOOTPROTO=none
IPADDR=10.10.10.2
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
USERCTL=no
PEERDNS=yes

For Network Adapter 3 -- LAN 3 (192.168.1.0/24) (Connected to Internet)
MAC Address: 00:0C:29:A3:F5:FA
[root@test network-scripts]# vi ifcfg-eth2
DEVICE="eth2"
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0C:29:A3:F5:FA
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.10
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth2"
USERCTL=no
PEERDNS=yes

[root@test network-scripts]# service network restart
Shutting down interface eth0:                              
[  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down interface eth2:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:                                [  OK  ]
Bringing up interface eth2:                                [  OK  ]


On Linux 2
[root@test1 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:51:AA:CD
          inet6 addr: fe80::20c:29ff:fe51:aacd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:801 errors:0 dropped:0 overruns:0 frame:0
          TX packets:789 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:64811 (63.2 KiB)  TX bytes:72377 (70.6 KiB)
          Interrupt:19 Base address:0x2024

eth2     Link encap:Ethernet  HWaddr 00:0C:29:51:AA:D7
          inet6 addr: fe80::20c:29ff:fe51:aad7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2470 (2.4 KiB)  TX bytes:7223 (7.0 KiB)
          Interrupt:16 Base address:0x20a4

eth3     Link encap:Ethernet  HWaddr 00:0C:29:51:AA:E1
          inet6 addr: fe80::20c:29ff:fe51:aae1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3461 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:244030 (238.3 KiB)  TX bytes:23210 (22.6 KiB)
          Interrupt:17 Base address:0x2424

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:90 errors:0 dropped:0 overruns:0 frame:0
          TX packets:90 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:7200 (7.0 KiB)  TX bytes:7200 (7.0 KiB)

For Network Adapter -- LAN 1 (172.168.0.0/24)
MAC Address: 00:0C:29:51:AA:CD
[root@test1 network-scripts]# vi ifcfg-eth1
DEVICE=eth1
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0c:29:51:aa:cd
TYPE=Ethernet
BOOTPROTO=none
IPADDR=172.168.0.3
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
USERCTL=no
PEERDNS=yes

[root@test1 network-scripts]# cp ifcfg-eth1 ifcfg-eth2
[root@test1 network-scripts]# cp ifcfg-eth1 ifcfg-eth3

For Network Adapter 2 -- LAN 2 (10.10.10.0.0/24)
MAC Address: 00:0C:29:51:AA:D7
[root@test1 network-scripts]# vi ifcfg-eth2
DEVICE=eth2
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0c:29:51:aa:d7
TYPE=Ethernet
BOOTPROTO=none
IPADDR=10.10.10.3
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth2"
USERCTL=no
PEERDNS=yes

For Network Adapter 3 -- LAN 3 (192.168.1.0/24) (Connected to Internet)
MAC Address: 00:0C:29:51:AA:E1
[root@test1 network-scripts]# vi ifcfg-eth3
DEVICE=eth3
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0c:29:51:aa:e1
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.11
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth3"
USERCTL=no
PEERDNS=yes

[root@test1 network-scripts]# service network restart
Shutting down interface eth1:                              
[  OK  ]
Shutting down interface eth2:                              [  OK  ]
Shutting down interface eth3:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth1:                                [  OK  ]
Bringing up interface eth2:                                [  OK  ]
Bringing up interface eth3:                                [  OK  ]


Verify the configuration

From Linux 1
[root@test ~]# ping 172.168.0.3
PING 172.168.0.3 (172.168.0.3) 56(84) bytes of data.
64 bytes from 172.168.0.3: icmp_seq=1 ttl=64 time=0.513 ms
64 bytes from 172.168.0.3: icmp_seq=2 ttl=64 time=0.639 ms
^C
--- 172.168.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1520ms
rtt min/avg/max/mdev = 0.513/0.576/0.639/0.063 ms

[root@test ~]# ping 10.10.10.3
PING 10.10.10.3 (10.10.10.3) 56(84) bytes of data.
64 bytes from 10.10.10.3: icmp_seq=1 ttl=64 time=2.39 ms
64 bytes from 10.10.10.3: icmp_seq=2 ttl=64 time=0.515 ms
^C
--- 10.10.10.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1551ms
rtt min/avg/max/mdev = 0.515/1.453/2.392/0.939 ms

[root@test ~]# ping google.com
PING google.com (74.125.236.167) 56(84) bytes of data.
64 bytes from maa03s16-in-f7.1e100.net (74.125.236.167): icmp_seq=1 ttl=56 time=14.0 ms
64 bytes from maa03s16-in-f7.1e100.net (74.125.236.167): icmp_seq=2 ttl=56 time=10.5 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1049ms
rtt min/avg/max/mdev = 10.584/12.334/14.085/1.754 ms


From Linux 2
[root@test1 ~]# ping 172.168.0.2
PING 172.168.0.2 (172.168.0.2) 56(84) bytes of data.
64 bytes from 172.168.0.2: icmp_seq=1 ttl=64 time=0.261 ms
64 bytes from 172.168.0.2: icmp_seq=2 ttl=64 time=0.460 ms
^C
--- 172.168.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1127ms
rtt min/avg/max/mdev = 0.261/0.360/0.460/0.101 ms

[root@test1 ~]# ping 10.10.10.2
PING 10.10.10.2 (10.10.10.2) 56(84) bytes of data.
64 bytes from 10.10.10.2: icmp_seq=1 ttl=64 time=1.12 ms
64 bytes from 10.10.10.2: icmp_seq=2 ttl=64 time=0.628 ms
^C
--- 10.10.10.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1074ms
rtt min/avg/max/mdev = 0.628/0.875/1.123/0.249 ms

[root@test1 ~]# ping google.com
PING google.com (74.125.236.163) 56(84) bytes of data.
64 bytes from maa03s16-in-f3.1e100.net (74.125.236.163): icmp_seq=1 ttl=56 time=9.69 ms
64 bytes from maa03s16-in-f3.1e100.net (74.125.236.163): icmp_seq=2 ttl=56 time=10.3 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1520ms
rtt min/avg/max/mdev = 9.699/10.006/10.314/0.323 ms


So I think everything is working as expected. Let me know your success and failures

Related Articles
Creating an internal network using VMware Workstation


Follow the below links for more tutorials

8 examples to help you understand top command usage in Unix/Linux
Script to take backup of any critical directory in Unix/Linux
Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
What is virtual memory, paging and swap space?

Iptables rules to block/allow icmp ping request in Linux

$
0
0
In this article I will show you different ways to block or allow incoming and outgoing icmp ping request in your Linux server.

Block ICMP ping request from all the servers in my network 192.168.1.0/24 towards my localhost 192.168.1.6
[root@test1 ~]# iptables -I INPUT -s 192.168.1.0/24 -p icmp -j DROP
Try to ping from any other machine of same network
[root@test ~]# ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
^C
--- 192.168.1.6 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2949ms

In the above test 3 packets were transmitted but none of them were received. As you can see below 3 packets were blocked by the INPUT chain in our localhost
[root@test1 ~]# iptables -L -v
Chain INPUT (policy ACCEPT 28 packets, 2004 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3  252 DROP       icmp --  any    any     192.168.1.0/24       anywhere

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 18 packets, 1688 bytes)
 pkts bytes target     prot opt in     out     source               destination

Block ALL the outgoing ping request

[root@test1 ~]# iptables -I OUTPUT -d 192.168.1.0/24 -p icmp -j DROP
[root@test1 ~]# ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted

^C
--- 192.168.1.2 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2183ms

As you see above 3 packets made an attempt to send an icmp request to 192.168.1.0/24 but as it says "operation not permitted"
[root@test1 ~]# iptables -v -L
Chain INPUT (policy ACCEPT 38 packets, 2548 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 25 packets, 2688 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3  252 DROP       icmp --  any    any     anywhere             192.168.1.0/24

You can also use extra arguments for icmp request types
1. echo-request (ping)
2. echo-reply (pong)

When you are trying to ping a server, basically you are sending a echo-request to that server and that server once receives the request, it will reply with echo-reply.

Block all outgoing echo-reply for echo-request coming from 192.168.1.0/24 using OUTPUT chain
[root@test1 ~]# iptables -I OUTPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-reply -j DROP
Now try to ping from any of the machine of same network
[root@test ~]# ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
^C
--- 192.168.1.6 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2521ms

As you can see 3 packets were blocked in the OUTPUT chain
[root@test1 ~]# iptables -L -v
Chain INPUT (policy ACCEPT 26 packets, 1952 bytes)
 pkts bytes target     prot opt in     out     source    destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source    destination

Chain OUTPUT (policy ACCEPT 16 packets, 1504 bytes)
 pkts bytes target   prot opt in   out  source           destination
    3  252 DROP     icmp --  any  any  192.168.1.0/24   anywhere   icmp echo-reply


Block all ICMP incoming traffic for ESTABLISHED connection only
[root@test1 ~]# iptables -I INPUT -s 192.168.1.0/24 -p icmp -m state --state ESTABLISHED -j DROP
Try to ping from any other machine of same network
[root@test ~]# ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
64 bytes from 192.168.1.6: icmp_seq=1 ttl=64 time=2.00 ms
^C
--- 192.168.1.6 ping statistics ---
4 packets transmitted, 1 received, 75% packet loss, time 3092ms


Do you see something unusual above?
The first packet was sent properly which means node 1 sent with SYN signal which was accepted by node 2 with SYN/ACK signal and sent ACK signal back to node 1 (TCP 3 way handshake). So once the connection was established no further icmp request was allowed as you see out of 4 packets 1 was transmitted successfully and 3 were dropped.

[root@test1 ~]# iptables -L -v
Chain
INPUT (policy ACCEPT 28 packets, 2121 bytes)
 pkts bytes target     prot opt in     out     source               destination
   
3   252 DROP       icmp --  any    any     192.168.1.0/24       anywhere            state ESTABLISHED

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 18 packets, 1620 bytes)
 pkts bytes target     prot opt in     out     source               destination

You can do the same for other state condition as well
# iptables -I INPUT -s 192.168.1.0/24 -p icmp -m state --state NEW,ESTABLISHED,RELATED -j DROP
State
Description
NEW
meaning that the packet has started a new connection, or otherwise  associated with a connection which has not seen packets in both directions
ESTABLISHED
meaning that the packet is associated with a connection which has seen packets in both directions
RELATED
meaning that the packet is starting a new connection, but is  associated  with an existing connection, such as an FTP data transfer, or an ICMP error
So I hope I made my self clear. Please let me know your success and failures

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

Iptables rules to allow/block ssh connection from specific host in Linux

$
0
0
Let me show you some iptable rules which can be used to allow or block ssh connection from a specific host or network


Block 192.168.1.10 from connecting your localhost 192.168.1.6
[root@test1 ~]# iptables -I INPUT -s 192.168.1.10 -p tcp --dport ssh -j REJECT
Let us try to connect 192.168.1.6
[root@test ~]# ssh 192.168.1.6 -v
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.6 [192.168.1.6] port 22.
debug1: connect to address 192.168.1.6 port 22:
Connection refused
ssh: connect to host 192.168.1.6 port 22: Connection refused

So it straight away throws "Connection refused"

Let us check the packet received attempts on 192.168.1.6 made by 192.168.1.10
[root@test1 ~]# iptables -L INPUT -v
Chain INPUT (policy ACCEPT 19 packets, 1263 bytes)
 pkts bytes target     prot opt in     out     source               destination
    1   120 REJECT     tcp  --  any    any     192.168.1.10         anywhere            tcp dpt:ssh reject-with icmp-port-unreachable

So as per the log 1 attempt was made to connect to our machine from 192.168.1.10

Let us try some other ways to block ssh connection from a specific host
[root@test1 ~]# iptables -I INPUT -s 192.168.1.10 -p tcp --dport ssh -j DROP
Let us try to connect our 192.168.1.6 from 192.168.1.10
[root@test ~]# ssh 192.168.1.6 -v
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.6 [192.168.1.6] port 22.
debug1: connect to address 192.168.1.6 port 22:
Connection timed out
ssh: connect to host 192.168.1.6 port 22: Connection timed out

As you see a new message as compare to last rule.

Here we are accepting SYN signal from the remote host but we are not responding to it so there was no successful connection made between both the hosts.

Lets see no. of packets sent in an attempt to connect 192.168.1.6
[root@test1 ~]# iptables -L INPUT -v
Chain INPUT (policy ACCEPT 22 packets, 1552 bytes)
 pkts bytes target     prot opt in     out     source               destination
    3   180 DROP       tcp  --  any    any     192.168.1.10         anywhere            tcp dpt:ssh

3 packets or attempts were made by 192.168.1.10 before throwing "Connection timed out" error

Block ssh connection for ESTABLISHED state from 192.168.1.10
[root@test1 ~]# iptables -I INPUT -s 192.168.1.10 -p tcp --dport ssh -m state --state ESTABLISHED -j REJECT
Let us make an attempt for the same from 192.168.1.10
[root@test ~]# ssh 192.168.1.6 -v
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.6 [192.168.1.6] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1

The attempts gets stucked here after establishing a connection

Allow ssh connection from 192.168.1.10
# iptables -I INPUT -s 192.168.1.10 -p tcp --dport ssh -j ACCEPT
Let us make an attempt for the same from 192.168.1.10
[root@test ~]# ssh 192.168.1.6
root@192.168.1.6's password:
Last login: Thu Mar  6 11:19:32 2014 from 192.168.1.2
[root@test1 ~]#

We have successfully connected

Much more strict rule to block or allow the same (replace ACCEPT with REJECT to block)
[root@test1 ~]# iptables -I INPUT -s 192.168.1.10 -p tcp --dport ssh -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
State
Description
NEW
meaning that the packet has started a new connection, or otherwise  associated with a connection which has not seen packets in both directions
ESTABLISHED
meaning that the packet is associated with a connection which has seen packets in both directions
RELATED
meaning that the packet is starting a new connection, but is  associated  with an existing connection, such as an FTP data transfer, or an ICMP error

Block ssh connection from all the host EXCEPT 192.168.1.2
# iptables -I INPUT ! -s  192.168.1.2 -p tcp --dport ssh -m state --state NEW,ESTABLISHED,RELATED -j REJECT
Let us also log this message to verify our rule
# iptables -I INPUT ! -s  192.168.1.2 -p tcp --dport ssh -m state --state NEW,ESTABLISHED,RELATED -j LOG --log-prefix "BLOCK SSH "
To know more about how to log iptable messages follow the below link
How to log iptables messages in different log file

Make an attempt to do ssh from any other machine in 192.168.1.0/24 network
[root@test ~]# ssh 192.168.1.6
ssh: connect to host 192.168.1.6 port 22: Connection refused

Verify in the logs
# cat /var/log/iptables | grep "BLOCK SSH"
Mar  6 14:03:55 test1 kernel:
BLOCK SSH IN=eth3 OUT= MAC=00:0c:29:51:aa:e1:00:0c:29:a3:f5:fa:08:00 SRC=192.168.1.10 DST=192.168.1.6 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=43914 DF PROTO=TCP SPT=35026 DPT=22 WINDOW=14600 RES=0x00 SYN URGP=0


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

How to configure a caching only bind DNS server in Red Hat Linux

$
0
0
caching-only nameserver won't allow references to internal clients by hostname, but it does allow clients to take advantage of frequently requested domains that are cached.

Pre-requisites
Make sure all the below packages are installed
  • bind (includes DNS server, named)
  • bind-utils (utilities for querying DNS servers about host information)
  • bind-libs (libraries used by the bind server and utils package)
  • bind-chroot (tree of files which can be used as a chroot jail for bind)
# rpm -qa | grep bind
bind-chroot-9.8.2-0.23.rc1.el6_5.1.i686
bind-9.8.2-0.23.rc1.el6_5.1.i686
bind-utils-9.8.2-0.23.rc1.el6_5.1.i686
bind-libs-9.8.2-0.23.rc1.el6_5.1.i686

Now follow the below steps
Add a new entry in named.conf as shown in blue below
# vi /etc/named.conf
options {
        listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost; };
        recursion yes;
       
forwarders { 192.168.1.10; };
        forward only;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
The block above will cause the caching name server to forward DNS requests it can't resolve to your DNS server. Here 192.168.1.10 is my DNS server.

Check the permissions on named.conf
-rw-r-----  1 root named     1056 Mar 13 09:32 named.conf
Verify the named.conf file for any syntax errors
# named-checkconf /etc/named.conf

# echo $?
0
So it seems our named.conf is good to go.

Edit your resolv.conf file and add the below entry
# vi /etc/resolv.conf
nameserver 127.0.0.1

# service named restart
Stopping named: .                                          
[  OK  ]
Starting named:                                            [  OK  ]

Make the service auto start after reboot
# chkconfig named on
Verify your caching-nameserver
# ping google.com
PING google.com (74.125.236.64) 56(84) bytes of data.
64 bytes from maa03s05-in-f0.1e100.net (74.125.236.64): icmp_seq=1 ttl=56 time=85.4 ms
64 bytes from maa03s05-in-f0.1e100.net (74.125.236.64): icmp_seq=2 ttl=56 time=29.2 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1281ms
rtt min/avg/max/mdev = 29.298/57.350/85.402/28.052 ms

# dig golinuxhub.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> golinuxhub.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59633
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;golinuxhub.com.                        IN      A

;; ANSWER SECTION:
golinuxhub.com.         3102    IN      A       50.63.202.15

;; Query time: 26 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Mar 13 09:45:38 2014
;; MSG SIZE  rcvd: 48

Retry to query golinuxhub.com
# dig golinuxhub.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> golinuxhub.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52632
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;golinuxhub.com.                        IN      A

;; ANSWER SECTION:
golinuxhub.com.         3068    IN      A       50.63.202.15

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Mar 13 09:46:12 2014
;; MSG SIZE  rcvd: 48

As you see our query time reduced from 26 msec to 0msec

So everything is working as expected.

Related Articles
What is the difference between DNS A record and CNAME record?
How does a DNS query works when you type a URL on your browser?
DNS server related errors
Configure your BIND DNS server on different port no.
How to configure BIND-9.2 DNS server in Red Hat Linux
How to configure BIND-9.8 DNS server in Red Hat Linux 6


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

Existing lock /var/run/yum.pid: another copy is running

$
0
0
This is a very common error which you might come across in Red Hat Linux distro while trying to run yum command

Error:
# yum install bind
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 3054.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  49 M RSS (343 MB VSZ)
    Started: Fri Mar 14 03:32:19 2014 - 00:10 ago
    State  : Sleeping, pid: 3054

Reason
As you see from the error it says yum command is locked by another application. yum command can be run only one at a time in one machine. In case you try to run it on multiple terminals then you will get the above pop up error unless the lock is released by the application which is using yum.

Solution:
Look out for the process id and the user who is using the yum command
# ps aux | grep yum
root      3054  0.5  4.9 351016 49860 pts/1    S+   03:32   0:00 /usr/bin/python /usr/bin/yum install bind bind-chroot
root      3083  5.4  2.5 341876 25596 ?        S    03:34   0:01 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py refresh-cache yes
root      3087  0.0  0.0 103244   860 pts/2    S+   03:35   0:00 grep yum
So in my case 3054 PID is used by deepak user. You can either notify user deepak and check the time of how long his application will lock yum

or else you can go ahead and kill the PID
# kill -9 3054

Next try to run the command yum from your console. It should run like Milkha Singh (just kidding..).


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

How to configure BIND-9.8 DNS server in Red Hat Linux 6

$
0
0
In my earlier post I had shown you the step by step configuration guide for BIND DNS server but since that time I had used older version of bind rpm so most of the parameters used in that tutorial would not work with bind 9.8 so I thought of posting another article for the same.

I will use chroot i.e.jail environment for configuring dns server as it is considered to be much more safer than normal bind.

NOTE:Please take a copy of the original configuration file before making any changes to it.

Pre-requisites:
Make sure you have all the required packages
# rpm -q bind
package bind is not installed

# rpm -q bind-chroot
package bind-chroot is not installed

Install the required package using yum
# yum -y install bind bind-chroot
By default all the bind files would not be copied inside chroot so we will have to manually do that

Next copy the required files inside chroot directory.
NOTE: Use -p argument along with cp command to preserve the permission and ownership of all the files and directories
# cp -rvpf /etc/named.* /var/named/chroot/etc/
`/etc/named.conf' -> `/var/named/chroot/etc/named.conf'
`/etc/named.iscdlv.key' -> `/var/named/chroot/etc/named.iscdlv.key'
`/etc/named.rfc1912.zones' -> `/var/named/chroot/etc/named.rfc1912.zones'
`/etc/named.root.key' -> `/var/named/chroot/etc/named.root.key'

# cp -rvpf named.* chroot/var/named/
`named.ca' -> `chroot/var/named/named.ca'
`named.empty' -> `chroot/var/named/named.empty'
`named.localhost' -> `chroot/var/named/named.localhost'
`named.loopback' -> `chroot/var/named/named.loopback'

# cp -prvf data/ chroot/var/named/
`data/' -> `chroot/var/named/data'

# cp -prvf dynamic/ chroot/var/named/
`dynamic/' -> `chroot/var/named/dynamic'

# cp -prvf slaves/ chroot/var/named/
`slaves/' -> `chroot/var/named/slaves'

Now lets start editing our main configuration file
# cd /var/named/chroot/etc/

# vi named.conf
options {
        listen-on port 53 { 127.0.0.1;
192.168.1.11; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { localhost; 192.168.1.0/24; };
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

Chane the IP Address of your local machine in the resolv.conf file and ifcfg-eth file
# vi /etc/resolv.conf
search example
nameserver
192.168.1.11

NOTE:DNS entry has to made in ifcfg-eth file only for Red Hat Linux 6 and above. For Red Hat Linux 5 DNS entry is made only in resolv.conf file
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=192.168.1.11

Verify your hostname
# vi /ets/sysconfig/network
HOSTNAME=test2.example.com

Run this command on the terminal
# hostnametest2.example.com
If you use the below command on the terminal your hostname should reflect as STD out
# hostname
test2.example.com

Restart your network services
# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Determining if ip address 192.168.1.11 is already in use for device eth0...
                                                           [  OK  ]

# service named restart
Stopping named:                                            [  OK  ]
Generating /etc/rndc.key:                                 [  OK  ]
Starting named:                                            [  OK  ]

NOTE:In case your system stucks at
Generating /etc/rndc.key:
Try this command
# rndc-confgen -a -r /dev/urandom
wrote key file "/etc/rndc.key"

and again retry to restart your named services

References
Generating rndc key

Verify your Internet Connection

# ping google.com
PING google.com (74.125.236.71) 56(84) bytes of data.
64 bytes from maa03s05-in-f7.1e100.net (74.125.236.71): icmp_seq=1 ttl=56 time=223 ms
64 bytes from maa03s05-in-f7.1e100.net (74.125.236.71): icmp_seq=2 ttl=56 time=319 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1349ms
rtt min/avg/max/mdev = 223.861/271.853/319.846/47.995 ms

So our DNS server is working fine now let us configure forward and reverse zone
# vi /var/named/chroot/etc/named.rfc1912.zones
(Make new entry as shown below)

# Forward Zone Entry #
zone "example.com" IN {
        type master;
        file "example.com.zone";
        allow-update { none; };
};

# Reverse Zone Entry #
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.1.zone";
        allow-update { none; };
};

Create the zone files as mentioned in named.rfc1912.zones file above
# pwd
/var/named/chroot/var/named

# cp -p named.loopback 192.168.1.zone

# cp -p named.localhost example.com.zone

Forward Zone file

# vi example.com.zone
$TTL 1D
@       IN SOA  example.com. hostmaster.example.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                IN NS           example.com.
                IN A            192.168.1.11
test2           IN CNAME        example.com.
www             IN CNAME        example.com.

Reverse Zone file

# vi 192.168.1.zone
$TTL 1D
@       IN SOA  example.com.  hostmaster.example.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN NS   example.com.
11      IN PTR  example.com.

Verify the permissions


IMPORTANT NOTE:
The permission on all the bind related files should be 640 and for all directories it should be 770 with root as user owner and named as group owner
# ll
total 36
-rw-r-----. 1
root  named  207 Mar 14 18:36 192.168.1.zone
drwxrwx---. 2 named named 4096 Jan 20 23:10 data
drwxrwx---. 2 named named 4096 Jan 20 23:10 dynamic
-rw-r-----. 1 root  named  242 Mar 14 18:32 example.com.zone
-rw-r-----. 1 root  named 1892 Feb 18  2008 named.ca
-rw-r-----. 1 root  named  152 Dec 15  2009 named.empty
-rw-r-----. 1 root  named  152 Jun 21  2007 named.localhost
-rw-r-----. 1 root  named  168 Dec 15  2009 named.loopback
drwxrwx---. 2 named named 4096 Jan 20 23:10 slaves

Restart named services
# service named restart
Stopping named: .                                          [  OK  ]
Starting named:                                            [  OK  ]
Verify both the zones
# nslookup example.com
Server:         192.168.1.11
Address:        192.168.1.11#53

Name:  
example.com
Address: 192.168.1.11

# dig -x 192.168.1.11
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -x 192.168.1.11
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60861
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;11.1.168.192.in-addr.arpa.     IN      PTR

;; ANSWER SECTION:
11.1.168.192.in-addr.arpa. 86400 IN     PTR     example.com.

;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400   IN      NS      example.com.

;; ADDITIONAL SECTION:
example.com.            86400   IN      A       192.168.1.11

;; Query time: 2 msec
;; SERVER: 192.168.1.11#53(192.168.1.11)
;; WHEN: Fri Mar 14 18:35:24 2014
;; MSG SIZE  rcvd: 98

So we are getting outputs for forward and reverse lookup entries. Everything is working as expected.

Let me know your success and failures

Related Articles
How to configure a caching only bind DNS server in Red Hat Linux
What is the difference between DNS A record and CNAME record?
How does a DNS query works when you type a URL on your browser?
DNS server related errors
Configure your BIND DNS server on different port no.
How to configure BIND-9.2 DNS server in Red Hat Linux

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
What is virtual memory, paging and swap space?

What is GRUB boot Loader ?

$
0
0
On a Red Hat Linux system, the boot loader's function is to locate the Linux Kernel, and any other necessary files, and load them into memory. It then starts the kernel so that the kernel can run processes.

The boot loader also lets you to control how a system is booted. If you dual boot, a boot loader enables you to choose between operating systems at startup.

When a computer boots, the basic input/output system (BIOS) in read only memory usually loads the boot loader from the Master Boot Record (MBR) on the system's primary hard drive.

However some versions of Linux run directly from the flash memory, by passing the BIOS and the boot loader. Linux was designed to run without an interactive boot loader with the kernel located at particular sectors on the disk.

Using a boot loader offers several benefits including
  • the ability to boot multiple operating systems
  • the ability to pass parameters interactively to the kernel, which is useful for disabling certain features in order to solve hardware problems
  • the ability to load different kernels interactively, which is useful when you deploy a new kernel because it is easy to revert to the working kernel.

GRUB vs LILO

The two boot loaders that Red Hat Linux provides for x86 architecture are the Grand Unified Boot Loader (GRUB) and the Linux Loader (LILO). In the past LILO has been the most popular for Linux and the default loader on most distributions.

However, the GNU project's GRUB is new more commonly used.

GRUB is currently the default Red Hat Linux boot Loader. It is an improvement over LILO in that it enables you to
  • use password protection
  • try different boot parameters during the boot process without permanently hanging the GRUB configuration file.
  • boot Windows NT operating syste,s from the MBR area of the hard drive
GRUB also supports Logical Block Addressing (LBA) mode which enables the computer to find the /boot files more easily, particularly if they are located beyond the 1024th cylinder of the hard drive.

Direct vs Chain-loading Method

The boot method for Red Hat Linux is called the direct loading method, because the boot loader loads the operating system directly without using an intermediary stage between the boot loader and the kernel.

In the chain loading boot method, the MBR points to the first sector of the partition that contains the operating system. The MBR uses the files in this location to boot the operating system.

GRUB supports both direct and chain loading boot methods, so it can boot almost any operating system.
'

Related Articles
What is kernel-PAE in Linux?
What is a Kernel in Linux?
What is swappiness and how do we change its value?
What is virtual memory, paging and swap space?
What is the difference between POP3 and IMAP?

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?


How to generate ER diagram using Oracle SQL developer

$
0
0
Tool Used : SQL Developer version 3.1.07
Schema Used : HR
Tables Used : Countries, Departments, Employees, Job_History, Jobs, Locations, Regions

Navigate the below path and step by step screen shots:

File > Data Modeler > Import > Data Dictionary

1# Select DB Connection and click on next

2# Select Schema/DB you wish to import and select Import to New Relational Model and click on next  


3# select the objects you wish to import and click on next and finish


4# E-R relationship diagram is created between list of tables


5# You can save and print ER relationship by following below path

File > Data Modeler > Print Diagram or Print

I hope I made my self clear. Please let me know your success and failures.

How to extend/resize Logical Volume and Volume Group in Linux

$
0
0
As of now you can see my root partition is on LVM with 5.8Gb size. I want to extend my root filesystem with +1GB. Now here there can be two scenarios where
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
                     
5.8G 4.1G  1.4G  76% /
tmpfs                 504M  260K  504M   1% /dev/shm
/dev/sda1             194M   26M  158M  15% /boot

1. You want to extend size using extra partition
2. You want to extend size with space in existing Volume Group

I will show you steps required to perform the same using both the scenarios

Scenario 1

Extend LVM using additional partition

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cf049

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1306    10279936   8e  Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-root: 6278 MB, 6278873088 bytes
255 heads, 63 sectors/track, 763 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
So as you see I have added extra partition hard disk /dev/sdb with 2GB space. Let us use it to extend our root file system.

Steps required to perform the same
1. Create partition for /dev/sdb with 1 GB storage
2. Create Physical Volume
3. Extend existing Volume Group
4. Extend LVM
5. Verify the changes

Create partition with /dev/sdb

# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x55693454.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): +1G

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x55693454

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM      df  BootIt
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x55693454

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  8e Linux LVM


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
# partprobe /dev/sdb1Now at this stage our partition is created as /dev/sdb1 with LVM type.

Create Physical Volume

# pvcreate /dev/sdb1
 
Physical volume "/dev/sdb1" successfully created


Extend Volume Group

Before extending the size of our existing Volume group let us verify the size of the same
# vgdisplay
  --- Volume group ---
  VG Name              
VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.80 GiB
  PE Size               4.00 MiB
  Total PE              2509
  Alloc PE / Size       2009 / 7.85 GiB
  Free  PE / Size       500 / 1.95 GiB
  VG UUID               uH5AP5-b24E-92h7-nL8b-7Bio-fXe3-pstWIW

So our Volume Group contains 9.80 GB

Next extend the Volume Group using the below command
# vgextend VolGroup /dev/sdb1
 
Volume group "VolGroup" successfully extended

Verify the change
# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size              
10.81 GiB
  PE Size               4.00 MiB
  Total PE              2767
  Alloc PE / Size       2009 / 7.85 GiB
  Free  PE / Size       758 / 2.96 GiB
  VG UUID               uH5AP5-b24E-92h7-nL8b-7Bio-fXe3-pstWIW

As you can verify the change i.e. extra 1 GB has been added to our Volume Group which we can use to extend out root filesystem

Extend LVM

Before extending the root fs let us verify the existing size
# lvdisplay /dev/VolGroup/root
  --- Logical volume ---
  LV Path                /dev/VolGroup/root
  LV Name                root
  VG Name                VolGroup
  LV UUID                Qn8TnI-TLNm-rl4Y-ORnd-zU3p-2Kj1-ALSLAg
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
 
LV Size                5.85 GiB
  Current LE             1497
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

So our existing LVM size for root is 5.85GB

Let us extend the size with +1GB
# lvextend -L +1G /dev/VolGroup/root
  Extending logical volume root to 6.85 GiB
  Logical volume root successfully resized

Verify the changes
# lvdisplay /dev/VolGroup/root
  --- Logical volume ---
  LV Path                /dev/VolGroup/root
  LV Name                root
  VG Name                VolGroup
  LV UUID                Qn8TnI-TLNm-rl4Y-ORnd-zU3p-2Kj1-ALSLAg
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                6.85 GiB
  Current LE             1753
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Let us see if the changes are reflected using df
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
                     
5.8G 4.1G  1.4G  76% /
tmpfs                 504M  260K  504M   1% /dev/shm
/dev/sda1             194M   26M  158M  15% /boot

But it still shows old size for root. The reason is because we need to update the partition table with the new value of LVM which can be done using the below command
# resize2fs /dev/VolGroup/root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/VolGroup/root to 1795072 (4k) blocks.
The filesystem on /dev/VolGroup/root is now 1795072 blocks long.

In case you notice above initially the command throws out an error as we were attempting to resize on a mounted partition but since our file system is ext4, we get an additional feature of online resizing where we do not need to unmount the file system for extending its size

NOTE: We can resize the file system online if following conditions are met

  • 2.6.x kernel sereis
  • Must be formatted with ext3 fs or above

Re-verify the change now

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-root
                      6.8G 4.2G  2.3G  65% /
tmpfs                 504M  260K  504M   1% /dev/shm
/dev/sda1             194M   26M  158M  15% /boot

So everything worked as expected.

Scenario 2

In case you already have enough space in your volume group for extending the root file system then you don't need to create a new physical volume.

You can just follow the steps of extending LVM as shown above

Related Articles
How to remove logical and physical volume from Volume Group in Linux

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

How to install libraries manually in Linux

$
0
0
Shared libraries relies heavily on concept of libraries. These are the collection of software that are re used by other programs. This avoids having to rewrite the code for functions that are used repeatedly.

Software libraries can be linked in two ways

Statically

These are compiled together with a program to produce a single piece of executable code. this can have advantage of producing executable code that runs quickly. However this disadvantage is that the resulting code tends to be long and so uses large amount of system resources.

Dynamically

These are also shared libraries and are loaded into memory as they are needed. This means that the code compiled with dynamically linked libraries has a smaller memory footprint then if it were linked statically.

Shared libraries are frequently updated. Installing new libraries means that you need to maintain the software that depends on these libraries. We do this in order to avoid or resolve dependencies and conflicts.

To list the shared libraries
# ldd /bin/ls
        linux-vdso.so.1 =>  (0x00007fffa9bff000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003f64600000)
        librt.so.1 => /lib64/librt.so.1 (0x0000003f63600000)
        libcap.so.2 => /lib64/libcap.so.2 (0x0000003f66e00000)
        libacl.so.1 => /lib64/libacl.so.1 (0x0000003f6da00000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003f62e00000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003f62a00000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003f62600000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003f63200000)
        libattr.so.1 => /lib64/libattr.so.1 (0x0000003f73200000)


Install a library manually

To install a library file you need to copy the file inside /usr/lib and then run ldconfig (as root). It will install any new library in that directory
# ldconfig -n -v /usr/lib
ldconfig  creates  the  necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).  The cache is used by the run-time linker, ld.so  or  ld-linux.so.ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.

ldconfig  will attempt to deduce the type of ELF libs (i.e., libc5 or libc6/glibc) based on what C libs, if any, the library was linked against.

NOTE: if you install library in a non standard directory you need to add this path LD_LIBRARY_PATH for Red Hat Linux and SHLIB_PATH for HP-UX

You can add the path using the below command (path has to be added instead of /usr/lib followed by a colon ":")

For Red Hat Linux
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib
For HP-UX (Unix)
# export SHLIB_PATH=$SHLIB_PATH:/usr/lib:/usr/local/lib
For making these changes permanent add these path in .bash_profile. For more details follow the below link
How to set environment (PATH) variable permanently in Linux

References

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

How to change default login shell permanently in linux

$
0
0
In Red hat Linux the default shell you login to is /bin/bash but in case you want to change the default login shell follow the below procedure

To check the currently logged in shell
# echo $SHELL
/bin/bash

To view all the available shells in your machine
# chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

You can also view the available shell details from the below file
# less /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

To change the shell temporarily

To do this just provide the full path of the shell you want to use. But this is just a temporary change as next time you switch terminal you will login to the default shell
[root@test2 ~]# /bin/sh
sh-4.1#
As you see above my shell prompt changed from /bin/bash to /bin/sh

To change the shell prompt permanently

# chsh -s /bin/sh
Changing shell for root.
Shell changed.

[root@test2 ~]#
But as you notice even though our shell was changed successfully but still we see bash shell prompt.

NOTE: To make the changes affect you need to log out and log back in
Using username "root".
root@192.168.1.11's password:
Last login: Fri Mar 21 10:15:03 2014 from 192.168.1.2
-sh-4.1# echo $SHELL
/bin/sh
-sh-4.1#

So now as I try to login I see my default login shell is changed to /bin/sh

Which file is responsible for assigning shell by default?

What if you want next time you create a user, he/she should get different shell and every time you don't change their shell manually

Check the below file
# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

As you see the SHELL argument has /bin/bash as default. Just change this value to any shell you want to provide for a new user.

Related Articles
How to change user Password Expiry, Home Directory etc in Linux
How to create user without useradd command in Linux
How to give normal user root privileges using sudo in Linux/Unix


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

What is the difference between ext3 and ext4 filesystem in Linux ?

$
0
0
Ext3 was considered to be one of the most popular filsystems and is used in many commercial distributions but still with the increasing demands of the IT industry we started to find a lot of features which was lacking in ext3 which led to the development of ext4 filesystem. In this article I will try to be very thorough mentioning the details of the features where ext3 lacked and ext4 helped overcoming to it.

NOTE: Ext4 is available from machines having kernel version 2.6.19

Extent Support

Ext3 filesystem was designed to use indirect block mapping scheme, which is efficient for small files but causes high metadata over head and poor performance when dealing with large files especially while performing delete or truncate operations  because the mapping keeps a entry for every single block, and big files have many blocks which will led to huge mappings that will be slow to handle.

A new feature called extent has been added to ext4 filesystem. An extent is a single descriptor that represents a range of contiguous blocks. A single extent in ext4 can represent up to 128 MB

Calculations:

Ext3:
Using indirect block mapping schecme, 1 block = 4KB
So for 100MB file 100*1024/4 = 25600 blocks

Ext4:
1 extent can represent upto 128MB so a single extent can be used for mapping

Extents bring about a 25% throughput gain in large sequential I/O workloads when compared with ext3 hence increasing the overall performance of the filesystem.


Large FileSystem Support

One of the most important limitation of ext3 was 16TB filesystem size since it was using 32-bit block numbers and has a default 4k block size. This was overcome by ext4 filesystem theoritically supporting maximum filesystem size of 1EB (1 million TB i.e 1 EB = 1024 PB, 1 PB = 1024 TB, 1 TB = 1024 GB). This change was made possible with the combination of extent patches which uses 48-bit physical block numbers. Other metadata changes, such as in the super-block structure, were also made to support the 48-bit block number.

Journaling

A journaling filesystem is a filesystem that maintains a special file called a journal that is used to repair any inconsistencies that occur as the result of an improper shutdown of a computer.

In order to support more than 32-bit block numbers in the journaling block layer (JBD), JBD2 was forked from JBD at the same time that ext4 was cloned.

In Ext4 you get an additional advantage of disabling journaling feature which can help slightly improve the performance of machine for users with special requirements and lesser workloads.


Multiple Block Allocation

Block allocator is the one that decides which free blocks will be used to write the data. Ext3 allocator allocates one block at a time for any data in the filesystem so you can imagine the amount of CPU and time occupied while writing a data for 100MB as shown in above calculation.

Ext4 uses Multiblock Allocator which allows many blocks to be allocated to a file in a single operation, in order to dramatically reduce the amount of CPU usage searching for many free blocks in the filesystem. Also, because many file blocks are allocated at the same time, a much better decision can be made to find a chunk of free space where all of the blocks will fit.

Delayed Allocation

This is a feature  where writing new data on the filesystem is delayed as much as possible as compared to ext3 filesystems which immediately starts looking for free block and aloocates as soon as possible.

Combined with Multiblock Allocation a large no of block can be allocated at the same time by knowing the size of block required, a suitable chunk of free space can be looked for and allocated to it instead of picking up a single free block everytime.
This will reduce CPU time spent in block allocation increasing the performance.

Online Defragmentation

Ext4 will support online fragmentation which is performed by creating a temporary inode, using multiple block allocation to allocate contiguous blocks to the inode, reading all data from the original file to the page cache, then flushing the data to disk and migrating the newly allocated blocks over to the original inode.

Why we need defragmentation?
There happens a case when you have multiple files in your filesystem. Now these data are stored as small blocks. For example you have a single data file with 1GB so the kernel will place all the blocks for this single file at one place but eventually as the filesystem size goes full the blocks near that 1GB file will also be occupied. But what if you add more contents to the 1GB data file and its size is increased to 3GB. In that case kernel won't find any free blocks near that data file and will assign random free blocks on the filesystem which slows down the I/O performance. So we perform defragmentation to arange all the blocks for each data available on the filesystem.

Inode related tweeks

In ext3 the default inode size is 128 bytes but in ext4 the default inode size can be 256, 512, 1024, etc. up to filesystem blocksize. This will provide space for the new fields needed for the planned features, nanosecond time stamps, and inode versioning.

Indexing Feature

To increase directory scalability the directory indexing feature, available in ext3, will be turned on by default in ext4. Directory indexing uses a specialized Btree-like structure to store directory entries, rather than a linked list with linear access times. This significantly improves performance on
certain applications with very large directories.

Faster Repair and Recovery

In ext4 unallocated block groups and sections of the inode table are marked as such. This enables e2fsck to skip them entirely and greatly reduces the time it takes to check the file system. Linux 2.6.24 implements this feature.

Unlimited subdirectory limit

Utilising the B-Tree indexing feature the ext4 filesystem has overcome the maximum limit of subdirectories which was 32,768 in ext3. Unlimited directories can be created in ext4 filesystem.

A brief comparison chart between ext3 and ext4
Features
Ext3
Ext4
Filesystem limit
16TB
1EB (1 EB = 1024 PB, 1 PB = 1024 TB)
File limit
2TB
16TB
Default inode size
128 bytes
256 bytes
Block Mapping
Indirect
Extent
Time Stamp
Second
Nanosecond
Sub Directory Limit
32,768
Unlimited
Preallocation
In-core reservation
For extent file
Defragmentation
No
Yes
Directory Indexing
Disabled
Enabled
Delayed Allocation
No
Yes
Multiple Block Allocation
Basic
Advanced


References
Ext4: The Next Generation of Ext2/3 Filesystem
ext4: the next generation of the ext3 file system
Ext4


Related Articles
What is GRUB Boot Loader ?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
What is a Kernel in Linux?
What is virtual memory, paging and swap space?


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux

How to remove logical and physical volume from Volume Group in Linux

$
0
0

Remove Logical Volume from Volume Group


NOTE: Make sure the logical volume to be removed is unmounted.

Syntax:
# lvremove /path/to/lvm
Once the logical volume is unmounted run the below command from the terminal
# lvremove /dev/NewGroup/office
Do you really want to remove active logical volume office? [y/n]: y
  Logical volume "office" successfully removed

Verify the changes (As you see "office" logical volume is successfully deleted)
[root@test2 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/NewGroup/root
  LV Name                root
  VG Name                NewGroup
  LV UUID                52mm9d-feyC-AWVH-NTMC-VwNa-Ns1p-cJc8vJ
  LV Write Access        read/write
  LV Creation host, time test2.example, 2014-03-14 02:37:58 +0530
  LV Status              available
  # open                 1
  LV Size                9.92 GiB
  Current LE             2539
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/NewGroup/swap
  LV Name                swap
  VG Name                NewGroup
  LV UUID                48hszS-I0uT-Zsxr-jnoY-yEbj-hfBJ-isofU7
  LV Write Access        read/write
  LV Creation host, time test2.example, 2014-03-14 02:38:00 +0530
  LV Status              available
  # open                 1
  LV Size                1.95 GiB
  Current LE             500
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

Remove Physical Volume from Volume Group


Verify the physical volume to be removed
# vgdisplay -v
    Finding all volume groups
    Finding volume group "VolGroup"
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  25
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               10.81 GiB
  PE Size               4.00 MiB
  Total PE              2767
  Alloc PE / Size       2265 / 8.85 GiB
  Free  PE / Size       502 / 1.96 GiB
  VG UUID               uH5AP5-b24E-92h7-nL8b-7Bio-fXe3-pstWIW

  --- Logical volume ---
  LV Path                /dev/VolGroup/root
  LV Name                root
  VG Name                VolGroup
  LV UUID                Qn8TnI-TLNm-rl4Y-ORnd-zU3p-2Kj1-ALSLAg
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                6.85 GiB
  Current LE             1753
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/swap
  LV Name                swap
  VG Name                VolGroup
  LV UUID                M1ucwx-2sjb-o9Q4-a2td-aPvi-FO1C-ggHuPn
  LV Write Access        read/write
  LV Creation host, time ,
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Physical volumes ---
  PV Name               /dev/sda2
  PV UUID               uYfzd6-4jh1-YTP7-I3hx-WdSJ-4mTR-HZcdtq
  PV Status             allocatable
  Total PE / Free PE    2509 / 244

  PV Name               /dev/sdb1
  PV UUID               Am341r-9WLV-NgWo-Un0Y-sVLQ-fyXM-0zyDix
  PV Status             allocatable
  Total PE / Free PE    258 / 258
As you can see my VolGroup contains /dev/sda2 and /dev/sdb1 partition. Let us try to remove /dev/sdb1

To remove a Physical Volume first we need to remove it from the Volume group using below syntax

Syntax:
# vgreduce name_of_vol_grp path/of/pv
# vgreduce VolGroup /dev/sdb1
 
Removed "/dev/sdb1" from volume group "VolGroup"

Once reduce from volgroup we can easily remove the PV using below command
# pvremove /dev/sdb1
 
Labels on physical volume "/dev/sdb1" successfully wiped

I hope I made my self clear. Please let me know your success and failures.


Related Articles
How to extend/resize LVM and Volume Group in Red Hat Linux 6

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?


Step by Step Linux Boot Process Explained In Detail

$
0
0
You can find a number of articles explaining you the Linux Boot Process. Well I am not going to tell any thing different but I would like to show my point of perspective on some extra details of the Linux Booting procedure.

The stages involved in Linux Booting Process are:
BIOS
Boot Loader

    - MBR
    - GRUB

Kernel
Init
Runlevel scripts


BIOS

  • This is the first thing which loads once you power on your machine.
  • It determines the bootable devices available in the system.
  • Prompts to select bootable device which can be Hard Disk, CD/DVD-ROM, Floppy Drive, USB Flash Memory Stick etc (optional)
  • Operating System tries to boot from Hard Disk where the MBR contains primary boot loader.

Boot Loader 

To be very brief this phase includes loading of the boot loader (MBR and GRUB/LILO) into memory to bring up the kernel.

MBR (Master Boot Record)
  • It is the first sector of the Hard Disk with a size of 512 bytes.
  • The first 434 - 446 bytes are the primary boot loader, 64 bytes for partition table and 6 bytes for MBR validation timestamp.
NOTE: Now MBR directly cannot load the kernel as it is unaware of the filesystem concept and requires a boot loader with file system driver for each supported file systems, so that they can be understood and accessed by the boot loader itself.

To overcome this situation GRUB is used with the details of the filesystem in /boot/grub.conf and file system drivers

GRUB (GRand Unified Boot loader)

This loads the kernel in 3 stages

GRUB stage 1: 
  • The primary boot loader takes up less than 512 bytes of disk space in the MBR - too small a space to contain the instructions necessary to load a complex operating system. 
  • Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.
GRUB Stage 1.5: 
  • Stage 1 can load the stage 2 directly, but it is normally set up to load the stage 1.5. 
  • This can happen when the /boot partition is situated beyond the 1024 cylinder head of the hard drive. 
  • GRUB Stage 1.5 is located in the first 30 KB of Hard disk immediately after MBR and before the first partition.
  • This space is utilised to store file system drivers and modules.
  • This enabled stage 1.5 to load stage 2 to load from any known loaction on the file system i.e. /boot/grub

GRUB Stage 2:
  • This is responsible for loading kernel from /boot/grub/grub.conf and any other modules needed
  • Loads a GUI interface i.e. splash image located at /grub/splash.xpm.gz with list of available kernels where you can manually select the kernel or else after the default timeout value the selected kernel will boot
A symlink can be observed for /boot/grub/grub.conf at /etc/grub.conf
Sample /boot/grub/grub.conf
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-194.26.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.26.1.el5.img

title Red Hat Enterprise Linux Server (2.6.18-194.11.4.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.11.4.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.11.4.el5.img
title Red Hat Enterprise Linux Server (2.6.18-194.11.3.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.11.3.el5 ro root=/dev/VolGroup00/root clocksource=acpi_pm divisor=10
        initrd /initrd-2.6.18-194.11.3.el5.img


For more information on GRUB and LILO follow the below link
What is GRUB Boot Loader ?

Kernel

This can be considered the heart of operating system responsible for handling all system processes.

Kernel is loaded in the following stages:
  1. Kernel as soon as it is loaded configures hardware and memory allocated to the system.
  2. Next it uncompresses the initrd image (compressed using zlib into  zImage or bzImage formats) and mounts it and loads all the necessary drivers.
  3. Looks out for hard disk types be it a LVM or RAID.
  4. Unmounts initrd image and frees up all the memory occupied by the disk image.
  5. Then kernel mounts the root partition as specified in grub.conf as read-only.
  6. Next it runs the init process
For more information on kernel follow the below link
What is a Kernel in Linux?

Init Process

  • Executes the system to boot into the run level as specified in /etc/inittab
Sample output defining the default boot runlevel inside /etc/inittab
# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

As per above O/P system will boot into runlevel 5

You can check current runlevel details of your system using below command on the terminal
# who -r
         
run-level 3  Jan 28 23:29                  last=S

  • Next as per the fstab entry file system's integrity is checked and root partition is re-mounted as read-write (earlier it was mounted as read-only).

Runlevel scripts

A no. of runlevel scripts are defined inside /etc/rc.d/rcx.d
Runlevel Directory
0/etc/rc.d/rc0.d
1/etc/rc.d/rc1.d
2/etc/rc.d/rc2.d
3/etc/rc.d/rc3.d
4/etc/rc.d/rc4.d
5/etc/rc.d/rc5.d
6/etc/rc.d/rc6.d

  • Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the /etc/rc.d directory.
  • Scripts used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through /etc/rc.d/rc6.d, respectively.
  • For more details on scripts inside /etc/rc.d follow the below link
    What are the s and k scripts in the etc rcx.d directories

Next if everything goes fine you should be able to see the Login Screen on your system.


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?
8 examples to help you understand top command usage in Unix/Linux
Script to take backup of any critical directory in Unix/Linux
What is the difference between ext3 and ext4 filesystem in Linux ?


How to rename Logical Volume and Volume Group in Linux

$
0
0

Rename a Logical Volume


NOTE: To rename a Logical Volume you will have to unmount your partition.

Syntax
# lvrename Volu_Group_Name  Old_log_vol_namenew_log_vol_name
# lvrename VolGroup work office
 
Renamed "work" to "office" in volume group "VolGroup"

So now our Logical Volume is renamed.

In case your logical volume was mounted, you will have to remount to make the changes affect.
[root@test2 ~]# mount /dev/VolGroup/office /work/

Verify the changes
[root@test2 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-root     11G  3.3G  7.0G  33% /
tmpfs                        495M   72K  495M   1% /dev/shm
/dev/sda1                    194M   30M  155M  16% /boot
/dev/mapper/VolGroup-office 1008M   34M  924M   4% /work

Rename Volume Group

The existing name for my Volume Group is VolGroup as you see in blue color. Let us try to rename it.
# vgdisplay
  --- Volume group ---
 
VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               14.80 GiB
  PE Size               4.00 MiB
  Total PE              3789
  Alloc PE / Size       3295 / 12.87 GiB
  Free  PE / Size       494 / 1.93 GiB
  VG UUID               iebYT7-Bukv-7FdP-AEMJ-noFk-INmV-7wX2PI

Syntax
# vgrename old_vol_group_namenew_vol_group_name
# vgrename VolGroup NewGroup
 
Volume group "VolGroup" successfully renamed to "NewGroup"

Verify the changes
[root@test2 ~]# vgdisplay
  --- Volume group ---
 
VG Name               NewGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               14.80 GiB
  PE Size               4.00 MiB
  Total PE              3789
  Alloc PE / Size       3295 / 12.87 GiB
  Free  PE / Size       494 / 1.93 GiB
  VG UUID               iebYT7-Bukv-7FdP-AEMJ-noFk-INmV-7wX2PI
So everything worked as expected. Please let me know your success and failures.

Related Articles
How to extend/resize Logical Volume and Volume Group in Linux
How to remove logical and physical volume from Volume Group in Linux


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
Step by Step Linux Boot Process Explained In Detail
What is the difference between ext3 and ext4 filesystem in Linux ?
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

VMware Workstation throws internal error when powering on VM

$
0
0
I was surprised to get this error every time I made an attempt to power on a vm in my VMware Workstation 10. Well it is not much of a big issue, so just thought to post a solution for it.

Error:


Reason:
This happens because the VMware Workstation services has not been started.

Solution:
Start the required services for VMware Workstation using the steps below

Open the run prompt and run the services.msc as shown below

The Services window will come on screen. Look out for VMware Workstation Server from the list of services

Click on Start the service

Verify if the service is started

Also make sure the service starts automatically from next time to avoid these steps in future. Right click the service and open the properties dialog box

Select Automatic from the drop down option and also verify the service is started as shown below and click on OK to apply the setting

I hope I made my self clear.

Related Articles
Creating an internal network using VMware Workstation
How to configure Private Network in VMware Workstation


Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?
8 examples to help you understand top command usage in Unix/Linux
Step by Step Linux Boot Process Explained In Detail
What is the difference between ext3 and ext4 filesystem in Linux ?
How to change default login shell permanently in linux
What is GRUB Boot Loader ?

Practical examples for using find command in Linux

$
0
0
Here I have tried to show you a list of options or arguments which you can use with find command to narrow down your search queries.

Find all the files with respect to their permission


using octal method
# find / -perm755-typef
using symbolic method
# find / -permu=rwx,g=rx,o=rx-typef
Find all files with executable permission
# find / -executable -typef
Find all files with writable permission
# find / -writable -typef
Find all files with readable permission
# find / -readable -typef

Locate files with respect to their special permission


Find all the executable files inside /usr/bin, /bin/, /usr/sbin/, /sbin/ with SGID
# find /usr/bin/ /bin/ /usr/sbin/ /sbin/-perm+2000-execuatble
/usr/bin/ssh-agent
/usr/bin/locate
/usr/bin/wall
/usr/bin/write

Find all the executable files inside /usr/bin, /bin/, /usr/sbin/, /sbin/ with SUID
# find /usr/bin/ /bin/ /usr/sbin/ /sbin/-perm +4000-execuatble
/usr/bin/ksu
/usr/bin/gpasswd
/usr/bin/chsh
/usr/bin/chage
/usr/bin/sudo

Locate files with respect to size


Find all the files with more than 30MB size
# find / -size+30M-typef
Find all the files with more than 1GB size
# find / -size+1G-typef
Find all the files with more than 6KB size
# find / -size +6k -typef
NOTE: In case you want to find files/directories with size less than, use "-" sign instead of "+" sign in above examples

Find files with respect to their owners


Find all the files whose user owner is deepak
# find / -user deepak -type f
Find all the files whose group owner is deepak
# find / -group deepak -typef
NOTE: You can also use -uid and -gid argument respectively instead of -user and -group

Saving o/p to file with extra parameter


This command will locate for all the files/directories with user owner deepak and save the o/p to file.txt (the o/p will resemble same as ls -l)
# find / -user deepak -flsfile.txt
# cat file.txt
   210    4 drwx------   9 deepak   deepak       4096 Apr  5 20:26 /home/deepak
   868    4 -rw-r--r--   1 deepak   deepak        176 Jul 18  2013 /home/deepak/.bash_profile
  7053    4 -rw-r--r--   1 deepak   deepak        124 Jul 18  2013 /home/deepak/.bashrc
  7078    4 drwxrwxr-x   2 deepak   deepak       4096 Apr  5 20:26 /home/deepak/mywork
  7083    4 -rw-------   1 deepak   deepak         99 Apr  5 20:27 /home/deepak/.bash_history
  7080    4 drwxrwxr-x   2 deepak   deepak       4096 Apr  5 20:26 /home/deepak/work
  7073    4 drwxr-xr-x   2 deepak   deepak       4096 Nov 12  2010 /home/deepak/.gnome2
  7074    4 drwxr-xr-x   4 deepak   deepak       4096 Mar 14 02:38 /home/deepak/.mozilla

NOTE: If the files does not exist it will be created, and if it already exists then it will be overwritten

This command will just save the o/p to file.txt
# find / -user deepak  -fprintfile.txt
# cat file.txt
/home/deepak
/home/deepak/.bash_profile
/home/deepak/.bashrc
/home/deepak/mywork
/home/deepak/.bash_history
/home/deepak/work
/home/deepak/.gnome2
/home/deepak/.mozilla

Add an extra argument along with find command


This command will show you long list details of all the files with size more than 50MB
# find / -size +50M  -ls
270138 65588 -rw-r--r--   1 root     root     67159234 Nov 23 00:20 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre/lib/rt.jar
134253 96796 -rw-r--r--   1 root     root     99158576 Mar 14 02:39 /usr/lib/locale/locale-archive
  7291    0 -rw-------   1 root     root     134217728 Apr  5 16:49 /sys/devices/pci0000:00/0000:00:0f.0/resource1
  7292    0 -rw-------   1 root     root     134217728 Apr  5 20:17 /sys/devices/pci0000:00/0000:00:0f.0/resource1_wc

Find files irrespective of case


This command will find all the files/directories inside /home with name "test" irrespective of case
# find /home/-inametest
/home/deepak/test
/home/deepak/Test

Find files/directory with respect to their name


Find all the files/directories with name "test"
# find /home/-nametest
/home/deepak/test

Find files using wildcard


This command will search all the files with .txt extentsion
# find / -name *.txt -typef
This command will search all the files from file[0-9] with .txt extentsion
# find / -name file?.txt -typef

Find files with respect to their modification/access time


Find all the directories accessed before 5 min
# find / -amin -5 -typed
Find all the directories accessed 60 min back from current time
# find / -amin+60 -type d
Find all the files/directories accessed exactly 5 min back
# find / -amin-type d
Find all the files/directories accessed 5 days back
# find / -atime-5 -type d
NOTE: You can run all the above commands as per the modification time just by replacing "-atime" with "-mtime"

Complex example


Locate all files with name test.tx inside /home/deepak and remove them
# find /home/deepak/-name test.txt -type f | xargs rm -f

or

# find /home/deepak/-nametest.txt -type f -exec rm -f {} \;


Please do let me know your feedback or in case I missed any thing.

Related Articles
8 examples to help you understand top command usage in Unix/Linux

Follow the below links for more tutorials

Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to configure Samba 4 Secondary Domain Controller
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is swappiness and how do we change its value?
How to log iptables messages in different log file
What are the s and k scripts in the etc rcx.d directories
How to check all the currently running services in Linux
How to auto start service after reboot in Linux
What is virtual memory, paging and swap space?

RAID levels 0, 1, 2, 3, 4, 5, 6, 0+1, 1+0 features explained in detail

$
0
0

What is RAID?

RAID stands for Redundant Array of Inexpensive Disks which was later interpreted to Redundant Array of Independent Disks. This technology is now used in almost all the IT organizations looking for data redundancy and better performance. It combines multiple available disks into 1 or more logical drive and gives you the ability to survive one or more drive failures depending upon the RAID level used.

Why to use RAID?

With the increasing demand in the storage and data world wide the prime concern for the organization is moving towards the security of their data. Now when I use the term security, here it does not means security from vulnerable attacks rather than from hard disk failures and any such relevant accidents which can lead to destruction of data. Now at those scenarios RAID plays it magic by giving you redundancy and an opportunity to get back all your data within a glimpse of time.

Levels

Now with the moving generation and introduction of new technologies new RAID levels started coming into the picture with various improvisation giving an opportunity to organizations to select the required model of RAID as per their work requirement.

Now here I will be giving you brief introduction about some of the main RAID levels which are used in various organizations.

RAID 0

This level strips the data into multiple available drives equally giving a very high read and write performance but offering no fault tolerance or redundancy. This level does not provides any of the RAID factor and cannot be considered in an organization looking for redundancy instead it is preferred where high performance is required.

Calculation:
No. of Disk: 5
Size of each disk: 100GB

Usable Disk size: 500GB

Pros
Cons
Data is stripped into multiple drives
No support for Data Redundancy
Disk space is fully utilized
No support for Fault Tolerance
Minimum 2 drives required
No error detection mechanism
High performance
Failure of either disk results in complete data loss in respective array

RAID 1

This level performs mirroring of data in drive 1 to drive 2. It offers 100% redundancy as array will continue to work even if either disk fails. So organization looking for better redundancy can opt for this solution but again cost can become a factor.

Calculation:
No. of Disk: 2
Size of each disk: 100GB

Usable Disk size: 100GB

Pros
Cons
Performs mirroring of data i.e identical data from one drive is written to another drive for redundancy.
Expense is higher (1 extra drive required per drive for mirroring)
High read speed as either disk can be used if one disk is busy
Slow write performance as all drives has to be updated
Array will function even if any one of the drive fails

Minimum 2 drives required


RAID 2

This level uses bit-level data stripping rather than block level. To be able to use RAID 2 make sure the disk selected has no self disk error checking mechanism as this level uses external Hamming code for error detection. This is one of the reason RAID is not in the existence in real IT world as most of the disks used these days come with self error detection. It uses an extra disk for storing all the parity information

Calculation:
Formula: n-1 where n is the no. of disk

No. of Disk: 3
Size of each disk: 100GB

Usable Disk size: 200GB

Pros
Cons
BIT level stripping with parity
It is used with drives with no built in error detection mechanism
One designated drive is used to store parity
These days all SCSI drives have error detection
Uses Hamming code for error detection
Additional drives required for error detection

RAID 3

This level uses byte level stripping along with parity. One dedicated drive is used to store the parity information and in case of any drive failure the parity is restored using this extra drive. But in case the parity drive crashes then the redundancy gets affected again so not much considered in organizations.

Calculation:
Formula: n-1 where n is the no. of disk

No. of Disk: 3
Size of each disk: 100GB

Usable Disk size: 200GB


Pros
Cons
BYTE level stripping with parity
Additional drives required for parity
One designated drive is used to store parity
No redundancy in case parity drive crashes
Data is regenerated using parity drive
Slow performance for operating on small sized files
Data is accessed parallel

High data transfer rates (for large sized files)

Minimum 3 drives required


RAID 4

This level is very much similar to RAID 3 apart from the feature where RAID 4 uses block level stripping rather than byte level.

Calculation:
Formula: n-1 where n is the no. of disk

No. of Disk: 3
Size of each disk: 100GB

Usable Disk size: 200GB

Pros
Cons
BLOCK level stripping along with dedicated parity
Since only 1 block is accessed at a time so performance degrades
One designated drive is used to store parity
Additional drives required for parity
Data is accessed independently
Write operation becomes slow as every time a parity has to be entered
Minimum 3 drives required

High read performance since data is accessed independently.


RAID 5

It uses block level stripping and with this level distributed parity concept came into the picture leaving behind the traditional dedicated parity as used in RAID 3 and RAID 5.  Parity information is written to a different disk in the array for each stripe. In case of single disk failure data can be recovered with the help of distributed parity without affecting the operation and other read write operations.

Calculation:
Formula: n-1 where n is the no. of disk

No. of Disk: 4
Size of each disk: 100GB

Usable Disk size: 300GB


Pros
Cons
Block level stripping with DISTRIBUTED parity
In case of disk failure recovery may take longer time as parity has to be calculated from all available drives
Parity is distributed across the disks in an array
Cannot survive concurrent drive failures
High Performance

Cost effective

Minimum 3 drives required


RAID 6

This level is an enhanced version of RAID 5 adding extra benefit of dual parity. This level uses block level stripping with DUAL distributed parity. So now you can get extra redundancy. Imagine you are using RAID 5 and 1 of your disk fails so you need to hurry to replace the failed disk because if simultaneously another disk fails then you won't be able to recover any of the data so for those situations RAID 6 plays its part where you can survive 2 concurrent disk failures before you run out of options.

Calculation:
Formula: n-2 where n is the no. of disk

No. of Disk: 4
Size of each disk: 100GB

Usable Disk size: 200GB

Pros
Cons
Block level stripping with DUAL distributed parity
Cost Expense can become a factor
2 parity blocks are created
Writing data takes longer time due to dual parity
Can survive concurrent 2 drive failures in an array

Extra Fault Tolerance and Redundancy

Minimum 4 drives required


RAID 0+1

This level uses RAID 0 and RAID 1 for providing redundancy. Stripping of data is performed before Mirroring. In this level the overall capacity of usable drives is reduced as compared to other RAID levels. You can sustain more than one drive failure as long as they are not in the same mirrored set.

NOTE: The no. of drives to be created should always be in the multiple of 2

Calculation:
Formula: n/2 * size of disk (where n is the no. of disk)

No. of Disk: 8
Size of each disk: 100GB

Usable Disk size: 400GB

Pros
Cons
No parity generation
Costly as extra drive is required for each drive
Performs RAID 0  to strip data and RAID 1 to mirror
100% disk capacity is not utilized as half is used for mirroring
Stripping is performed before Mirroring
Very limited scalability
Usable capacity is n/2 * size of disk (n = no. of disks)

Drives required should be multiple of 2

High Performance as data is stripped


RAID 1+0 (RAID 10)

This level performs Mirroring of data prior stripping which makes it much more efficient and redundant as compared to RAID 0+1. This level can survive multiple simultaneous drive failures. This can be used in organizations where high performance and security are required. In terms of fault Tolerance and rebuild performance it is better than RAID 0+1.

NOTE: The no. of drives to be created should always be in the multiple of 2

Calculation:
Formula: n/2 * size of disk (where n is the no. of disk)

No. of Disk: 8
Size of each disk: 100GB

Usable Disk size: 400GB

Pros
Cons
No Parity generation
Very Expensive
Performs RAID 1 to mirror and RAID 0 to strip data
Limited scalability
Mirroring is performed before stripping

Drives required should be multiple of 2

Usable capacity is n/2 * size of disk (n = no. of disks)

Better Fault Tolerance than RAID 0+1

Better Redundancy and faster rebuild than 0+1

Can sustain multiple drive failures



Related Articles:
Tutorial for SYSLOG with Examples in Red Hat Linux
What is kernel-PAE in Linux?
What is swappiness and how do we change its value?
What is virtual memory, paging and swap space?
What is GRUB Boot Loader ?


Follow the below links for more tutorials

Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to secure Apache web server in Linux using password (.htaccess)
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
How to log iptables messages in different log file



What are the maximum and minimum limits for RHEL 4 vs 5 vs 6 ?

$
0
0
Below chart shows you the comparison of various features of Red Hat Enterprise Linux between version 4, 5 and 6.


Version 4
Version 5
Version 6
Maximum Logical CPUs



X86
32
32
32
Itanium 2
256/512
256/1024
NA
X86_64
64/64
160/255
160/4096
POWER
64/128
128/128
128




Maximum Memory



X86
64GB
16GB
16GB
Itanium 2
2TB
2TB
NA
X86_64
256GB/1TB
1TB
3TB/64TB
POWER
128GB/1TB
512GB/1TB
2TB




Required Minimum



X86
256MB
512MB minimum/1GB/logical CPU recommended
512MB minimum/1GB/logical CPU recommended
X86_64
256MB
512MB minimum/1GB/logical CPU recommended
512MB minimum/1GB/logical CPU recommended
Itanium 2
512MB
512MB minimum/1GB/logical CPU recommended
NA
POWER
512MB
1GB minimum/ 2GB recommended
2GB minimum/ 2GB required per install
Minimum Disk Space
800MB
1GB minimum/ 5GB recommended
1GB minimum/ 5GB recommended



File systems & storage limits



Maximum filesize (Ext3)
2TB
2TB
2TB
Maximum filesystem size (Ext3)
8TB
16TB
16TB
Maximum filesize (Ext4)
---
16TB
16TB
Maximum filesystem size (Ext4)
---
16TB
16TB
Maximum filesize (GFS)
16TB/8EB *
16TB/8EB *
NA
Maximum filesystem size (GFS)
16TB/8EB *
16TB/8EB *
NA
Maximum filesize (GFS2)
---
100TB
100TB
Maximum filesystem size (GFS2)
---
100TB
100TB
Maximum filesize (XFS)
---
100TB
100TB
Maximum filesystem size (XFS)
---
100TB
100TB




Kernel and OS features



Kernel foundation
Linux 2.6.9
Linux 2.6.18
Linux 2.6.32-2.6.34
Compiler
GCC 3.4
GCC 4.1
GCC 4.4

NOTE:* If there are any 32-bit machines in the cluster, the maximum gfs file system size is 16TB. If all machines in the cluster are 64-bit, the maximum size is 8EB




Follow the below links for more tutorials

Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
How to secure Apache web server in Linux using password (.htaccess)
Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
15 tips to enhance security of your Linux machine
Why is Linux more secure than windows and any other OS
How to log iptables messages in different log file

Viewing all 392 articles
Browse latest View live