The example below shows how to create a software RAID1 array on Debian systems. Disk partitions /dev/sda1 and /dev/sdc1 will be used as the members of the RAID array md0, which will be mounted on the /home partition.

Install the mdadm package

root@localhost:~# apt-get install mdadm

Create the RAID1 array

Create disk partitions with type 0xfd. Afterwards, do:

root@localhost:~# mdadm --zero-superblock /dev/sda /dev/sdc
root@localhost:~# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdc1

Note

If you have the two entire disks available, you can skip the partitioning. Just add the disk devices to the raid array (i.e. /dev/sda, /dev/sdc).

Create filesystem (i.e. ext4) on RAID1 block device (md0)

root@localhost:~# mkfs.ext4 /dev/md0

Add entry to /etc/fstab:

/dev/md0 /home ext4 noatime,rw 0 0

Create the mdadm config file:

root@localhost:~# mdadm --detail --scan /dev/md0 >> /etc/mdadm/mdadm.conf
DEVICE /dev/sda1 /dev/sdc1
ARRAY /dev/md0 devices=/dev/sda1,/dev/sdc1 level=1 num-devices=2 auto=yes

Note that the array is actually started by the mdadm-raid service or (either via mdadm -A -s or the mdrun commands). The RAID1 array should have been completed. You are done! {OK}

Root filesystem on RAID

If you intend to have your root partition on the RAID device remember to regenerate the initramfs:

update-initramfs -u

This is needed to embed the mdadm.conf file because the init process needs to know which arrays to assemble before trying to find the rootfs.

Query the RAID array

This step is optional. If you would like to gain more information about the RAID array, you can query its status as shown below.

root@localhost:~# mdadm --query --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Feb 24 14:29:34 2016
     Raid Level : raid1
     Array Size : 285092864 (271.89 GiB 291.94 GB)
  Used Dev Size : 285092864 (271.89 GiB 291.94 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

  Intent Bitmap : Internal

    Update Time : Fri Feb 26 15:30:42 2016
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : localhost:0  (local to host localhost)
           UUID : bc3c058d:56029657:fa438017:c0f2acf4
         Events : 2126

    Number   Major   Minor   RaidDevice State
       0       8        2        0      active sync   /dev/sda1
       1       8       18        1      active sync   /dev/sdc1


CategoryHardware | CategorySystemAdministration | CategoryRedundant: merge with other ?CategoryRaid pages