Growing linux RAID

I finally took the plunge and grew the RAID 1 and RAID 5 arrays on my Ubuntu NAS box to include the 2 new drives I got in March.

First off I partitioned the new drives to match the existing 3 by copying the setup of one of the original drives

sudo sfdisk -d /dev/sda > partitions.sda

editing the /dev/sda references to the relevant new drives (ie /dev/sde) and then set the partitions for each new drive

sudo sfdisk /dev/sde < partitions.sde

Next up was adding the new partitions to the existing RAID arrays

sudo mdadm –add /dev/md0 /dev/sdb1
sudo mdadm –add /dev/md0 /dev/sde1
sudo mdadm –add /dev/md1 /dev/sdb2
sudo mdadm –add /dev/md1 /dev/sde2

Then, fingers crossed, and grow the arrays

sudo mdadm –grow /dev/md0 –raid-devices=5
sudo mdadm –grow /dev/md1 –raid-devices=5

My /dev/md0 is a 100MB RAID 1 for /boot so that grew within seconds.  I did have to set the boot flags on the 2 new drives though to make them bootable – I used GParted which makes it a simple few clicks to do this.

/dev/md1 is a RAID 5 of the remaining space on the 1TB drives so this took a while to grow – 20 hours was the original estimate.  It seems the default settings need tweaking to improve the grow time, I used

echo 8192 >> /sys/block/md3/md/stripe_cache_size
echo 30000 >> /sys/block/md3/md/sync_speed_min
echo 200000 >> /sys/block/md3/md/sync_speed_max

though I had problems running these to start with as I kept getting permission errors when sudoing the commands. The solution was to

sudo bash

to get a root terminal and then the commands worked – at that point I had about 10 hours left which reduced to about 6 hours.

While the partitions were growing I updated /etc/mdadm/mdadm.conf to reflect the new number of devices in each array.  What I didn’t do, though, was update my initramfs to reflect my updates to mdadam.conf.  I should have run

sudo update-initramfs -u

but because I didn’t when I rebooted I got dumped into an initramfs prompt as it couldn’t find /dev/md1 (it was still looking for just 3 devices).  I spent a while trying to sort out a bootable USB linux install so I could fix this but turns out at the prompt I just needed to assemble my arrays and exit to continue to boot into Ubuntu

mdadm –assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm –assemble /dev/md1 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2 /dev/sde2

Now that everything was grown and I had a system that rebooted probably all that was left to do was to grow the actual filesystem on my RAID 5 array.  After my problems with initramfs I had hooked up a CD drive and had a Ubuntu Live CD so I booted into that, assembled my array (as above) and then ran

sudo fsck.ext3 /dev/md1
sudo resize2fs /dev/md1

This took a while but was a lot quicker than the RAID grow.

So, after a couple of days and  a little fun with initramfs I now have twice as much storage on my NAS box.

I gleaned most of this from:
Linux RAID Wiki
Ferg’s Gaff