HOW TO FAIL, REMOVE AND REPLACE PARTITION IN RAID (linux)

In this post we will learn how to fail one harddisk , remove harddisk from raid  and then replace it with other harddisk . I’m gonna show you this lab on raid 5 . Raid 5 requires minimum three harddisks . In this diagram , i’m going to fail sda6 harddisk , remove it and replace it with sda 8 harddisk .

raid 5 in linux

  • First lets create partitions .
  • Make sure all partitions have equal size
  • Command n  ( to create partition )
  • Command t    ( change partition type )
[root@localhost ~]# fdisk /dev/sda
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

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57614-65399, default 57614):
Using default value 57614
Last cylinder or +size or +sizeM or +sizeK (57614-65399, default 65399): +1000M
Command (m for help): t
Partition number (1-7): 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-7): 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-7): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)
  • Create one more partition for replacing fail one .
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57737-65399, default 57737):
Using default value 57737
Last cylinder or +size or +sizeM or +sizeK (57737-65399, default 65399): +1000M

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): w
  • Mandatory – Run partprobe command to save all changes .
[root@localhost ~]# partprobe /dev/sda
  • Now create raid 5 .
  • –level will be 5 (raid 5)
  • Add partitions sda5 , sda 6 and sda7
  • It might ask ” Continue creating array ? ” . Type yes and hit Enter .
[root@localhost ~]# mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/sda5 /dev/sda6 /dev/sda7
mdadm: /dev/sda5 appears to contain an ext2fs file system
    size=3951232K  mtime=Wed Jan 25 08:20:49 2017
mdadm: /dev/sda5 appears to be part of a raid array:
    level=raid0 devices=2 ctime=Wed Jan 25 08:19:29 2017
mdadm: /dev/sda6 appears to be part of a raid array:
    level=raid0 devices=2 ctime=Wed Jan 25 08:19:29 2017
mdadm: /dev/sda7 appears to be part of a raid array:
    level=raid0 devices=2 ctime=Wed Jan 25 08:19:45 2017
Continue creating array? yes
mdadm: array /dev/md5 started.
  • Let’s fail sda6 from /dev/md5 (raid 5)
[root@localhost ~]# mdadm /dev/md5 --fail /dev/sda6
mdadm: set /dev/sda6 faulty in /dev/md5
  • Check by   cat   /proc/mdstat command to see  which raid is active and on which partition .
  • Like md5 ( raid5) is active on sda7 and sda5 .   SDA6 is failed .
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0]
md5 : active raid5 sda7[3](S) sda6[4](F) sda5[0]
  • Now we will remove sda5 from /dev/md5
[root@localhost ~]# mdadm /dev/md5 --remove /dev/sda6
mdadm: hot removed /dev/sda6
  • Then add new partition that we create for replacement ( sda8) in /dev/md5
[root@localhost ~]# mdadm /dev/md5 --add /dev/sda8
mdadm: added /dev/sda8
  • Again run   cat   /proc/mdstat command to check
  • You can see now md5 is active on sda8 , sda7 and sda5
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0]
md5 : active raid5 sda8[4](S) sda7[3](S) sda5[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