Skip to content

mdadm

how to create raid 1 with one missing disk and add second disk later

format, create partitiontable, create partition, create filesystem

https://wiki.archlinux.org/title/Parted

parted /dev/sdc
mklabel gpt
mkpart primary ext4 0% 100% ((parted) mkpart part-type-or-part-label fs-type start end)
or
mkpart primary ext4 <1MiB or 100MiB> 100% ((parted) mkpart part-type-or-part-label fs-type start end) > Not tested yet if necessary to be able to match more disks of different manufactures
print

mdadm erstellen mit einer missing disk um im anschluss daten rüberzuschieben * https://arstechnica.com/civis/threads/mdadm-raid-1-with-existing-data.1136487/ * https://wiki.archlinux.org/title/RAID

sudo apt install mdadm

prepare disk

create the array

Danger

the missing drive is the one containing data

sdc1 = new empty sdrive

mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdc1 missing

(sdc1 is the new drive which is empty)

check the details, showing an array with 2 devices, 1 in use.

mdadm --detail /dev/md0
````

create the filesystem on raid array OR with parted
```sh
mkfs.ext4 /dev/md0
or
parted /dev/md0
mkpart primary ext4 0% 100%

mount the raid array

mount /dev/md0 /mnt/raid

mount the drive containing all of the data

mount /dev/sdb /mnt/extdisk

copy data to empty portion of the raid1 using whatever arguments for rsync you prefer

!!!

rsync -ahvP /media/tb1/ /media/raid1

unmount the drive containing the data (which is not part of the raid set)
sudo umount /media/tb1

## first create partitiontable and create filesystem on old one

add said drive to the array
sudo mdadm --add /dev/sda1

Obviously, substitute your drive naming scheme for the one's I've used, paying close attention to detail.

Wait for sync.....and mount on startup via fstab.

cat /proc/mdstat
Personalities : [raid1] 
md0 : active raid1 sda1[2] sdd1[0]
      976759936 blocks [2/1] [U_]
      [==>..................]  recovery = 10.3% (101263680/976759936) finish=134.6min speed=108370K/sec



## change sync speed limits
Syncing can take a while. If the machine is not needed for other tasks the speed limit can be increased.


```sh
cat /proc/mdstat
cat /proc/mdstat
 Personalities : [raid10]
 md127 : active raid10 sdd1[3] sdc1[2] sdb1[1] sda1[0]
     31251490816 blocks super 1.2 512K chunks 2 far-copies [4/4] [UUUU]
     [=>...................]  resync =  5.2% (1629533760/31251490816) finish=2071.7min speed=238293K/sec
     bitmap: 221/233 pages [884KB], 65536KB chunk
In the above example, it would seem the max speed is limited to approximately 238 M/sec.

change speed limit

# sysctl dev.raid.speed_limit_min
dev.raid.speed_limit_min = 1000
# sysctl dev.raid.speed_limit_max
dev.raid.speed_limit_max = 200000

```sh
set a new maximum speed of raid resyncing operations using sysctl:

# sysctl -w dev.raid.speed_limit_min=600000
# sysctl -w dev.raid.speed_limit_max=600000

Then check out the syncing speed and estimated finish time.

check status

cat /proc/mdstat
 Personalities : [raid10] 
 md127 : active raid10 sdd1[3] sdc1[2] sdb1[1] sda1[0]
     31251490816 blocks super 1.2 512K chunks 2 far-copies [4/4] [UUUU]
     [=>...................]  resync =  5.3% (1657016448/31251490816) finish=1234.9min speed=399407K/sec
     bitmap: 221/233 pages [884KB], 65536KB chunk 

setup notification

nano /etc/mdadm/mdadm.conf
MAILADDR root

Tip

use root instead of mail@domain.tld so the mail can be changed central in /etc/aliases

check if notification work and generate testfailure

mdadm --monitor --scan --oneshot --test

gives information about raid but cant remember why it should be checked when notification work

mdadm -D /dev/md0