RAID1 – HOW IT WORKS AND HOW TO CONFIGURE IT IN LINUX

In this post we will learn how to configure raid 1 in linux . And how it works .

 

raid 1 in linux

HOW IT WORKS:

Let me explain Raid 1 diagram shown above to better understand how it works . Raid 1 requires two harddisks and of same size . Let my data be 1 ,2 , 3 and 4 . Raid 1 is also known as mirroring of data . So Raid 1 is saving my data to both  harddisks . 1,2 , 3 and 4 goes to harddisk 5(sda5) and same data goes to harddisk 6(sda6) . That’s why Raid 1 size is 1000MB because it can take data from any one harddisk . If your one harddisk is crash , Raid 1 can still have data on another harddisk . For safety purpose Raid 1 is better than Raid 0 .

CONFIGURE RAID1 IN LINUX

  • Create two partitions and make sure they are are of same size .
  • Command n     ( to create partition )
[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
  • Also change partition type  to raid
  • Code   –  fd    ( linux raid)
  • Command   t  ( to change partition type )
  • Command p ( to print )
  • Command  w     ( to save)
  • Make sure you run Partprobe command after that to save all changes made .
Command (m for help): t
Partition number (1-6): 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-6): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)

Command (m for help): p
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

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.
[root@localhost ~]# partprobe /dev/sda
  • Now your partitions are ready .
  • Let’s create Raid 5 .
  •  After mdadm –create  give raid name like /dev/md1 or md2, md3 any .
  • –level =1 ( raid 1) means my  /dev/md1 should be raid 1
  • Then add your both partition in /dev/md1
  • It might ask “Continue creating array ? ”  Type yes and hit ENTER .
[root@localhost ~]# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda5 /dev/sda6
mdadm: /dev/sda5 appears to contain an ext2fs file system
    size=3950976K  mtime=Tue Jan 17 06:16:22 2017
mdadm: /dev/sda5 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Tue Jan 17 00:56:10 2017
mdadm: /dev/sda6 appears to contain an ext2fs file system
    size=3950976K  mtime=Tue Jan 17 06:16:22 2017
mdadm: /dev/sda6 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Tue Jan 17 00:56:10 2017
Continue creating array? yes
mdadm: array /dev/md1 started.
  • Command  cat  /proc/mdstat to check raid
  • As you can see md1  is active on sda5 and sda6
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda6[1] sda5[0]
      987840 blocks [2/2] [UU]
      
unused devices: <none>
  • Format it before mounting .
[root@localhost ~]# mkfs.ext3 /dev/md1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
123648 inodes, 246960 blocks
12348 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=255852544
8 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • Create folder to mount that raid .
[root@localhost ~]# mkdir 3usageeks

  • Mount /dev/md1 to that folder
  • Type mount  raidname  foldername
  • Type df -h command to check .
[root@localhost ~]# mount /dev/md1 3usageeks
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             379G  4.8G  355G   2% /
tmpfs                 947M     0  947M   0% /dev/shm
/dev/md1              950M   18M  885M   2% /root/3usageeks
  • For permanent mounting
  • Go to /etc/fstab
[root@localhost ~]# vim /etc/fstab
  • Now make entry as shown below
  • First what you want to mount
  • Second where you want to mount
  • Third what type of file it is . 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/md1                /root/3usageeks         ext3    defaults         0 0
~
  • Press ESC and type :wq ( to save and quit )
~
~
~
:wq

 

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