Mdadm is used to create, manage, monitor, and maintain raid arrays.
In this simple guide I will be demonstrating the steps used to grow a raid5 array from 3 HDD’s to 4.
- Mdadm running a raid5 array
- Linux kernel > 2.6
- Check the current raid array
- Partition the new HDD
- Add the new HDD to the raid array
- Extend the file system onto the free space
Examine the current raid5 array to ensure all HDD’s are currently active
At the console, type:
The output should be similar to the following:
md0 : active raid5 sdc1 sdd1 sdb1 1465151808 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
Here we can see that all drives are active and part of the array.
An example of a failed array:
md0 : active raid5 sdc1 (f) sdd1 sdb1 1465151808 blocks level 5, 64k chunk, algorithm 2 [2/3] [_UU]
In this example we can see sdc1 has failed, this can be determined by the “(f)” after the HDD name and “[_UU]” instead of “[UU]” in the output. The failed drive will need to be replaced before you attempt to grow the array size.
Once you have added the new HDD to the machine, check its assignment:
8 65 sde1 168430629 1886732648 70507758 564062064
As you can see we have a new drive, referenced as “sde1″
The next step is to partition the new drive for the raid array, using:
$sudo FDISK /dev/sde
Replace “sde” with your new HDD
Now choose the following options:
Type "n" to add a new partition, use the default settings
Press "t" to change the partition type, now press "fd" to set the partition type to Linux raid autodetect
Press "p" to check the partition table
The output of “p” should be similar to:
Device Boot Start End Blocks Id System /dev/sde1 1 60801 488384001 fd Linux raid autodetect
Make sure the System type is set to “Linux raid autodetect”. Once you are sure everything is correct press:
"w" to write the changes to the partition table
If the system type wasn’t set to “Linux raid autodetect” then make sure you select “fd” in the “t” menu.
Ok, your new drive is now ready to add to the array.
First off run:
$sudo mdadm –add /dev/md0 /dev/sde1
Replace “/dev/md0″ with your current raid array and “sde1″ with your new HDD. This informs mdadm of the new HDD
$ sudo mdadm –grow /dev/md0 –raid-devices=4
Replace “/dev/md0″ with your current raid array.
This will tell mdadm to grow the current array onto our new HDD which was added before with the “mdadm -add” command.
While the array is growing (can take several hours) you can view the current status by running:
To speed up the growing of the array you can run the command:
$echo 25000 > /proc/sys/dev/raid/speed_limit_min
Finally once the array has finished growing check:
It should look similar to the following:
md0 : active raid5 sdc1 sde1 sdd1 sdb1 1465151808 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
As we can see all drives are active, from “[UUUU]“. The number of U’s being displayed is equal to the number of drives in your array, so if you grew it to 5 HDD’s it will display 5 U’s etc.
Now its time to move onto expanding the current file system onto the free room on the array. We will first need to unmount the current raid array using:
$sudo umount /dev/md0
Replace “/dev/md0″ with your raid array.
Now we use the e2fsck command to check the file system (will take around 10 minutes on a 1TB array):
$e2fsck -f /dev/md0
Once again replace “/dev/md0″ with your raid array.
$sudo resize2fs /dev/md0
This will expand the current file system onto the free space. (took around 15 minutes for 1 TB)
Once the expand is complete you can remount your array:
$sudo mount /dev/md0 /media/raid
Replace “/dev/md0″ with your raid array and “/media/raid” with the directory you wish to mount the file system into.
You should now have an expanded raid5 array, Please post any comments or suggestions.Share