Step1: Install mdadm
we’ll use the mdadm utility. You can install it by
sudo yum install mdadm
Step2: Check the disks connected and available on the system
We use the lsblk tools.
lsblk
This should give you a list of all hard drives on the system.
Or
ls -l /dev | grep sd
sudo mdadm --examine /dev/sd[a-c]
If the HHD is larger than 2TB, you need to change the disk label to gpt
sudo parted /dev/sda
(parted) print
(parted) mklabel gpt
(parted) print
Then use the fdisk tools to partition the HDD
sudo fdisk /dev/sda
Follow the below instructions for creating partitions.
§ Press ‘n‘ for creating a new partition.
§ Next select the partition number as 1.
§ Give the default value by just pressing the two times Enter key.
§ Next press ‘P‘ to print the defined partition.
Create Partitions Follow below instructions for creating Linux raid auto on partitions.
§ Press lower letter (L) ‘l‘ to list all available types.
§ Type ‘t‘ to choose the partitions.
§ Choose the Linux raid (it comes as a number in the list) and press Enter to apply.
§ Then again use ‘P‘ to print the changes that we have made.
§ Use ‘w‘ to write the changes.
Check the disk and see the partition.
lsblk
Note: Follow the same to create a partition on other drives.
After creating partitions, verify all the drivers are correctly defined for RAID using the following command.
sudo mdadm --examine /dev/sd[a-c]
sudo mdadm --examine /dev/sd[a-c]1
Step5: Creating RAID md Devices
Step5-1: Now create md device (i.e. /dev/md0)
sudo mdadm -C /dev/md0 -l raid0 -n 3 /dev/sd[a-c]1
sudo mdadm --create /dev/md0 --level=stripe --raid-devices=3 /dev/sd[a-c]1
§ -C – create
§ -l – level
§ -n – No of raid-devices
Now verify the status of RAID Level, Devices and Array used, with the help of following series of commands as shown.
sudo cat /proc/mdstat
Verify RAID Level
sudo mdadm -E /dev/sd[b-c]1
Verify RAID Device
sudo mdadm --detail /dev/md0
Verify RAID Array
Step5-2: Assigning RAID Devices to Filesystem
Create an ext4 filesystem for a RAID device /dev/md0 and mount it under /dev/raid0.
sudo mkfs.ext4 /dev/md0
Now create a mount point directory (i.e. /scratch) and mount the device /dev/md0 under it.
sudo mkdir /scratch
sudo mount /dev/md0 /scratch/
Check the disk and see the partition.
lsblk
Step5-2: Create an fstab entry in /etc/fstab file.
sudo vim /etc/fstab
Add the following entry as described.
/dev/md0 /scratch ext4 defaults 0 0
Run mount ‘-a‘ to check if there is any error in fstab entry.
sudo mount -av
Step6: Saving RAID Configurations
14. Finally, save the raid configuration to one of the file to keep the configurations for future use. Again we use ‘mdadm’ command with ‘-s‘ (scan) and ‘-v‘ (verbose) options as shown.
sudo mdadm -E -s -v >> mdadm.conf
sudo mdadm --detail --scan --verbose >> mdadm.conf
cat mdadm.conf