expanding a raid 1 array in ubuntu

Ive been using RAID1 with mdadm for imaging servers for a while and it has been very reliable, but recently ran out of space. The 2 disks are 160Gb and I wanted to replace them with 400Gb disks, without having to muck about with copying files etc. Heres how to do it:

This is done on ubuntu dapper server, but I doubt it wil change between distros, so it will also work on {insert your distro here} with no (or very little) modification.

Swap disks

Remove one disk, replace with a bigger one.

I didnt want to risk hot-swapping the (sata) disks, but it may be possible, so powered off, then replaced one sata disk with a larger one. Fire up and mdadm will complain that it is running degraded. This is fine for now. Next we partition the new disk, and add this to the array.

sudo fdisk /dev/sda #replace sda with the disk you replaced
create a new primary partition, then change the type to "fd" or "linux raid autodetect"
press "w" to write changes

Now add it to the array (replace md0 and sda1 with your array and new partition)

sudo mdadm /dev/md0 --add /dev/sda1 

Now wait for it to resync

watch cat /proc/mdstat 

Once that has resynchronised, do the same with the next disk (in this case sdb1), and wait for that to resync. Now the fun part:

Resize the array

mdadm -G /dev/md0 -z max

This expands the array to the max size available. Now if you run mdadm --detail /dev/md0 you will see it shows the new size. Next we need to resize the filesystem:

Resize the filesystem

I used XFS, so growing is easy:

xfs_growfs /mountpoint

Remember that it wants the mountpoint, not the device - so this can be done while users are working.

For standard ext3 you can use  ext2online (i have not tested this on a raid array, but it works fine on LVM)

ext2online /dev/md0