This guide asumes you are creating a RAID from new (not already in use) disks. So I will format the full disk in a single partition. As usual, you may need to adapt device names and partition sizes to your setup, I’m just copy pasting from my terminal as a note for myself in the future.
Create a new partition table, as I’m going to use 3TB disks I will use a GPT partition table because DOS partition tables don’t support parititions bigger than 2TB.
$ parted /dev/sdc mklabel gpt
Now I have to create a partition using the full size of the disk.
$ parted -a optimal /dev/sdc mkpart primary 0% 3000GB
And set the raid flag on it, otherwise mdadm will not recognise the partition as a member of an array.
$ parted /dev/sdc set 1 raid on
Repeat in the second drive
$ parted /dev/sdd mklabel gpt $ parted -a optimal /dev/sdd mkpart primary 0% 3000GB $ parted /dev/sdd set 1 raid on
Now I can create the array, this is the most basic setup, I could add spare devices in case one fails, but I don’t have a spare device available.
$ mdadm --create --verbose /dev/md2 --level=mirror --raid-devices=2 /dev/sdc1 /dev/sdd1
Check it’s created and resyncing.
$ cat /proc/mdstat
Even if the array is being rebuild it is already fully functional and you can use it safely, the first thing to do is to format the array, I’m going to use ext4 for it.
$ mkfs.ext4 /dev/md2
mkfs has finished, I can mount my
/dev/md2 array as if it was a normal device, for example:
$ mount -t ext4 /dev/md2 /mnt
If you want your array to start automatically on system startup, add it to
Ask mdadm for the details of your new array
$ sudo mdadm --examine --scan ARRAY /dev/md2 UUID=8dc92785:7c0616c8:fecdba62:0dcb047a ARRAY /dev/md1 UUID=fb123aed:0146ba91:a4d2adc2:26fd5302
In this case
/dev/md1 is an array which I had previously configured, and
/dev/md2 is the new one, add to
/etc/mdadm/mdadm.conf any line not present in the config file.