Posted in RHCE

CentOS + RAID with mdadm

March 12, 2007 - 2 comments

RHCE exam requires you to be able to create a RAID array on a running system, as well as with the installer.

I won’t explain here how to deal with the installer as it’s pretty easy.

1. create the partitions

Using fdisk or else
Set the ID type to “fd” (Linux RAID autodetect)

Say we got here /dev/hda2 and /dev/hdb2

2. create the RAID array with the first drive only

mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/hda2 missing

That’s my way of dealing with the creation of an array. You can obviously create the array with the 2 drives now.

3. Formatting the new array in ext3

mke2fs -j -c /dev/md0

-j for ext3
-c for check

4. Adding the other drive to the array

mdadm –add /dev/md0 /dev/hdb2

You should hear the drives working. They are actually synching
Type : cat /proc/mdstat to see what is actually happening.

5. Edit fstab

Edit /etc/fstab

Add a line to get the array mounting when the system boots

/dev/md0 /raid ext3 defaults 0 2

Comments

BC

February 16, 2009 - 4:40

Would this recipe work if one of those drives contains the OS?

In other words, is it possible to create a RAID-1 setup on an existing Centos5 system?

I’ve created the RAID array (with one disk in it) using your recipe but am stuck on how to load the ‘regular’ disk’s contents into the array. If I simply mdadm –add /dev/md0 /dev/sda I get:
mdadm: Cannot open /dev/sda: Device or resource busy
I guess that makes sense because the partitions in /dev/sda aren’t of type fd; they’re regular Linux partitions.
Would changing those partitions to fd first and then attempting to add them to the array work?

Ovidiu

March 1, 2010 - 6:04

How to destroy the array:
umount /dev/md0 to umount the array

mdadm –stop /dev/md0 to shut down the array
mdadm –remove /dev/md0 to remove the array
mdadm –zero-superblock /dev/sda for each drive of stopped array

Please complete or correct me if something wrong

Leave Comment

Please consider visiting the partners below if you enjoyed this article :

If this post saved you time and money, please consider checking my Amazon wishlist.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.