Scenario:
I had two 1tb drives raided with mdadm level 1. I finally filled up my raid, and wanted to ultimatly add another 1tb to the raid. Therefore I wanted to change my raid to level 5, and add this third drive. As a result the raid should become 2tb in usable space. However I don’t have spare harddrive space avaiable to backup everything, to create a three drive level 5 raid. Basically what i’m saying, I had to make this change using live data.

After much research via google and linux irc channels no one seemed to give a straight answer about how to make a level 1 mdadm /dev/md# drive into a level 5 drive. I was advised not to do this because it was risky and because it wouldn’t work. Well thier right, it’s impossible, but there is a work around. Well guess what…… I did it, and it’s not that difficult. If you are confortable with linux it’s easy, you just need to understand the logic.

This tutorial will not tell you the specific commands, and what to type in. So if your not familar with basic linux commands your going to need some additional resources.

Required:

  • i used mdadm v2.6.9
  • be confortable with linux
  • have the balls to do this

Legend:

/dev/sda = 1tb harddrive
/dev/sdb = 1tb harddrive
/dev/sdc = 1tb harddrive

/dev/md0 = /dev/sda1 + /dev/sdb1
/dev/sdc = newly purchased drive

Logical Steps:

  1. physically add your third harddrive to your computer. (edit mdadm.conf if drive names changed)
  2. fdisk / mkfs.ext3 / mount your third drive to a temporary location such as /mnt/temp
  3. move all your /dev/md0 contents to wherever you mounted /dev/sdc1, then umount /dev/sdc1 if you wish
  4. comment out /dev/md0 in /etc/fstab
  5. stop /dev/md0
  6. rm /dev/md0
  7. delete mdadm.conf, or just rename it
  8. format / mkfs to clean out the drives /dev/sda and /dev/sdb
  9. mdadm –create /dev/md0 –level=5 –raid-devices=2 /dev/sda1 /dev/sdb1
  10. monitor /proc/mdstat    …. (cat /proc/mdstat), and wait for it to sync
  11. dont forget to mkfs.ext3 /dev/md0
  12. readd /dev/md0 to the /etc/fstab
  13. i rebooted just to make sure it would work
  14. remount /dev/sdc1 to your temporary location, and copy everything back onto your raid
  15. clean out /dev/sdc
  16. grow the /dev/md0 with /dev/sdc
  17. make sure mdadm.conf is correct
  18. Done

Problems / Answered Questions:

Raid would fail on boot
When i physically added the third drive into the computer my raid failed on boot, the drive names were rearraged. So i had to check the drives names and edit mdadm.conf

how much space does a two drive level 5 raid have, how does it work?
This question really irritated me because no one would give me a straight answer. Some said it’s not possible, while others said it would act if the third drive is failed, and others said drive two would be parity. Well the answer is the second drive will be a parity. For those who do not believe me check the screen shots below. So basically it”s a level 1 drive. Argue what you want with me, I don’t care. All i cared is that it would hold my my stuff, until i added the third drive.