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.
Prerequisites
At the console, type:
An example of a failed array:
The next step is to partition the new drive for the raid array, using:
Now choose the following options:
Ok, your new drive is now ready to add to the array.
Now run:
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:
Now we use the e2fsck command to check the file system (will take around 10 minutes on a 1TB array):
Now run:
Once the expand is complete you can remount your array:
You should now have an expanded raid5 array, Please post any comments or suggestions.
In this simple guide I will be demonstrating the steps used to grow a raid5 array from 3 HDD's to 4.
Prerequisites
- 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
Check the current raid array
Examine the current raid5 array to ensure all HDD's are currently activeAt the console, type:
$cat /proc/mdstatThe output should be similar to the following:
md0 : active raid5 sdc1[0] sdd1[2] sdb1[1]Here we can see that all drives are active and part of the array.
1465151808 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
An example of a failed array:
md0 : active raid5 sdc1[0] (f) sdd1[2] sdb1[1]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.
1465151808 blocks level 5, 64k chunk, algorithm 2 [2/3] [_UU]
Partition the new HDD
Once you have added the new HDD to the machine, check its assignment:$cat /proc/diskstatsOutput:
8 65 sde1 168430629 1886732648 70507758 564062064As 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/sdeReplace "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 tableThe output of "p" should be similar to:
Device Boot Start End Blocks Id SystemMake sure the System type is set to "Linux raid autodetect". Once you are sure everything is correct press:
/dev/sde1 1 60801 488384001 fd Linux raid autodetect
"w" to write the changes to the partition tableIf 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.
Add the new HDD to the raid array
First off run:$sudo mdadm –add /dev/md0 /dev/sde1Replace "/dev/md0" with your current raid array and "sde1" with your new HDD. This informs mdadm of the new HDD
Now run:
$ sudo mdadm –grow /dev/md0 –raid-devices=4Replace "/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:
$cat /proc/mdstatTo speed up the growing of the array you can run the command:
$echo 25000 > /proc/sys/dev/raid/speed_limit_minFinally once the array has finished growing check:
$cat /proc/mdstatIt should look similar to the following:
md0 : active raid5 sdc1[0] sde1[3] sdd1[2] sdb1[1]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.
1465151808 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
Extend the file system onto the free space
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/md0Replace "/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/md0Once again replace "/dev/md0" with your raid array.
Now run:
$sudo resize2fs /dev/md0This 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/raidReplace "/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.