Mdraid: Difference between revisions

From Q
Jump to navigation Jump to search
Tgurr (talk | contribs)
No edit summary
Tgurr (talk | contribs)
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 12: Line 12:
{{Root|gdisk /dev/sdb}}
{{Root|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|
{{Code|gdisk commands|
Line 22: Line 23:
1
1
enter
enter
enter
-100M
fd00
fd00


Line 33: Line 34:


== Create the RAID array ==
== Create the RAID array ==


=== RAID 1 ===
=== RAID 1 ===


{{Root|mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1}}
{{Root|<nowiki>mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1</nowiki>}}
 


=== RAID 5===
=== RAID 5===


{{Root|mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1}}
{{Root|<nowiki>mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd[b-d]1</nowiki>}}
 


=== Checking the progress ===
=== Checking the progress ===
Line 46: Line 50:
{{Root|cat /proc/mdstat}}
{{Root|cat /proc/mdstat}}
{{Root|mdadm --detail /dev/md0}}
{{Root|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].}}
{{Root|mdadm --examine /dev/sdb1}}
{{Root|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.
{{Root|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
{{Root|<nowiki>mkfs.ext4 -b 4096 -E stride=128,stripe-width=256 /dev/md0</nowiki>}}
== Label ==
{{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|
<pre>
<pre>
UUID=b036ad79-939f-d4ae-e2c0-2f3f5c2e7087 /mnt/raid ext4 defaults
UUID=b036ad79-939f-d4ae-e2c0-2f3f5c2e7087 /mnt/raid ext4 defaults,noatime 0 2
</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 ==
{{Root|mkdir -p /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