How to Setup a Raid1/Mirror using mdadm on Linux System

This guide describes how to set up mdadm with a raid1 or also known as mirror. Then the filesystem is added and monitored.

1. Install mdadm:

Make sure you have mdadm installed on your system. You can do this by running the following command:

sudo apt-get install mdadm

2. Identify the disks:

Use the lsblk command to identify the disks you want to include in the Mirror array. Make a note of their device names (e.g., /dev/sda, /dev/sdb, etc.).

3. Create the RAID 1 array:

Run the following command to create the RAID 1 array:

sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda /dev/sdb

Replace /dev/sda and /dev/sdb with the actual device names of your disks. You can also adjust the RAID device name (/dev/md0) if desired.

4. Monitor the array creation:

You can monitor the progress of the RAID array creation by running the following command:

watch cat /proc/mdstat

This will display the current status of the array creation process. Once it shows that the array is "active" and in a "clean" state, you can proceed to the next step.

5. Create a file system:

Now, you need to create a file system on the RAID array. For example, to create an ext4 file system, run the following command:

sudo mkfs.ext4 /dev/md0

Replace /dev/md0 with the device name of your RAID array.

6. Mount the RAID array:

Create a directory where you want to mount the RAID array and then mount it using the following command:

sudo mkdir /mnt/raid
sudo mount /dev/md0 /mnt/raid

Adjust the mount point (/mnt/raid) as per your preference.

7. Update /etc/mdadm/mdadm.conf (optional):

You can optionally update the mdadm configuration file to ensure the RAID array is automatically assembled during system boot. Run the following command to update the file:

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

That's it! You have successfully set up a RAID 1 array using mdadm. The array will now provide data redundancy by mirroring the contents of the two disks. Remember to update the device names and mount points according to your specific configuration.