mdadm notes

Notes on mdadm.

Useful commands

Get basic info on RAID status:

cat /proc/mdstat

Read config:

cat /etc/mdadm.conf

Get detailed info, e.g. for /dev/md1 array:

mdadm --detail /dev/md1

Assemble an array

To assemble /dev/md1 array from disk partitions /dev/sda1 and /dev/sdb1:

mdadm --assemble /dev/md1 /dev/sda1 /dev/sdb1

Write config to /etc/mdadm.conf

When you’ve assembled your arrays, you can add the config to /etc/mdadm.conf so that you can easily start the arrays in the future.

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

The arrays can now be assembled with the following command:

mdadm --assemble --scan

Adding a hot spare to an existing RAID1 array

Say we have /dev/sda and /dev/sdb in an array /dev/md1 and we want to add a blank disk as a hot spare.

Copy the partition table from /dev/sda to /dev/sdc:

Warning: Repartitioning a disk with sfdisk will destroy its data.

sfdisk -d /dev/sda | sfdisk /dev/sdc

Add the spare disk to the array:

mdadm --add /dev/md1 /dev/sdc1
mdadm --add /dev/md2 /dev/sdc2

(Two partitions participating in RAID1).

Check with mdadm --detail /dev/mdN where N is the array number. It should show two active devices and one spare.

E.g. In this example /dev/sdc1 and /dev/sdc2 are already partitioned:

me@pc ~ $ sudo mdadm --add /dev/md1 /dev/sdc1
mdadm: added /dev/sdc1
me@pc ~ $ sudo mdadm --add /dev/md2 /dev/sdc2
mdadm: added /dev/sdc2
me@pc ~ $ cat /proc/mdstat
Personalities : [raid1] 
md1 : active raid1 sdc1[2](S) sda1[3] sdb1[1]
      190272 blocks super 1.2 [2/2] [UU]
md2 : active raid1 sdc2[2](S) sda2[0] sdb2[1]
      488191168 blocks [2/2] [UU]
unused devices: <none>


Last modified: 15/07/2015 Tags:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top