One Hundred Hellos - Blog

Growing a raid5 array - 06 October 2006

Grow a raid5 array from 3 disks to 4.

mdadm - lvm(2) - evm - extfs

A- Growing a raid5 directly
get mdadm 2.5.2 or above
confir kernel >2.6.17

first create 4 devices in vmware. /dev/sd[bdce]1
mdadm --create --verbose /dev/md0 -l5 -n3 /dev/sdb1 /dev/sdc1 /dev/sdd1
# how big does the backup file need to be?
mdadm --grow /dev/md0 -n4 --backup-file=/tmp/raidbackup
mdadm -a /dev/md0 /dev/sde1

Then redo this with a filesystem on /dev/md0, or better ext3fs over lvm over /dev/md0

B- Alternatively using multiple raid5 pv's we can simply grow each pv independantly:
* pvmove /dev/md3 # Move all data off of /dev/md3
* vgreduce vg /dev/md3 # Remove /dev/md3 from the volume group
* pvremove /dev/md3 # Remove the LVM signature from /dev/md3
* mdadm --stop /dev/md3 # Stop the array
* mdadm --zero-superblock /dev/md3 # Remove the md signature from the disk
* mdadm --create /dev/md3 --level=5 --raid-devices=4 /dev/hda3 /dev/hdc3 /dev/hde3 /dev/hdg3 # Create the new array
* pvcreate /dev/md3 # Prepare /dev/md3 for LVM use
* vgextend vg /dev/md3 # Add /dev/md3 into the array

---- found this enabling note---
For those now reading this, you can actually expand a raid 5 array with mdadm for software based raid in linux. At least as of kernel 2.6.17 and mdadm 2.5.2 it is possible. One easy way to stest this is to create 4 files with dd, I created 4 100MB files named raidfile[1-4]. Next, use losetup to set them up as loop back devices, I used loop[0-3]. To create the initial array do:
mdadm --create --verbose /dev/md0 -l5 -n3 /dev/loop0 /dev/loop1 /dev/loop2
The array should now be initializing, when it is finished, increase the number of raid devices in the array by issuing the command:
mdadm --grow /dev/md0 -n4 --backup-file=/tmp/raidbackup
This part requires a backup file in case power is lost during the reordering of data, this backup file has to be used to assemble the raid array in that case.
Next, to add the other drive to the array use:
mdadm -a /dev/md0 /dev/loop4
the new drive will then be added to the array with no data lose hopefully. During my testing it has worked flawlessly so far, but as for using it on a production box its probably not recommended unless you have backups. You do keep backups correct?