LINUX – HOW TO ADD SPARE DEVICES IN RAID.

In this post we will learn how to configure raid with spare  devices in linux . In this lab you will see sda8 is a spare device added in /dev/md1 (raid5) . It means if one of the drive fails spare device ( sda8) will take its place .

spare device in raid

  • First create four partitions . We want to make raid 5 and as you know requires minimum three partitions . One extra partition for adding in spare devices .
  • Command n ( to create partition in linux )
  • Command t ( to change partition type )
  • Hex code   -fd ( linux raid )
  • Command w ( to save )
[root@3usageeks ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 68514.
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-68514, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-68514, default 68514): +500M

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

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

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57554-68514, default 57554):
Using default value 57554
Last cylinder or +size or +sizeM or +sizeK (57554-68514, default 68514): +500M
Command (m for help): t 
Partition number (1-8): 8 
Hex code (type L to list codes): fd 
Changed system type of partition 8 to fd (Linux raid autodetect) 

Command (m for help): t 
Partition number (1-8): 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-8): 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-8): 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.
  • Mandotory – run partprobe command to save all changes made .
[root@3usageeks ~]# partprobe /dev/sda
  • Now create raid 5
  • –level=5 ( raid 5)
  • Add all three raid devices
  • After that add spare deices you wanna include
[root@3usageeks ~]# mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sda5 /dev/sda6 /dev/sda7 --spare-devices=1 /dev/sda8
mdadm: array /dev/md1 started.
  • Check by   cat  /proc /mdstat command
  • You will see after sda8 there is symbol [s] means it is spare devices .
[root@3usageeks ~]# cat /proc/mdstat
Personalities : [raid1] 
md1 : active raid5 sda7[2] sda8[3](S) sda6[1] sda5[0]
      995712 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU
  • Lets fail one drive to check spare device ( sda8 ) will take it place or not .
[root@3usageeks ~]# mdadm /dev/md1 --fail /dev/sda6
mdadm: set /dev/sda6 faulty in /dev/md1
  • Again run cat  /proc/mdstat command  to check
  • You can see sda 6 is Failed ( F) .
[root@3usageeks ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md1 : active raid5 sda7[2] sda8[1] sda6[3](F) sda5[0]
      995712 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
  • There’s one more command to check raid .
  • With this command you will easily understand .
[root@3usageeks ~]# mdadm --detail /dev/md1
/dev/md1:
        Version : 0.90
  Creation Time : Sat Feb  4 03:27:23 2017
     Raid Level : raid5
     Array Size : 995712 (972.54 MiB 1019.61 MB)
  Used Dev Size : 497856 (486.27 MiB 509.80 MB)
   Raid Devices : 3
  Total Devices : 4
Preferred Minor : 1
    Persistence : Superblock is persistent
    Update Time : Sat Feb  4 03:28:22 2017
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 0
         Layout : left-symmetric
     Chunk Size : 64K
           UUID : e337c6d6:123947db:2941f62a:e79b9291
         Events : 0.6
    Number   Major   Minor   RaidDevice State
       0       8        5        0      active sync   /dev/sda5
       1       8        8        1      active sync   /dev/sda8
       2       8        7        2      active sync   /dev/sda7
       3       8        6        -      faulty spare   /dev/sda6

 

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