INCLUDING LOOP DEVICES , CREATE RAID HAVING SPARE DEVICES IN LINUX

In this post you will learn how to configure raid over loop devices with spare devices in linux .

  • First we will create four files .
  • I’m creating .txt file but you can take .pdf or .mp3 any file to make it as loop devices .
[root@3usageeks ~]# touch q.txt
[root@3usageeks ~]# touch w.txt
[root@3usageeks ~]# touch e.txt
[root@3usageeks ~]# touch r.txt
  • Now i’m giving these files a size ( 1000MB to each one ) through dd ( disk dumping )
[root@3usageeks ~]# dd if=/dev/zero of=q.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 9.23686 seconds, 114 MB/s

[root@3usageeks ~]# dd if=/dev/zero of=w.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 26.7816 seconds, 39.2 MB/s

[root@3usageeks ~]# dd if=/dev/zero of=e.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 15.99 seconds, 65.6 MB/s

[root@3usageeks ~]# dd if=/dev/zero of=r.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 11.3283 seconds, 92.6 MB/s
  • Then we will convert these files into loop devices
[root@3usageeks ~]# losetup /dev/loop1 q.txt
[root@3usageeks ~]# losetup /dev/loop2 w.txt
[root@3usageeks ~]# losetup /dev/loop3 e.txt
[root@3usageeks ~]# losetup /dev/loop4 r.txt
  • Check by losetup  -a command .
[root@3usageeks ~]# losetup -a
/dev/loop1: [0801]:62488638 (q.txt)
/dev/loop2: [0801]:62488639 (w.txt)
/dev/loop3: [0801]:62488640 (e.txt)
/dev/loop4: [0801]:62488641 (r.txt)
  • Now create raid and add spare devices in last same as you add raid devices .
[root@3usageeks ~]# mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/loop1 /dev/loop2 /dev/loop3 --spare-devices=1 /dev/loop4
mdadm: array /dev/md5 started.
  • Now check by cat /proc/mdstat command
  • You can check md5 ( raid 5) is active on loop 1 , loop2  , loop 3 and spare device loop4
  • (S) stands for spare device
[root@3usageeks ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 loop3[4] loop4[3](S) loop2[1] loop1[0]
      2047872 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [>....................]  recovery =  1.4% (14720/1023936) finish=10.2min speed=1635K/sec
unused devices: <none>
  • Let’s fail one loop device to check whether spare device will take its place or not .
  • SO i’m going to fail loop2 .
[root@3usageeks ~]# mdadm /dev/md5 --fail /dev/loop2
mdadm: set /dev/loop2 faulty in /dev/md5
  • Now again run cat  /proc/mdstat command to check
[root@3usageeks ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 loop3[3] loop4[4] loop2[5](F) loop1[0]

 

 

 

 

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