Linux RAID Mdadm Cheat Sheet

Linux RAID Mdadm Cheat Sheet

Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays; in the past raidtools was the tool we have used for this. This cheat sheet will show the most common usages of mdadm to manage software raid arrays; it assumes you have a good understanding of software RAID and Linux in general, and it will just explain the commands line usage of mdadm. The examples bellow use RAID1, but they can be adapted for any RAID level the Linux kernel driver supports.

1. Create a new RAID array

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

 

or using the compact notation:

 

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:

or on debian

 

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

 

and now we can remove it:

 

This can be done in a single step using:

 

4. Add a disk to an existing array

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

 

5. Verifying the status of the RAID arrays

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

 

 

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:

 

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:

 

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

 

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:

 

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

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
How to Clear RAM Memory Cache, Buffer and Swap Space on Linux
Viewed 1844 times since Mon, Nov 23, 2020
10 Linux DIG Command Examples for DNS Lookup
Viewed 10671 times since Sun, Sep 30, 2018
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting
Viewed 14846 times since Wed, May 30, 2018
12 Linux Rsync Options in Linux Explained
Viewed 11458 times since Wed, Oct 31, 2018
HowTo: Find Out Hard Disk Specs / Details on Linux
Viewed 2741 times since Mon, Jan 28, 2019
RHEL: GPT/MBR partition tables (using disks larger than 2 TiB)
Viewed 11738 times since Sun, May 27, 2018
Install OpenVPN On CentOS / RHEL 7
Viewed 2544 times since Fri, May 15, 2020
Monitoring bezpieczeństwa Linux: integracja auditd + OSSEC cz. I
Viewed 1973 times since Fri, Apr 5, 2019
RHCS6: Extend an existing Logical Volume / GFS2 filesystem
Viewed 2711 times since Sun, Jun 3, 2018
20 IPtables Examples For New SysAdmins
Viewed 1782 times since Fri, May 15, 2020