Saturday 4 January 2014

Find Command in Linux with Examples

FIND:- Find  - searches for files in a directory hierarchy

FIND command  uses and example

(1) Find all files whose name is abc in pwd (Present Working Directory)
[root@CLIENT ~ ] #  find . -name abc
./abc

(2) Find all file in /home directory  whose name is abc
[root@CLIENT ~ ] # find  /home  -name  abc

(3) Find all file whose name is abc ignoring case senstivity
[root@CLIENT ~ ] # find /home  -iname abc

(4) Find a directory in  /home directory  whose name is arun
[root@CLIENT ~ ] # find /home -type d -name arun
/home/arun

(5) Find all html files in Linux file system
[root@CLIENT ~ ] # find  / -type f -name "*.html"

(6) Find files base on their permissions
[root@CLIENT ~ ] # find  / -type f   -perm 700

(7) Find all files with their permission 700 and change permission with  600
[root@CLIENT ~ ] # find  / -type  f  -perm 700 -exec chmod 600 {} \;

(8) Find all files  base on user arun
[root@CLIENT ~ ] # find  /  -user arun

(9) Find all files  base on group Linux
[root@CLIENT ~ ] # find  /  -group Linux

(10) Find a particular file named abc.txt of user arun
[root@CLIENT ~ ] # find  /  -type f -user arun -name abc.txt

(11) Find files and directory on base of date and time

-atime    access time              |          +90          more than 90 days back
-mtime   modified time           |           90           exact 90 days back
-ctime    change time             |           -90          less than 90 days back

[root@CLIENT ~ ] #  find  / -ctime +90

(12) Find  files whose size is less than 10 MB
[root@CLIENT ~ ] #  find  /  -size  -10M

(13) Find  files whose size is less than 100 MB and more than 50 MB
[root@CLIENT ~ ] #  find  /  -size  -100M  -size  +50M











Thursday 2 January 2014

Boot Process of Linux

There are 6 process occurs during booting process of kernel

(1) BIOS
(2) MBR
(3) GRUB
(4) KERNEL
(5) INIT
(6) RUN LEVEL PROGRAMS


BIOS:- BIOS stands for Basic Input Output System
Bios search , loads & execute boot loader program.Once the boot loader program is detected & loaded into memory.Bios gives control to it.


MBR:- MBR stands for master boot record
 The first sector  of bootable device is MBR
Its size is 512 bytes


 446 Bytes
 (Primary Bootloader Info)
64 Bytes
 (Partition table info) 
2Bytes (validation check)




GRUB:- GRUB stands Grand Unified Bootloader 
It loads and execute the defaults kernel image as specified in grub configuration file /boot/grub/grub.conf


KERNEL:- Mount the root file system . Kernel execute the /sbin/init .INIT is the first prog executed in Linux kernel .Kernel contains device driver compiled inside which help to access the hardware.

INIT:- INIT decide the run levels. These run levels are mention in /etc/inittab file
There are 7 run levels in linux

0  -->  Halt
1  -->  Single user mode
2  -->  Multiuser mode without NFS
3  -->  Full multiuser mode
4  -->  Unused
5  -->  Graphical
6  -->  Reboot

RUN LEVEL PROGRAMS:- When the Linux system booting up various services getting started.
for example   httpd ---- OK
                     named----OK
                     vsftpd -----OK
Depending on your default init level setting , the system will execute the programs from one of the following directory.


Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/

Difference Between Soft Link & Hard Link in Linux

Soft Link :- soft links are the shortcut to the original file .If u delete the original file the shortcuts will fail.Soft links have different inode number than source file

Command to create  soft link:-  ln -s  /root/file1  /root/Desktop/file2 


Hard Link :-  Hard Links are mirror copy of  source file .If we changes in file 1 it appears in file 2. Hard links have same inode number as of source file

Command to create  soft link:-  ln   /root/file1  /root/Desktop/file2 

RAID (Redundant Array of Independent Disks) in Linux with Practical

RAID (Redundant Array of Independent Drives (or Disks)
A. A Redundant Array of Independent Drives (or Disks), also known as Redundant Array of Inexpensive Drives (or Disks) (RAID) is an term for data storage schemes that divide and/or replicate data among multiple hard drives. RAID can be designed to provide increased data reliability or increased I/O performance, though one goal may compromise the other.

Mainly there are 3 types of RAID :

RAID  0
RAID  1
RAID  5



RAID 0 (Striping)
This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of all disks used. Practical example: 3 disks, each 80GB in size can be used in a 240GB RAID 0 configuration.

RAID 0 works by breaking data into fragments and writing to all disk simultaneously. This significantly improves the read and write performance. On the other hand, no single disk contains the entire information for any bit of data committed. This means that if one of the disks fails, the entire RAID is rendered inoperable, with unrecoverable loss of data.

RAID 0 is suitable for non-critical operations that require good performance, like the system partition or the /tmp partition where lots of temporary data is constantly written. It is not suitable for data storage.



RAID 1 (Mirroring)

This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of the smallest of disks used. This is because RAID 1 keeps every bit of data replicated on each of its devices in the exactly same fashion, create identical clones. Hence the name, mirroring. Practical example: 2 disks, each 80GB in size can be used in a 80GB RAID 1 configuration. On a side note, in mathematical terms, RAID 1 is an AND function, whereas RAID 0 is an OR.

Because of its configuration, RAID 1 reduced write performance, as every chunk of data has to be written n times, on each of the paired devices. The read performance is identical to single disks. Redundancy is improved, as the normal operation of the system can be maintained as long as any one disk is functional. RAID 1 is suitable for data storage, especially with non-intensive I/O tasks.






RAID 5

This is a more complex solution, with a minimum of three devices used. Two or more devices are configured in a RAID 0 setup, while the third (or last) device is a parity device. If one of the RAID 0 devices malfunctions, the array will continue operating, using the parity device as a backup. The failure will be transparent to the user, save for the reduced performance.

RAID 5 improves the write performance, as well as redundancy and is useful in mission-critical scenarios, where both good throughput and data integrity are important. RAID 5 does induce a slight CPU penalty due to parity calculations.





PRACTILE  OF RAID USING RAID 1
First create 3 partitions sda10,sda11,sda12 of raid type
[root@www ~]# mdadm -C /dev/md0 -l 1 -n 2 /dev/md10 /dev/md11
C-- create
l-- level
n-- numder of device
[root@www ~]# mdadm --detail /dev/md0
[root@www ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:24:07 2013
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.6


    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       1       8       12        1      active sync   /dev/sda11

      

[root@www ~]# mkfs.ext3 /dev/md0
[root@www ~]# mkdir /raid
[root@www ~]# mount /dev/md0 /raid
now add a spare device
[root@www ~]# mdadm --add /dev/md0 /dev/md12
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:24:07 2013
          State : clean
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.6

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       1       8       11        1      active sync   /dev/sda11
       2       8       12        2      spare sync   /dev/sda12
[root@www ~]# cp -rvf /etc /raid
[root@www ~]# mdadm --fail /dev/md0 /dev/sda11
[root@www ~]#  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:23:54 2013
          State : clean, degraded, recovering
 Active Devices : 1
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 1

 Rebuild Status : 50% complete

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.4

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       2       8       12        1      spare rebuilding   /dev/sda12

       3       8       11        -      faulty spare   /dev/sda11

[root@www ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Sun Jan 13 22:11:49 2013
     Raid Level : raid1
     Array Size : 104320 (101.89 MiB 106.82 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 2
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sun Jan 13 22:23:54 2013
          State : clean, degraded, recovering
 Active Devices : 1
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 1

 Rebuild Status : 94% complete

           UUID : 63a6d6db:ced50964:3fb69cfe:6b30dd55
         Events : 0.4

    Number   Major   Minor   RaidDevice State
       0       8       10        0      active sync   /dev/sda10
       2       8       12        1      spare rebuilding   /dev/sda12

       3       8       11        -      faulty spare   /dev/sda11