I recommend reading my article Description of RAID types.
You can install mdadm in Ubuntu using the command:
sudo aptitude install mdadm
In CentOS:
sudo 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@ixnfo.com
MAILFROM mdadm@ixnfo.com
Restart the monitoring service:
service mdadm restart
You can configure some parameters by answering the questions with the command:
dpkg-reconfigure mdadm
When synchronizing and rebuilding the raid, some restrictions are used in kilobytes, you can see them by running the commands:
cat /proc/sys/dev/raid/speed_limit_min
cat /proc/sys/dev/raid/speed_limit_min
And change if necessary (I note that by increasing speed_limit_min you can adversely affect the operation of other important services in the system, if any, and for example for a backup server you can increase it a little):
echo 1000 > /proc/sys/dev/raid/speed_limit_min
echo 200000 > /proc/sys/dev/raid/speed_limit_max
See also my articles:
- How to fix the problem with mdadm disks
- Configuring Software RAID1 on a Running Ubuntu System
- Monitoring mdadm in Zabbix