Helpful mdadm commands

root's picture

How to "fail" a disk in md:

# mdadm /dev/mdX -f /dev/[hs]dX

How to remove a disk from md array:

# mdadm /dev/mdX -r /dev/[hs]dX

How to add a disk in md array:

This command is used also to re-add a disk back into the array if was previously removed due to disk issues.
# mdadm /dev/mdX -a /dev/[hs]dX

How to refresh the mdadm configuration file:

# mdadm --examine --scan
# echo 'DEVICE disk' > /etc/mdadm.conf
# mdadm --detail --scan >> /etc/mdadm.conf

How to display the status of md:

# mdadm --detail /dev/mdX

How to create a mirror raid device with two active devices and no spare:

# mdadm --create --verbose /dev/md2 -l 1 -x 0 -n 2 /dev/sdb3 /dev/sdc3
If you do not have the second mirror at hand, you can put missing instead of any device. The md device will be created in degraded mode and you can attach the other disk later:
# mdadm --create --verbose /dev/md2 -l 1 -x 0 -n 2 /dev/sdb3 missing

How to stop (remove) a md raid device:

# mdadm --manage --stop /dev/md4
mdadm: stopped /dev/md4

How to start (assemble) a previously created raid device:

# mdadm --assemble /dev/md0
mdadm: /dev/md0 not identified in config file.
# mdadm --examine --scan
ARRAY /dev/md/0 metadata=1.2 UUID=9c97d:435:cc1:d0643 name=pluto:0
# echo "ARRAY /dev/md/0 metadata=1.2 UUID=9c97d:435:cc1:d0643 name=pluto:0" >> /etc/mdadm/mdadm.conf
# mdadm --assemble /dev/md0
mdadm: /dev/md0 has been started with 2 drives.

How to revert mdadm auto-read-only:

core:vbox# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active (auto-read-only) raid1 sda1[0] sdb1[1]
      256896 blocks [2/2] [UU]
unused devices: <none>
core:vbox# mdadm --readwrite /dev/md0

core:vbox# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[0] sdb1[1]
      256896 blocks [2/2] [UU]
unused devices: <none>

The option --readwrite from the example above works also when you have resync=PENDING.

root@pluto:~# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active (auto-read-only) raid1 dm-8[1] dm-7[0]
      209584000 blocks super 1.2 [2/2] [UU]
unused devices: <none>

How to resize a md device:

mdadm --grow --size=max /dev/md2

How to get details about a md device:

core:linux# mdadm --query --detail /dev/md0
        Version : 0.90
  Creation Time : Fri Nov 13 20:12:39 2009
     Raid Level : raid1
     Array Size : 256896 (250.92 MiB 263.06 MB)
  Used Dev Size : 256896 (250.92 MiB 263.06 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sat Dec 13 01:28:07 2014
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           UUID : 9c97d:435:cc1:d0643
         Events : 0.5174

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.