MDADM Cheat Sheet

Create a new RAID array

Create (mdadm --create) is used to create a new array:
[codesyntax lang="bash"]

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb2

[/codesyntax]

or using the compact notation:
[codesyntax lang="bash"]

mdadm -Cv /dev/md0 -l1 -n2 /dev/sd[ab]1

[/codesyntax]

/etc/mdadm.conf

/etc/mdadm.conf or /etc/mdadm/mdadm.conf (on debian) is the main configuration file for mdadm. After we create our RAID arrays we add them to this file using:
[codesyntax lang="bash"]

mdadm --detail --scan >> /etc/mdadm.conf

[/codesyntax]

or on debian
[codesyntax lang="bash"]

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

[/codesyntax]

Remove a disk from an array

We can’t remove a disk directly from the array, unless it is failed, so we first have to fail it (if the drive it is failed this is normally already in failed state and this step is not needed):
[codesyntax lang="bash"]

mdadm --fail /dev/md0 /dev/sda1

[/codesyntax]

and now we can remove it:
[codesyntax lang="bash"]

mdadm --remove /dev/md0 /dev/sda1

[/codesyntax]

This can be done in a single step using:
[codesyntax lang="bash"]

mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

[/codesyntax]

Add a disk to an existing array

We can add a new disk to an array (replacing a failed one probably):
[codesyntax lang="bash"]

mdadm --add /dev/md0 /dev/sdb1

[/codesyntax]

Verifying the status of the RAID arrays

We can check the status of the arrays on the system with:
[codesyntax lang="bash"]

cat /proc/mdstat

[/codesyntax]

or

[codesyntax lang="bash"]

mdadm --detail /dev/md0

[/codesyntax]

The output of this command will look like:

[codesyntax lang="bash"]

cat /proc/mdstat

[/codesyntax]
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
104320 blocks [2/2] [UU]

md1 : active raid1 sdb3[1] sda3[0]
19542976 blocks [2/2] [UU]

md2 : active raid1 sdb4[1] sda4[0]
223504192 blocks [2/2] [UU]

here we can see both drives are used and working fine - U. A failed drive will show as F, while a degraded array will miss the second disk _

Note: while monitoring the status of a RAID rebuild operation using watch can be useful:
[codesyntax lang="bash"]

watch -n1 cat /proc/mdstat

[/codesyntax]

Checking a linux MD raid array

In this example my RAID array will be /dev/md0

[codesyntax lang="bash"]

cd /sys/block/md0/md
echo check >sync_action
watch -n1 cat /proc/mdstat

[/codesyntax]

OR:

[codesyntax lang="bash"]

/usr/share/mdadm/checkarray -a /dev/md0
watch -n1 cat /proc/mdstat

[/codesyntax]

Note: if you receive the following error message:

[codesyntax lang="bash"]

checkarray: W: array md0 in auto-read-only state, skipping...

[/codesyntax]

Then you should do this:
[codesyntax lang="bash"]

mdadm --readwrite /dev/md0

[/codesyntax]

Stop and delete a RAID array

If we want to completely remove a raid array we have to stop if first and then remove it:
[codesyntax lang="bash"]

mdadm --stop /dev/md0
mdadm --remove /dev/md0

[/codesyntax]

and finally we can even delete the superblock from the individual drives:
[codesyntax lang="bash"]

mdadm --zero-superblock /dev/sda

[/codesyntax]

Finally in using RAID1 arrays, where we create identical partitions on both drives this can be useful to copy the partitions from sda to sdb:
[codesyntax lang="bash"]

sfdisk -d /dev/sda | sfdisk /dev/sdb

[/codesyntax]

(this will dump the partition table of sda, removing completely the existing partitions on sdb, so be sure you want this before running this command, as it will not warn you at all).

There are many other usages of mdadm particular for each type of RAID level, and I would recommend to use the manual page (man mdadm) or the help (mdadm --help) if you need more details on its usage. Hopefully these quick examples will put you on the fast track with how mdadm works.

Source: This info is taken from here and here

Scrie si tu o vorbulita


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.