Mdraid

From Q
Revision as of 03:41, 14 November 2013 by Tgurr (talk | contribs)
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
# 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

fstab

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