Creating RAID in Linux

Here I will show you how to build a simple RAID configuration using 2 hard disks. We will be creating a mirror RAID configuration. You are most welcome to use your own RAID level since the procedure is the same. Before we proceed, please ensure that your disks are visible in the OS using fdisk command.

# fdisk -l

And your output should look something like this:

Disk /dev/sdd: 500118192 sectors, 238G
Logical sector size: 512
Disk identifier (GUID): 78d162d7-f425-49e7-a4c5-09eb12d95b77
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 500118158
Number Start (sector) End (sector) Size Code Name
1 2048 500118158 238G 0700
Disk /dev/sde: 500118192 sectors, 238G
Logical sector size: 512
Disk identifier (GUID): 78d164f7-f425-21e7-a4c5-09eb75d95b77
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 500118158
Number Start (sector) End (sector) Size Code Name
1 2048 500118158 238G 0700
 
Now we run the command to create the disk array:
 
# mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdd /dev/sde
 
Confirm the array creation.
 
RAID creation completion will be confirmed by:
 
mdadm: array /dev/md0 started
 
Confirm that the array is created using the following command:
 
# ll /dev/md0
 
The output is something like this:
 
brw-rw----. 1 root disk 9, 0 Mar 27 15:09 /dev/md0
 
Here we can see that there is a block device created.
 
You can check RAID using mdstat command as well:
 
# cat /proc/mdstat
 
The output will be similar to this:
 
Personalities : [raid1]
md0 : active raid1 sdd[0] sde[0]
998244352 blocks super 1.2 [2/2] [UU]
unused devices: <none>
 
Now we create a filesystem on our newly created RAID device and label it DATA:
 
mkfs.xfs -L DATA /dev/mod0
 
Use the mdadm command to display how your RAID is built:
 
# mdadm --detail --scan
 
You will be presented with the following output:
 
ARRAY /dev/md0 metadata=1.2 name=server203.sefnet.local:0 UUID=98c3b7ca:994e7f12:42458ba3:3898dc13
 
This information is needed to automatically create the array on the system reboot. We need to forward and append this information to the mdadm.conf file:
 
# mdadm --detail --scan >> /etc/mdadm.conf
 
Since this is a software array, the array can be stopped using the following command:
 
# mdadm --stop /dev/md0
mdadm: stopped /dev/md0
 
To start it again, we need to read the information from the mdadm.conf configuration file using the following command:
 
# mdadm --assemble --scan
mdadm: /dev/md0 has been started with 2 drives.
 
Now we can proceed to mount the filesystem:
 
# mount /dev/md0 /Data
 
To ensure that the filesystem is mounted every time after the reboot, add it in the /etc/fstab file.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.