How to Set Up Software RAID 1

mdadm is used to manage software RAID. Install mdadm package with

apt install mdadm

To set up RAID 1 (mirror), you need 2 drives or partitions of the same size

Setup Partition

Create a partition with the following commands on both the drives used for RAID 1.

parted /dev/sdX mklabel gpt
parted /dev/sdX mkpart primary ext4 0% 100%
parted /dev/sdX set 1 raid on
parted /dev/sdX print

Replace /dev/sdX with device name of the drive you will be using for the RAID.

Create RAID 1

To create a RAID 1 mirror, use the following command

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

In the above command, replace /dev/md0 with the device name of the RAID array you need. If your system already has a raid array with this name, use another name, for example: /dev/md1.

/dev/sdb1 and /dev/sdc1 = replace these with the device name of the drives you will be using for the RAID 1

To see the raid status, use the command

cat /proc/mdstat

To find details, use the command:

mdadm --detail /dev/md0

Formatting the RAID drive

Once you created a RAID array, you need to format it with the command

mkfs.ext4 /dev/mdX

/dev/mdX = replace it with the actual device name used while creating the RAID array.

mkfs.ext4 will format the drive with EXT4 file system. To use other supported file systems replace mkfs.ext4 with other available file system types. For example mkfs.xfs

Mount the Drive

To mount the drive, use the following commands

mkdir /backup
mount /dev/md0 /backup

This will mount /dev/md0 as /backup. Change the mount point and device name as needed.

Auto Assemble RAID on the boot

To ensure the array is reassembled automatically at boot, update the mdadm configuration file:

mdadm --detail --scan

Add entry for the RAID array in file /etc/mdadm/mdadm.conf

Update the initramfs:

update-initramfs -u

Make the Drive auto-mount

To automount the drive on boot, edit /etc/fstab

vi /etc/fstab

Add the following line

/dev/md0 /backup ext4 defaults 0 2

Verify it is mounting properly with the command

mount -a

Back to RAID

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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