RAID
Steps to be followed to configure RAID on a linux system
First thing let's check if we have Raid already on our machine: cat /proc/mdstat
md stands for : multiple disk, used to stand for mirror disk since there was only RAID0
The tool we use is called : mdadm
‘multiple disk administration’
So make sure it is installed on the system!
sudo apt-get install mdadm
It is going to take a quite of time since it will generate a new initramd.
In my setup i have this :
The main disk which is sda and a couple of partitions sda1, sda2 we will use sdb, sdd, sdc for this lab
And for that lets partition them
Using fdisk do these steps for all of them and partition them all, for example using : fdisk /dev/sdb
the disk signature should be changed to fd ‘linux raid auto’, by default linux assigns linux signature to it
Make sure to write changes!
Now for the Creation time:
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
It will ask you if you want to continue creating the array type ‘y’ and press enter
As you can see, we specified the mirror level wich is RAID1, and for simplicity purpose, i have chosen two disks
Now you can start partitioning the /dev/md0 as a regular disk fdisk /dev/md0
and you can proceed with the regular partitioning Don’t forget:
mkfs.ext4 /dev/md0
And now if we check /proc/mdstat again:
and TRA, sure enough, we have a raid device
Last but not least, wee need to make a configuration file and this is very easy :
let’s redirect this to
And now when the system boots i will auto create that device
Now, you can mount this drive and start creating some data
If you want to simulate a disk failure :
Simulate a Disk Failure: To simulate a disk failure, you can mark one of the disks as faulty using the
mdadm --fail
command. For example, to mark/dev/sdb1
as faulty in the/dev/md0
array, you can use the following command:
Check the RAID Array: After simulating the disk failure, you can check the status of the RAID array with the
cat /proc/mdstat
command:
This command will show the status of all active RAID arrays on your system. You should see that /dev/sdb1
is marked as faulty (F).
Remove the Faulty Disk: After marking the disk as faulty, you need to remove it from the array using the
mdadm --remove
command. For example, to remove/dev/sdb1
from the/dev/md0
array, you can use the following command:
Re-add the Disk: To recover the disk, you need to add it back to the RAID array using the
mdadm --add
command. For example, to add/dev/sdb1
back to the/dev/md0
array, you can use the following command:
This command will add /dev/sdb1
back to the /dev/md0
array, and the data will start to be mirrored to the disk.
Summary:
The cool thing about RAID, we can unplug these drivers out and put them in another system, and we could use the mdadm --assemble
sudo mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1
Last updated