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 :

root@k8snode:/home/touk# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda5  /dev/sdb  /dev/sdc  /dev/sdd

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!

root@k8snode:/home/touk# ls /dev/sd*
/dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdc1  /dev/sdd  /dev/sdd1

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:

root@k8snode:/home/touk# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      1046528 blocks super 1.2 [2/2] [UU]

unused devices: <none>

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 :

mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=k8snode:0 UUID=5e31cabf:b1c9a14f:85a0e135:642f10a4

let’s redirect this to

mdadm --detail --scan > /etc/mdadm.conf

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 :

  1. 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:

sudo mdadm /dev/md0 --fail /dev/sdb1
  1. Check the RAID Array: After simulating the disk failure, you can check the status of the RAID array with the cat /proc/mdstat command:

cat /proc/mdstat

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).

  1. 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:

sudo mdadm /dev/md0 --remove /dev/sdb1
  1. 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:

sudo mdadm /dev/md0 --add /dev/sdb1

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