How to create software raid-1 with spare devices.

Posted: December 12, 2016 in RAID and LVM
Tags: , ,

This tutorial is all about software raid-1 creation in linux.We will learn how to configure software raid-1 in linux having spare devices.In this lab we are going to use RedHat Enterprise Linux 5 to configure software raid-1 with spare device.We use spare device as a reserved disk which is used only when any of disk used in raid-1 failed.

As we know RAID-1 needs minimum of two disk and when any of disk among those two failed or crashes spare device replaces itself with that failed device or disk.

raid1 configuration in linux

 

 

Step:1 create partitions from different disk and each partitions must have same space.

First check the number of disks available  using fdisk tool.

[root@localhost ~]# fdisk -l
Disk /dev/sda: 34.3 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 4177 33447330 8e Linux LVM
Disk /dev/sdb: 2306 MB, 2306867200 bytes
255 heads, 63 sectors/track, 280 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn’t contain a valid partition table
Disk /dev/sdd: 2306 MB, 2306867200 bytes
255 heads, 63 sectors/track, 280 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdd doesn’t contain a valid partition table

 

Now create partitions each of 1GB from each hard disk.

 

From above output you can clearly have a view about the number of disks available.

/dev/sda  /dev/sdb  /dev/sdc and /dev/sdd it means there are 4 hard disk available now.

 

Now its time to create partitions from different hard disk and change the partition type to RAID-Type because we are going to use these devices to create raid device.

 

[root@localhost ~]# fdisk /dev/sdb
 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 Building a new DOS disklabel. Changes will remain in memory only,
 until you decide to write them. After that, of course, the previous
 content won't be recoverable.
 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 Command (m for help): n
 Command action
 e extended
 p primary partition (1-4)
 p
 Partition number (1-4): 3
 First cylinder (1-280, default 1):
 Using default value 1
 Last cylinder or +size or +sizeM or +sizeK (1-280, default 280): +1G
 Command (m for help): t
 Selected partition 3
 Hex code (type L to list codes): fd
 Changed system type of partition 3 to fd (Linux raid autodetect)
 Command (m for help): p
 Disk /dev/sdb: 2306 MB, 2306867200 bytes
 255 heads, 63 sectors/track, 280 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Device Boot Start End Blocks Id System
 /dev/sdb3 1 123 987966 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 you must run partprobe command to save the changes in partition table as i have shown below

[root@localhost ~]# partprobe /dev/sdb

 

Similarly create partitions from each disks using fdisk and change there id to raid type.

root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): +1G
Command (m for help): p
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc3 1 123 987966 83 Linux
Command (m for help): t
Selected partition 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

 [root@localhost ~]# partprobe /dev/sdc

 

[root@localhost ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-280, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-280, default 280): +1G
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: 2306 MB, 2306867200 bytes
255 heads, 63 sectors/track, 280 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 123 987966 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

 [root@localhost ~]# partprobe /dev/sdd

 

Now after you finish the partition creation you can check it whether it is properly configured or not:

[root@localhost ~]# fdisk -l
Disk /dev/sda: 34.3 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 4177 33447330 8e Linux LVM
Disk /dev/sdb: 2306 MB, 2306867200 bytes
255 heads, 63 sectors/track, 280 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb3 1 123 987966 fd Linux raid autodetect
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc3 1 123 987966 fd Linux raid autodetect
Disk /dev/sdd: 2306 MB, 2306867200 bytes
255 heads, 63 sectors/track, 280 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdd1 1 123 987966 fd Linux raid autodetect

Step:2 now create raid device with spare device using mdadm command line tool.

 

 [root@localhost ~]# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb3 /dev/sdc3 --spare-devices=1 /dev/sdd1

 

The above code is self explanatory.

 

–level=1 shows it raid-1

/dev/md0  is name of raid device created

–raid-devices=2 tells two disks are used in this raid

/dev/sdb3 and /dev/sdc3 are those two disks used in raid

/dev/sdd1 is the spare device

Step3:check whether raid is properly created or not using below command.

[root@localhost ~]# mdadm –detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Mon Dec 12 14:18:02 2016
Raid Level : raid1
Array Size : 987840 (964.85 MiB 1011.55 MB)
Used Dev Size : 987840 (964.85 MiB 1011.55 MB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Mon Dec 12 14:18:25 2016
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
UUID : 7547df35:f740b7f7:06234e24:013d8e13
Events : 0.2
Number Major Minor RaidDevice State
0 8 19 0 active sync /dev/sdb3
1 8 35 1 active sync /dev/sdc3
2 8 49 – spare /dev/sdd1

 

You can also check raid creation using below command:

 [root@localhost ~]# cat /proc/mdstat
 Personalities : [raid1]
 md0 : active raid1 sdd1[2](S) sdc3[1] sdb3[0]
 987840 blocks [2/2] [UU]
 unused devices: <none>

 

Step4:Now to use raid devices format it and mount it.

 

First create a directory where we will mount created raid-1 device.

 [root@localhost ~]# mkdir /linuxtiwary

 

Now Format raid device using mkfs command:

[root@localhost ~]# mkfs.ext3 /dev/md0

 

Now mount the raid device:

[root@localhost ~]# mount /dev/md0 /linuxtiwary

 

Check your all mount using df command line tool:

[root@localhost ~]# df -Th
 Filesystem Type Size Used Avail Use% Mounted on
 /dev/mapper/VolGroup00-LogVol00
 ext3 29G 2.0G 26G 8% /
 /dev/sda1 ext3 99M 12M 82M 13% /boot
 tmpfs tmpfs 506M 0 506M 0% /dev/shm
 /dev/md0 ext3 950M 18M 885M 2% /linuxtiwary

 

Now our raid device is ready to use.

Leave a Reply

Please log in using one of these methods to post your comment:

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