Linux Software RAID
From LinuxFanBoy
The Linux software RAID system is very powerful and prefered by many over hardware RAID.
Contents |
RAID Creation
The best way to create a RAID array for the exam is to create it at installation time.
The VMware image I created has three disks so you can create a RAID5 array.
You can make a Linux software RAID from any set of like block devices. You can use disks, USB disks, memory cards and thumb drives. You can combine them to build RAID 0, 5, 10, 50 and other forms of RAID arrays. This is know as Just a Bunch of Disks
mdadm is the magic word for doing anything with RAID. To view the details of a raid array use the command:
mdadm --detail /dev/md0
Another way to view your software raid status is:
cat /proc/mdstat
To create a mirrored set of disks (RAID1) with a set of partitions (hda3 and hdb3) you would use a command like:
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda3 /dev/sdb3
This could be a three way mirror (hda3, hdb3 and hdc3)
mdadm --create /dev/md1 --level=1 --raid-devices=3 /dev/sda3 /dev/sdb3 /dev/hdc3
To create a raid five with the same set of three partitions the command would be:
mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sda3 /dev/sdb3 /dev/hdc3
In my case this show the array was degraded and disk 0 was showing removed. I used Spinrite to check the viability of the disk and it was ok. I then used this command to put the disk partition (sda2) back into the array (md0)
mdadm /dev/md0 -a /dev/sda2
The system started rebuilding and all was good.
Because disk 0 had failed I didn't thing the system would boot after I powered it off. I had build the system with its boot partition on disk 0 and used the space on the other drives as swap. What I didn't know was, Linux will create a RAID-1 (Mirror) from more then two disks.
Grub does not boot from the mirror. Because mirrors are copies of a partition and not stripped partitions all the data is on any one of the mirrors. Grub can then be pointed to any one of the mirrored partitions (sda1, sda2...) for its data.
After doing this it was time to build a new practice system.
Prepare a Disk for Software Raid
Make a RAID-1
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda3 /dev/sdb3
Make a RAID-5
mdadm --create /dev/md1 --level=1 --raid-devices=3 /dev/sda3 /dev/sdb3 /dev/hdc3
Make a Hot Spare
mdadm /dev/md1 --add /dev/sdd3
Remove a Failing Disk
We can simulate a drive failure by forcing one of the software raid members into a failed state.
mdadm /dev/md1 --fail /dev/sda3
A failed hard disk looks like this.
cat /proc/mdstat
or
mdadm --detail /dev/md1
We then remove the failed member from the array.
mdadm /dev/md1 --remove /dev/sda3
After replacing the failed drive, you add a "hot spare" and the system will automatically rebuild the failed md device(s) if a waiting hot spare has not already taken over.
mdamd /dev/md1 --add /dev/sda3
Predictive Disk Failure
In this case it is still working. To replace it you must deactivate it (mark it as failed) and then force it off line.
A physical disk may contain many partitions that are each a memory of a raid container. If the physical disk is in predictive failure you will need to fail each of these partitions before you remove the physical disk.
mdadm --fail /dev/md0 /dev/sdc1 mdadm --fail /dev/md1 /dev/sdc3 mdadm --detail /dev/md0 mdadm --detail /dev/md1
Now that the system knows the disk as failed you can power down and physicly remove it. After the disk is replaced you will need to recreate the partitions and use the add command to rebuild the virtual disks. The easy way to recreate the partitions is to copy the first sector from one of the other disks.
mdadm --remove /dev/md0 /dev/sdc1


