Main Menu
  • Home
  • Services
    • Strategy
      • Technology Partner
      • UI / UX
      • Artificial Intelligence

      Core Technologies
      • PHP
      • JavaScript
      • Laravel
      • VueJs
      • AWS
    • Development
      • Software Development
      • Mobile App Development
      • Software Integration
      • Software Support (SLA)
      • Managed Hosting
      • Microsoft Access Databases
    • Industries
      • Manufacturing
      • Transport / Logistics
      • Finance
      • Retail & E-commerce
      • Government
      • Construction
      • Health
      • Insurance
      • Mining
  • Our Work
  • About
  • Blog

© 2020 Codium Pty Ltd.

Codium Logo Codium Logo
  • Services
    • Strategy
      • Technology Partner
      • UI / UX
      • Artificial Intelligence

      Core Technologies
      • PHP
      • JavaScript
      • Laravel
      • VueJs
      • AWS
    • Development
      • Software Development
      • Mobile App Development
      • Software Integration
      • Software Support (SLA)
      • Managed Hosting
      • Microsoft Access Databases
    • Industries
      • Manufacturing
      • Transport / Logistics
      • Finance
      • Retail & E-commerce
      • Government
      • Construction
      • Health
      • Insurance
      • Mining
  • Our Work
  • About
  • Blog

Mdadm - Growing Raid5 Array (Ubuntu)

23 Jun 2008, in

  • Blog
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.
Codium Logo
Codium Pty Ltd.
Ground Floor, 207 Greenhill Road
Eastwood, 5063
Adelaide, South Australia

Company

  • About us
  • Blog
  • Terms of Business
  • Customer Experience
  • Quality Policy
  • Security Policy
  • Privacy Policy

Services

  • Software Development
  • Mobile App Development
  • Support Services
  • Managed Hosting
  • Software Integration
  • Technology Partner
  • Microsoft Access

Support

  • Contact Us
  • Customer Feedback
  • Careers
  • Codium Remote Support

Socialise

© Codium Pty Ltd. All Rights Reserved.

Back Top