HOW TO CONFIGURE RAID WITH SPARE DEVICES

In this article we will learn how to create raid with spare devices. I’m creating raid over loop devices but you can do it on partition also .

Question comes to your mind why we include spare devices?  Imagine we installed  three harddisk in our raid and if one of our hard disk fails , you are outside for break in your company then your superior screams at you because of data storage fails . Then spare devices comes into play.

raid with spare devies

Follow these steps to configure:

  • First we will create four files
[root@localhost ~]# touch a.txt
[root@localhost ~]# touch b.txt
[root@localhost ~]# touch c.txt
[root@localhost ~]# touch d.txt
  • Then we will give this file a size
[root@localhost ~]# dd if=/dev/zero of=a.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 4.06864 seconds, 129 MB/s

[root@localhost ~]# dd if=/dev/zero of=b.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 7.80803 seconds, 67.1 MB/s

[root@localhost ~]# dd if=/dev/zero of=c.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 9.49049 seconds, 55.2 MB/s

[root@localhost ~]# dd if=/dev/zero of=d.txt bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 8.06954 seconds, 65.0 MB/s
  • We will convert file into loop devices and check whether its been created or not
[root@localhost ~]# losetup /dev/loop0 a.txt
[root@localhost ~]# losetup /dev/loop1 b.txt
[root@localhost ~]# losetup /dev/loop2 c.txt
[root@localhost ~]# losetup /dev/loop3 d.txt

[root@localhost ~]# losetup -a
/dev/loop0: [0801]:618408 (a.txt)
/dev/loop1: [0801]:618415 (b.txt)
/dev/loop2: [0801]:618429 (c.txt)
/dev/loop3: [0801]:618430 (d.txt)
  • Now we will create raid 1 and as you know raid1 contains  only 2 partition so we will take loop0 ,loop1 and make loop2 & loop3 as spare devices.
[root@localhost ~]# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/loop0 /dev/loop1 --spare-devices=2 /dev/loop2 /dev/loop3

mdadm: array /dev/md1 started.

lets check whether its been created or not and if you see (s) back of any loop its spare device

[root@localhost ~]# cat /proc/mdstat

md1 : active raid1 loop3[3](S) loop2[2](S) loop1[1] loop0[0]
      511936 blocks [2/2] [UU]
      [=====>...............]  resync = 27.2% (139264/511936) finish=2.6min speed=2312K/sec
  • I’m going to fail one device lets see spare device will automatically take it place or not
[root@localhost ~]# mdadm /dev/md1 --fail /dev/loop1
mdadm: set /dev/loop1 faulty in /dev/md1
[root@localhost ~]# cat /proc/mdstat
md1 : active raid1 loop3[2] loop2[3](S) loop1[4](F) loop0[0]
      511936 blocks [2/1] [U_]
      [=>...................]  recovery =  5.8% (29824/511936) finish=3.2min speed=2485K/sec

You can see loop 4 fails and automatically loop3 takes it place.

So this how you can create raid with spare devices.

WHAT IS LOOP DEVICE AND HOW TO CONFIGURE

HOW TO SEND A MESSAGE THAT WILL SELF-DESTRUCT IN RECIPIENT’S INBOX

HOW TO CONFIGURE RAID OVER LVMHOW TO CONFIGURE RAID OVER LVM

2 thoughts on “HOW TO CONFIGURE RAID WITH SPARE DEVICES

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