In last post, we saw that how to create Software RAID 5 in Linux. In this post we would work on how we could add spare Disk in that RAID 5.

Detail of present RAID Device

We could find out md device detail with below commands. Number and name of disk used in RAID, like below

[root@srv6 ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Apr 19 01:47:10 2017
     Raid Level : raid5
     Array Size : 4189184 (4.00 GiB 4.29 GB)
  Used Dev Size : 2094592 (2045.84 MiB 2144.86 MB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Wed Apr 19 02:22:55 2017
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : srv6:0  (local to host srv6)
           UUID : 4e7c1751:cd467d3f:8e86a6a1:3c88f6a4
         Events : 18

     Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
       3       8       33        2      active sync   /dev/sdc1 

We can also check same thing in “/proc/mdstat” file.

[root@srv6 ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdc1[3] sdb1[1] sda1[0]
      4189184 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      
unused devices: 

We had already mounted /dev/md0 device under /raid5_disk directory.

[root@srv6 ~]# df -hTP /raid5_disk/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md0       ext4  4.0G  213M  3.6G   6% /raid5_disk

Addition of Another Disk in RAID

Now we have added another disk (/dev/sdd) to increase md device. We have to create disk partition and label it as RAID device.

[root@srv6 ~]# fdisk /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1009, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009): 
Using default value 1009

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

Command (m for help): p

Disk /dev/sdd: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdf5aa814

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1009     2095662   fd  Linux raid autodetect

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now we could add disk in already existing RAID device.

[root@srv6 ~]# mdadm --manage /dev/md0 --add /dev/sdd1 
mdadm: added /dev/sdd1

After addition of Disk in RAID device, we could see it quite easily as we check md device earlier.

[root@srv6 ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd1[4](S) sdc1[3] sdb1[1] sda1[0]
      4189184 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      
unused devices: 

We could also check it with mdadm command as well.

[root@srv6 ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Apr 19 01:47:10 2017
     Raid Level : raid5
     Array Size : 4189184 (4.00 GiB 4.29 GB)
  Used Dev Size : 2094592 (2045.84 MiB 2144.86 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Apr 19 14:20:41 2017
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 512K

           Name : srv6:0  (local to host srv6)
           UUID : 4e7c1751:cd467d3f:8e86a6a1:3c88f6a4
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
       3       8       33        2      active sync   /dev/sdc1

       4       8       49        -      spare   /dev/sdd1

Now we could see that new disk is used as spare device. Spare device is used automatically when any of active device fail. But right now we are working to know how it increase RAID disk storage. For same we have to add this Disk as Active member of RAID device. For that we need to work like below.

[root@srv6 ~]# mdadm --grow /dev/md0 -n4 
mdadm: Need to backup 3072K of critical section..

We could also check new Disk added in RAID in mdadm command and /proc/mdstat file. This Disk is also in Reshape status right now, which could seen in below output.

ev/md0:
        Version : 1.2
  Creation Time : Wed Apr 19 01:47:10 2017
     Raid Level : raid5
     Array Size : 4189184 (4.00 GiB 4.29 GB)
  Used Dev Size : 2094592 (2045.84 MiB 2144.86 MB)
   Raid Devices : 4
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Apr 19 14:52:30 2017
          State : clean, reshaping 
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

 Reshape Status : 29% complete
  Delta Devices : 1, (3->4)

           Name : srv6:0  (local to host srv6)
           UUID : 4e7c1751:cd467d3f:8e86a6a1:3c88f6a4
         Events : 43

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
       3       8       33        2      active sync   /dev/sdc1
       4       8       49        3      active sync   /dev/sdd1
[root@srv6 ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd1[4] sdc1[3] sdb1[1] sda1[0]
      4189184 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
      [=======>.............]  reshape = 38.0% (796672/2094592) finish=0.5min speed=36142K/sec
      
unused devices: 

Now we have to resize md0 device, So that it will effect in df command output as well, like below.

[root@srv6 ~]# df -hTP /raid5_disk
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md0      ext4   4.0G  213M  3.6G   6% /raid5_disk

[root@srv6 ~]# resize2fs /dev/md0
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/md0 is mounted on /raid5_disk; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/md0 to 1570944 (4k) blocks.
The filesystem on /dev/md0 is now 1570944 blocks long.

[root@srv6 ~]# df -hTP /raid5_disk
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md0       ext4  5.9G  213M  5.4G   4% /raid5_disk

After All this, don’t forget to save this configuration in /etc/mdadm.conf.

[root@srv6 ~]# mdadm --detail --scan --verbose >> /etc/mdadm.conf
[root@srv6 ~]# cat /etc/mdadm.conf 
ARRAY /dev/md0 level=raid5 num-devices=4 metadata=1.2 name=srv6:0 UUID=4e7c1751:cd467d3f:8e86a6a1:3c88f6a4
   devices=/dev/sda1,/dev/sdb1,/dev/sdc1,/dev/sdd1