Mdraid: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 34: | Line 34: | ||
== Create the RAID array == | == Create the RAID array == | ||
=== RAID 1 === | === RAID 1 === | ||
{{Root|<nowiki>mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1</nowiki>}} | {{Root|<nowiki>mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1</nowiki>}} | ||
=== RAID 5=== | === RAID 5=== | ||
{{Root|<nowiki>mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd[b-d]1</nowiki>}} | {{Root|<nowiki>mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd[b-d]1</nowiki>}} | ||
=== Checking the progress === | === Checking the progress === | ||
| Line 51: | Line 54: | ||
{{Root|mdadm --examine /dev/sdb1}} | {{Root|mdadm --examine /dev/sdb1}} | ||
== Create the file system == | == Create the file system == | ||
Useful for calculating the options: http://uclibc.org/~aldot/mkfs_stride.html | Useful for calculating the options: http://uclibc.org/~aldot/mkfs_stride.html | ||
=== RAID 1=== | === RAID 1=== | ||
| Line 61: | Line 66: | ||
{{Root|mkfs.ext4 -b 4096 /dev/md0}} | {{Root|mkfs.ext4 -b 4096 /dev/md0}} | ||
=== RAID 5=== | === RAID 5=== | ||
| Line 70: | Line 76: | ||
{{Root|<nowiki>mkfs.ext4 -b 4096 -E stride=128,stripe-width=256 /dev/md0</nowiki>}} | {{Root|<nowiki>mkfs.ext4 -b 4096 -E stride=128,stripe-width=256 /dev/md0</nowiki>}} | ||
== Label == | == Label == | ||
{{Root|tune2fs -L raid /dev/md0}} | {{Root|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.}} | |||
{{Root|tune2fs -m 0 /dev/md0}} | |||
== fstab == | == fstab == | ||
{{Root|blkid}} | |||
{{Code|/etc/fstab| | {{Code|/etc/fstab| | ||
| Line 81: | Line 97: | ||
</pre> | </pre> | ||
}} | }} | ||
== Update /etc/mdadm.conf == | |||
{{Root|mdadm --detail --scan >> /etc/mdadm.conf}} | |||
{{Code|/etc/mdadm.conf| | |||
<pre> | |||
ARRAY /dev/md0 metadata=1.2 name=host:0 UUID=b036ad79:939fd4ae:e2c02f3f:5c2e7087 | |||
MAILADDR admin@mail.local | |||
</pre> | |||
}} | |||
== Mount == | == Mount == | ||
{{Root|mkdir -p /mnt/raid}} | {{Root|mkdir -p /mnt/raid}} | ||
{{Root|mount /mnt/raid}} | {{Root|mount /mnt/raid}} | ||
== Enable mdadm.service == | |||
{{Root|systemctl enable mdadm.service}} | |||
Latest revision as of 21:29, 14 November 2013
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