Table of Contents

Using mdadm to create a Software RAID in Linux

Part of Linux

Installation

In Debian:

sudo apt get install mdadm

Partition Disks for mdadm usage

You can use:

sudo mdadm -E /dev/sd[b-c]

to check if the devices are part of a RAID / super-block is found.

Drive Partitioning for RAID:

sudo fdisk /dev/sdX

To create the partition, input the following values in order. Each Input should be followed by a confirmation (ENTER)

ValueDescription
nNew primary Partition
PDefine as Primary Partition
1Partition Number
(ENTER)Confirm Default Starting Block
(ENTER)Confirm Default End Block
tChoose partitions type
fdPartition type: Linux Raid auto
wWrite Changes

Useful Options for fdisk

ValueDescription
dDelete selected partition
pPrint partitions information
LList available types of partitions

Don't forget to repeat the steps for all disks you using on the RAID.

Creating a RAID 1

sudo mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
ValueDescription
–createCreate a new RAID
/dev/md0Using /dev/md0
–level=mirrorRaid as Mirror
–raid-devices=2Use 2 devices
/dev/sd[b-c]1The devices sdb1 and sdc1

Creating File System on a RAID Device

Use mkfs to create a ext4 File System with:

sudo mkfs.ext4 /dev/md0

Automount RAID on boot

Edit your fstab to auto-mount your RAID on boot:

sudo nano /etc/fstab

Eg:

/dev/md0  /mnt/md0  ext4  defaults,nofail 0 0

To make sure that the array is reassembled automatically at boot, adjust your /etc/mdadm/mdadm.conf:

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

Uncomment - if necessary - your array on /etc/mdadm/mdadm.conf by removing the Starting “#”:

sudo nano /etc/mdadm/mdadm.conf

Update the initramfs again so that the early boot process does not try to bring an unavailable array online:

sudo update-initramfs -u

Check Raid Status

You can use the following commands to check the status of your RAID:

sudo mdadm -E /dev/sd[b-c]1
sudo mdadm --detail /dev/md0