How do I create Software RAID 1 arrays on Linux systems without using GUI tools or installer options? How do I setup RAID 1 array under Linux systems?
You need to install mdadm which is used to create, manage, and monitor Linux software MD (RAID) devices. RAID devices are virtual devices created from two or more real block devices. This allows multiple devices (typically disk drives or partitions) to be combined into a single device to hold (for example) a single filesystem. Some RAID levels include redundancy and can survive some degree of device failure.
Linux Support For Software RAID
Currently, Linux supports the following RAID levels (quoting from the man page):
- LINEAR
- RAID0 (striping)
- RAID1 (mirroring)
- RAID4
- RAID5
- RAID6
- RAID10
- MULTIPATH, and FAULTY.
MULTIPATH is not a Software RAID mechanism, but does involve multiple devices: each device is a path to one common physical storage device. FAULTY is also not true RAID, and it only involves one device. It provides a layer over a true device that can be used to inject faults.
Install mdadm
Type the following command under RHEL / CentOS / Fedora Linux:
# yum install mdadm
Type the following command under Debian / Ubuntu Linux:
# apt-get update && apt-get install mdadm
How Do I Create RAID1 Using mdadm?
Type the following command to create RAID1 using /dev/sdc1 and /dev/sdd1 (20GB size each). First run fdisk on /dev/sdc and /dev/sdd with "Software Raid" type i.e. type 0xfd:
# fdisk /dev/sdc
# fdisk /dev/sdd
See fdisk(8) man page to setup partition type. Do not format partition. Just create the same. Now, create RAID-1 as follows.
If the device contains a valid md superblock, the block is overwritten with zeros:
# mdadm --zero-superblock /dev/sdc /dev/sdd
Create RAID1 using /dev/sdc1 and /dev/sdd1
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdc1 /dev/sdd1
Format /dev/md0 as ext3:
# mkfs.ext3 /dev/md0
Mount /dev/md0
# mkdir /raid1
# mount /dev/md0 /raid1
# df -H
Edit /etc/fstab
Make sure RAID1 get mounted automatically. Edit /etc/fstab and append the following line:
/dev/md0 /raid1 ext3 noatime,rw 0 0
Save and close the file.
How Do I See RAID Array Building Progress and Current Status?
Type the following command:
# watch -n 2 cat /proc/mdstat
OR
# tail -f /proc/mdstat
Update /etc/mdadm.conf File
Update or edit /etc/mdadm/mdadm.conf or /etc/mdadm.conf (distro specific location) file as follows:
ARRAY /dev/md0 devices=/dev/sdc1,/dev/sdd1 level=1 num-devices=2 auto=yes
This config file lists which devices may be scanned to see if they contain MD super block, and gives identifying information (e.g. UUID) about known MD arrays. Please note that Linux kernel v2.6.xx above can use both /dev/mdX or /dev/md/XX names. You can also create partitions for /dev/md/XX as /dev/md/d1/p2.
How Do I Get Information On Existing Array?
Type the following command
# mdadm --query /dev/md0
This will find out if a given device is a raid array, or is part of one, and will provide brief information about the device.
References:
- See man pages: mdadm(8) and mdadm.conf(5)
- RAID 5 vs RAID 10: Recommended RAID For Safety and Performance
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 16 comments… read them below or add one }
Thanks for the article.
Very cool! \o/
Thanks for this tutorial. It was exactly the information I searched for and a great help.
This is a nice article. Unfortunately it does not seem to give complete information. I have followed the steps, and have a /dev/md0 created, but I can’t format it. I get an error from mkfs.ext3 saying “Device size reported to be zero.” When I do mdadm –query /dev/md0 I get the following response “/dev/md0: is an md device which is not active”. Googling these errors has not produced anything helpful.
use
mke2fs -f /dev/md0
then use the following command to re size the md
resize2fs /dev/md0
Please tell me the procedure to recover the disk if some disaster happens .
I got the following error,
mdadm: Cannot open /dev/sda1: Device or resource busy
Can any one help me? I am New to Linux
In the rescue mode, while all drives dismounted, I’ve successfully mirrored my /, /home , and /usr, Using mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sda1 /dev/sdb1.
But the system is unable to boot from md0( / ). I updated etc/fstabe before I proceed with array creation. Also made changes in grub.conf, but the system unable to boot successfully, during booting process it asks about file system check on md0, I used e2fsck command but there is no result.
two steps more, 1st is to create an initrd (initial ramdisk) with RAID1 module (/sbin/mkinitrd ./boot/grub/initrdname uname -r –preload raid1 –with=raid1 –fstab=/etc/fstab)
2nd step: resize2fs and fsck all md……
and it is bootable
thanks a lot…………………
Thank you very much for detailed tutorials. Your site is the best place for Linux beginners, average and even experts.
Hi, many thanks for this.
I got as far as creating my array using 2 HDDs (2TB each) already in the system. (fedora 14)
I create /dev/md1 mounted at /raid1. (md0 is the operating system array which I created when I set-up the system)
After I rebooted I could no longer mount/dev/md1 so I looked at “disk utility” and found the the raid array “degraded” and called /dev/md127 (which I CAN mount)
/cat /proc/mdstat : show that the array is only using one HDD: /dev/sdd[1]
First time this happened I started from the beginning but now that I’s happened again, I wonder how to repair the raid array.
Any help would be much appreciated.
Thanks
Hi,
Before rebooting your machine try to mount md1 into any mount-point, (don’t make changes into fstab file until you can successfully mount)
It may not mount because you have to resize md1 before you mount it.
First you have to add the second drive into the array then fsck and then resize..
After you done make changes into fstab file(if not done before)
Example:
mdadm –add /dev/md1 /dev/sdx (here sdx is the secondary drive, you need to add in the array because it is degraded)
after synched , first e2fsck /dev/md1
then resize2fs /dev/md1.
If there is any error accrued you need to do from beginning, if accorded kindly let me know.
Regards,
Owais Hyder
Sr.Technical Consultant
Synergy Computers (Pvt.) Ltd.
I was searching a way to make software RAID on my Redhat Linux Advanced Server 5.5 Machine and this article helps me a-lot. very warm thanx for the author.
A million thanks i was trying about 100 times everything went right except for the mdadm.conf file which i did not no what to do
and the /etc/fstab
Thanks for the article
again
Thank u very very much
Awesome, this doc definitely helps the failed partitioner on Fedora 16 installer (for software raid that you want unmounted during install). Thanks!!