MDADM - Common Commands

MDADM - Common Commands

1. Create a new RAID array

Create (mdadm —create) is used to create a new array:

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

or using the compact notation:

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

2. /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:

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

or on debian

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

3. 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):

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

and now we can remove it:

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

This can be done in a single step using:

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

4. Add a disk to an existing array

We can add a new disk to an array (replacing a failed one probably):

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

5. Verifying the status of the RAID arrays

We can check the status of the arrays on the system with:

1
cat /proc/mdstat

or

1
mdadm --detail /dev/md0

The output of this command will look like:

1
2
3
4
5
6
7
8
9
10
cat /proc/mdstat
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:

1
watch cat /proc/mdstat

6. 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:

1
2
mdadm --stop /dev/md0
mdadm --remove /dev/md0

and finally we can even delete the superblock from the individual drives:

1
mdadm --zero-superblock /dev/sda

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:

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

(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).

    • Related Articles

    • MDADM - Monitor Mode with Email

      You can run mdadm as a daemon by using the follow-monitor mode. If needed, that will make mdadm send email alerts to the system administrator when arrays encounter errors or fail. Also, follow mode can be used to trigger contingency commands if a ...
    • StorCLI Common Commands

      Information for general use: /cx bzw. /vx stands for the Controller/Virtual Drive Number. /ex bzw. /sx stands for the Enclosure/Slot ID. Firmware Update sudo storcli /cx download file=/path/to/firmware.rom Information on the Controller and ...
    • MegaCli Common Commands

      General Parameters   Adapter parameter -aN   The parameter -aN (where N is a number starting with zero or the string ALL) specifies the adapter ID. If you have only one controller it’s safe to use ALL instead of a specific ID, but you’re encouraged ...
    • Install Windows Server 2008/2012 over an Existing RAID Array

      How to install Windows Server on an existing RAID array greater than 2TB in size Why is this a problem? When installing Windows on UEFI-based PC's with RAID arrays you must partition your hard drives using GPT. Traditional MBR-type drives are limited ...
    • Setup Ubuntu 14.04.5 LTS Server with Software Raid1 for OS. (Video)

      The attached video will demonstrate a complete Ubuntu 14.04.5 LTS Server setup with the following.   Legacy Bios Mode.  240 GB Raid 1 - 2 X 240 GB SSD - OS drive 800 GB Raid 0 - 2 X 400 GB SSD - SCRATCH   The video is approximately 6 Minutes and ...