mdadm – utility for managing software RAID arrays

I recommend reading my article Description of RAID types.

You can install mdadm in Ubuntu using the command:

sudo aptitude install mdadm

In CentOS:

yum install mdadm

On the test I will collect RAID in Ubuntu 14.04, I immediately switch to the root user (hereinafter the commands will be similar for other operating systems):

sudo -i

In the beginning we’ll see the list of disks by commands (I have two unmounted identical sizes /dev/sdb and /dev/sdc):

fdisk -l
df -h
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

Let’s create RAID 1:

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

Check the status of the array and its components by:

cat /proc/mdstat
mdadm --detail /dev/md0
mdadm -E /dev/sdb
mdadm -E /dev/sdc

Create a file system:

mkfs.ext4 -F /dev/md0

To mount the created RAID to the current system, create a directory and mount it into it:

mkdir -p /mnt/md0
mount /dev/md0 /mnt/md0

Let’s see the details of RAID:

mdadm --verbose --detail --scan

Save the changes:

mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
update-initramfs -u
echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | tee -a /etc/fstab

Done, after rebooting the system, RAID will be automatically mounted.

To receive e-mail notifications about the RAID status, in the mdadm.conf configuration file, specify which address to send and from which (for mail to be sent to the system, for example, postfix should be installed):

MAILADDR email@example.com
MAILFROM mdadm@example.com

Restart the monitoring service:

service mdadm restart

You can configure some parameters by answering the questions with the command:

dpkg-reconfigure mdadm

See also:
How to fix the problem with mdadm disks
Configuring Software RAID1 on a Running Ubuntu System

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply