Linux Administrator

Mdadm Usages to Manage Software Raid Arrays

mdadm-usages
mm
Written by Santosh Prasad

Mdadm is a tool which is used to manage software RAID arrays. In the past raidtools was the tool we have used for this. This article will show the most common usage of mdadm to manage software raid arrays. I believe that you have a good understanding of software RAID and Linux. I will just explain the commands line usage of mdadm. In below example I used RAID1, but you can use any RAID level the Linux Kernel driver supports.

Mdadm Usage

Follow the below mdadm usage to manage software RAID arrays.

1. Create New RAID Array

Follow the below command to create a new RAID array.

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

Or with compact notation:

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

2. /etc/mdadm.conf

/etc/mdadm.conf (for CentOS/RHEL) or /etc/mdadm/mdadm.conf (for debian) is the main configuration file for mdadm. You can add the RAID arrays after creating it into this file.

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

On Debian

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

3. Remove Disk From Array

You can not remove the disk directly from the RAID array, unless it is failed, First you need to fail it if the drive is already in failed state then this step is not needed.

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

Once failed you can remove it using below command.

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

You can also do this just single step using below command.

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

4. Add New Disk To Existing Array

You can add a new disk to an array using below command.

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

5. Check the RAID Arrays Status

You can verify the status of the arrays on the system using below command.

# cat /proc/mdstat
Or
# mdadm --detail /dev/md0

You will get some output like below:

# 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]

In the above example you can see the both drives are used and working fine –U. If there is any failed drive it will indicate with F.

while monitoring the status of a RAID rebuild operation using watch can be useful.
# watch cat /proc/mdstat

6. Stop and Delete RAID Array

If you want to remove RAID array completely first you have to stop it and then remove it as shown below.

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

And finally you can even delete the superblock from the individual drives using below command.

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

Above command 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 lots of mdadm usage for each type of RAID level, You can use the manual page or help if you need more details on its usage.

# man mdadm
# mdadm --help
Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment