Mdraid

From Q
Jump to navigation Jump to search

Prepare the hard drives

In this example we create a RAID just for storage, so we only have one Partition on each drive.

Code: GPT partition layout for RAID
/dev/sdb	2.7 TiB	FD00	Linux RAID
/dev/sdc	2.7 TiB	FD00	Linux RAID
# gdisk /dev/sdb

We leave 100M of free space on the end of the device, just to be on the safe side if we have to replace a drive and won't be able to get an identical one which has the exact same amount of sectors.

Code: gdisk commands
Command (? for help): p
Disk /dev/sdb: 5860533168 sectors, 2.7 TiB
[...]

n
1
enter
-100M
fd00

p
w
Y


Create the RAID array

RAID 1

# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1


RAID 5

# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd[b-d]1


Checking the progress

# cat /proc/mdstat
# mdadm --detail /dev/md0
Note: Don't be scared when you see [UU_], initially the raid is created in a degraded state, when the process is completed it should show [UUU].
# mdadm --examine /dev/sdb1


Create the file system

Useful for calculating the options: http://uclibc.org/~aldot/mkfs_stride.html


RAID 1

Nothing special here besides specifying the block size to be sure it's using 4096.

# mkfs.ext4 -b 4096 /dev/md0


RAID 5

  • chunk size = 512KiB (mdadm --detail /dev/md0 | grep "Chunk Size")
  • block size = 4KiB (recommended for large files, and most of time)
  • stride = chunk / block here 512KiB / 4KiB = 128
  • stripe-width = stride * ( (n disks in raid5) - 1 ) here: 128 * ( (3) - 1 ) = 256
# mkfs.ext4 -b 4096 -E stride=128,stripe-width=256 /dev/md0


Label

# tune2fs -L raid /dev/md0


Free space reserved for root

Warning: Don't do this to partitions containing a linux os, only to plain storage partitions.
# tune2fs -m 0 /dev/md0


fstab

# blkid
Code: /etc/fstab
UUID=b036ad79-939f-d4ae-e2c0-2f3f5c2e7087	/mnt/raid	ext4	defaults,noatime	0 2


Update /etc/mdadm.conf

# mdadm --detail --scan >> /etc/mdadm.conf
Code: /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=host:0 UUID=b036ad79:939fd4ae:e2c02f3f:5c2e7087
MAILADDR admin@mail.local


Mount

# mkdir -p /mnt/raid
# mount /mnt/raid


Enable mdadm.service

# systemctl enable mdadm.service