Blog

Mdadm – Growing Raid5 Array (Ubuntu)

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

  • Mdadm running a raid5 array
  • Linux kernel > 2.6

Steps

  1. Check the current raid array
  2. Partition the new HDD
  3. Add the new HDD to the raid array
  4. 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 active

At the console, type:

$cat /proc/mdstat

The output should be similar to the following:

md0 : active raid5 sdc1[0] sdd1[2] sdb1[1]

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[0] (f) sdd1[2] sdb1[1]

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.

Partition the new HDD

Once you have added the new HDD to the machine, check its assignment:

$cat /proc/diskstats

Output:

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.

Add the new HDD to the raid 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

Now run:

$ 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:

$cat /proc/mdstat

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:

$cat /proc/mdstat

It should look similar to the following:

md0 : active raid5 sdc1[0] sde1[3] sdd1[2] sdb1[1]

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.

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/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.

Now run:

$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.



Discussion

  1. Arnie  March 16, 2012

    Thanks. Great article resulting in a bigger raid

  2. cg monroe  June 3, 2012

    Very clear and helpful instruction on how to do this. Here are a few minor additions that might help others:

    If you’re raid is mounted as something important to the system, e.g. as /home, it is best to go to single user mode (Grub / Recovery mode) prior to extending the file system.

    Adding the -p option to the resize2fs command will generate a percent done scale. It is nice to see that something is happening and how fast.

    Finally, if your RAID is getting up in the multi TB size, consider using ext4 or one of the alternative file system types. File system checking is VERY slow on the older ext2/3 and can take many hours if the file system is large. With ext4, checking my 6TB system took under 3 min. and extending the file system from 6 to 8 took 15 or so minutes.

Add a Comment

You must be logged in to post a comment.