WHAT’S RAID5 AND HOW TO CONFIGURE IN LINUX

RAID level 5 uses striping, so data is spread across number of disks used in the array, and also provides redundancy with the help of parity. Raid 5 requires minimum three harddisks .

raid5 in linux

HOW IT WORKS :

Let data be 1, 2, 3, 4, 5 and 6 . You can see raid 5 spreads data like 1346 goes to sda5 harddisk , 2,1,5,4 goes to sda6  and 3,2,6,5 goes to sda7 . If one harddisk crash , raid 5 can redundant data from remaining two harddisks . That’s why Raid 5 size is 2000MB . But its main drawback is , if two harddisk crashes all data are lost .

HOW TO CONFIGURE RAID 5 IN LINUX

  • Create three partitions
  • Command n ( to create partitions)
  • Make sure your partitions are of same size .
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 65399.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-65399, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-65399, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57614-65399, default 57614):
Using default value 57614
Last cylinder or +size or +sizeM or +sizeK (57614-65399, default 65399): +1000M
  • Now we have to change partition type to configure raid .
  • Command t ( to change partition type )
  • Command w ( to save )
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-7): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
  • Run partprobe command to save all changes made .
[root@localhost ~]# partprobe /dev/sda
  • Check by fdisk -l command .
[root@localhost ~]# fdisk -l
Disk /dev/sda: 537.9 GB, 537932857344 bytes
255 heads, 63 sectors/track, 65399 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       50993   409601241   83  Linux
/dev/sda2           50994       57367    51199155   82  Linux swap / Solaris
/dev/sda4           57368       65399    64517040    5  Extended
/dev/sda5           57368       57490      987966   fd  Linux raid autodetect
/dev/sda6           57491       57613      987966   fd  Linux raid autodetect
/dev/sda7           57614       57736      987966   fd  Linux raid autodetect
  • Your partition is ready
  • Now create raid
  • After mdadm –create   give raidname like /dev/md5 or md6 , md1 , m2 any
  • –level=5 (raid5) means we want /dev/md5 to be raid 5
  • Then give partition you want to add in this raid .
  • It might ask “Continue creating array ?” . Type yes and hit ENTER .
[root@localhost ~]# mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/sda5 /dev/sda6 /dev/sda7
mdadm: /dev/sda5 appears to contain an ext2fs file system
    size=987840K  mtime=Tue Jan 17 23:52:57 2017
mdadm: /dev/sda5 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Tue Jan 17 23:51:54 2017
mdadm: /dev/sda6 appears to contain an ext2fs file system
    size=987840K  mtime=Tue Jan 17 23:52:57 2017
mdadm: /dev/sda6 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Tue Jan 17 23:51:54 2017
mdadm: /dev/sda7 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Tue Jan 17 00:57:01 2017
Continue creating array? yes
mdadm: array /dev/md5 started.
  • To check raid type command  cat  /proc/mdstat
  • md5 (raid 5) is active on sda5 , sda6 sda7
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sda7[2] sda6[1] sda5[0]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
  • Format /dev/md5 .
[root@localhost ~]# mkfs.ext3 /dev/md5
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
247296 inodes, 493920 blocks
24696 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=507510784
16 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
  • Create folder where you want to mount . Like my folder is 3usageeks
  • To mount  –    mount  raidname  foldername
  • df  -h command to check
[root@localhost ~]# mount /dev/md5 3usageeks
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  4.9G  355G   2% /
tmpfs                 947M     0  947M   0% /dev/shm
/dev/md5              1.9G   35M  1.8G   2% /root/3usageeks
  • That was temporary mounting , it will disappear when system reboots .
  • For permanent mounting .Go to /etc/fstab file .
[root@localhost ~]# vim /etc/fstab
  • Now make entry as shown below .
  • First is what you want to mount
  • Second is where you want to mount
  • Third file type . it’s ext3
  • Rest will be same
LABEL=/                 /                       ext3    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/md5                /root/3usageeks         ext3    defaults         0 0
~
  • Press ESC and type :wq ( to save and quit )
~
~
~
:wq

 

 

Don’t hesitate to comment if you got any problem .

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s