A friend of mine asked about the benefits of software RAID versus hardware RAID in Linux, and I proceeded to voice my support for the former. It was then brought up that online resizing was one of her concerns, and I set about to figure out how to do just that. These instructions were crafted in a CentOS 5 virtual machine, and come with no warranty or guarantee of any sort; I put them here on the off chance that they might help someone.
First, I started by adding four additional SCSI drives to my CentOS 5 virtual machine. I then booted the VM up, and partitioned the disks, creating one partition that encompassed the entire drive and setting its type to “fd”:
for i in a b c d ; do echo "; ; fd ;" | sfdisk /dev/sd$i ; doneThen I created the new RAID5 array with four devices, none of which should be kept as spares:
mdadm --create /dev/md0 --spare-devices=0 --level=5 --raid-devices=4 /dev/sd{a,b,c,d}1Third, create a physical volume for LVM to use:
pvcreate /dev/md0After that, I made a volume group:
vgcreate vg0 /dev/md0Then I made a logical volume in that group using all free physical extents:
lvcreate --extents=100%VG --name=storage vg0Sixth, slap a file system on that guy:
mke2fs -j /dev/vg0/storageMount it, put some data on it, and enjoy.
After you’ve been using the array for a while (or, after it’s finished resyncing if you’re just following along at home), you add some new drives to the machine that you want to add to the array. I shut my VM down, added some additional virtual disks to it, and powered it back up; your steps would presumably be somewhat similar. After the system came back up, I added the new drives like so.
Partition them as with the other drives in the set:
for i in e f ; do sfdisk -d /dev/sda | sfdisk /dev/sd$i ; doneAdd them to the RAID array:
mdadm --add /dev/md0 /dev/sd{e,f}1Expand the array to encompass all the disks (note that this will probably take a while, so you might want to do it overnight):
mdadm --grow --raid-devices=6 /dev/md0Expand the LVM physical volume to include the new space:
pvresize /dev/md0Then expand the logical volume as well:
lvresize --extents=100%VG /dev/vg0/storageFinally, grow the file system:
resize2fs /dev/vg0/storage
With the exception of powering down to add the new drives, nothing had to be brought offline, and if your storage controller supports the hot-adding of devices then you may not even have to that (though the scope of doing so is beyond this tutorial, since I don’t have ready access to such hardware).
Hope that helps, and please let me know if you see any inconsistencies or run into any problems!