On growing mdadm RAID5

There is a right way and there are wrong ways to add dri­ves to a RAID5 array with mdadm. Annoyingly, I chose one of the wrong ways last week when I went to increase the hard drive space in thevoid. Thankfully, my mis­take has proven more both­er­some and time con­sum­ing than harmful.

Starting out last week, thevoid had 4x 500GB dri­ves in an mdadm RAID5 con­fig­u­ra­tion: /dev/hde1, /dev/hdg1, /dev/sda1, /dev/sdb1. This had me sit­ting on 1.5TB of space with one drive worth of fail­abil­ity, which was prov­ing insuf­fi­cient. In order to resolve my space issues, I ordered 3x 500GB dri­ves and pro­ceeded to install them when the arrived: /dev/hdb, /dev/hdc, /dev/hdd.

In my haste to have more space, I pro­ceeded to add them to the array and grow it:

mdadm --manage /dev/md1 --add /dev/hdb
mdadm --manage /dev/md1 --add /dev/hdc
mdadm --manage /dev/md1 --add /dev/hdd
mdadm --grow /dev/md1 --raid-devices=7

This process then got to work and took about 3 – 4 days to com­plete. I assume the time was on account of most of the dri­ves being IDE dri­ves, many shar­ing chan­nels and there being an awful lot of space. Once the grow­ing process was com­plete, I merely needed to resize the ext3 par­ti­tion on the array:

resize2fs /dev/md1

This then took an hour or so and I was sit­ting on 3TB of total space. The only part of the process dur­ing which my drive was inac­ces­si­ble was when I had to turn off the com­puter to phys­i­cally install my IDE drives.

Everything is per­fect now, right? Wrong. Guess who for­got that you should par­ti­tion dri­ves before using them? That’s right, me. I really wanted to put a linux raid autode­tect par­ti­tion on each of the dri­ves before adding them to the array. Not that it really does much harm to add the dri­ves straight to the array but it’s poor form and it might pose prob­lems that I am not aware of in the future so, clearly, it’s a thing that should be fixed. Thankfully, being RAID5, my array is able to lose dri­ves and still be fine, thus allow­ing the solu­tion of fail­ing, remov­ing, par­ti­tion­ing and adding each of the new dri­ves back into the array:

mdadm --manage /dev/md1 --fail /dev/hdb
mdadm --manage /dev/md1 --remove /dev/hdb

par­tion /dev/hdb and then:

mdadm --manage /dev/md1 --add /dev/hdb1

now wait until the array has rebuilt itself:

cat /proc/mdstat

and repeat for the other dri­ves. Overall, it’s not hard but it’s annoy­ing and it does take about 1/2 to 2/3 of a day per drive to fix. Thankfully, though, now the endeavor is done and my array works cor­rectly with no lost data and min­i­mal down time. Hooray for soft­ware RAID and hav­ing 3TB in a sin­gle place.

Oh, and you don’t want to for­get to update /etc/mdadm.conf after every step of the process of you could have some poten­tial problems.

2 Responses to “On growing mdadm RAID5”

  1. Eph says:

    Ah!

    I wish I had read this a cou­ple of days ago. I just fin­ished grow­ing my RAID5 (2x1TB) with another drive. Have been impa­tient about the long process but finally, today, it fin­ished the rebuild.

    Before I was going to resize the RAID I thought I’d do a fdisk –l and then I noticed that also I for­got to add the Linux Raid Autodetect flag on the partition :(

    I fol­lowed your guide here and hope I (my data) will be OK, I’m sure it will.

    I rein­stalled the sys­tem the other day and really do appre­ci­ate the autode­tect of RAIDs so I would’t want it any other way. It’s prob­a­bly pos­si­ble to set the RAID up also with­out the flag but since I’m no linux guru I have no idea how to do it — do you know?

    Too bad there are sev­eral RAID HOWTOs out there that neglect to men­tion that you should set the Linux Raid Autodetect flag. The GROW HOWTO I fol­lowed did not and I didn’t really pay atten­tion to the fact that it should be par­ti­tioned before hand, even though I knew I should and intended to but for­got in my impa­tience of get­ting the larger disk space.

    Anywho, thanks for your mini-guide :)

  2. gwax says:

    Glad that I could help.

    FYI, if you for­get the Linux RAID Autodetect par­ti­tion type, any unmarked dri­ves will not be added to your array on reboot. I missed the flag on one of the dri­ves in my cur­rent RAID6 setup and every time that I rebooted, I had to man­u­ally re-add the miss­ing drive and rebuild the array. HOWTOs are, indeed, some­what sparse and I had rather a tough time track­ing down the prob­lem. My rebuilds are quick, RAID6 has extra redun­dancy, and Linux reboots are rare, though, so it took me a while to get fed up enough to actu­ally fix the problem.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

*