How to resize linux RAID array?

How to resize Linux MD RAID array?

Linux MD, also known as the Multiple Device , is a software RAID (Redundant Array of Independent Disks) system used in Linux. It allows you to create virtual devices by combining multiple physical devices, such as hard drives or partitions, into a single array. This array can provide redundancy, improve performance, or both, depending on the RAID level used.

You don’t need hardware RAID controllers to have RAID on any of you Linux machines. I, for example, run my own NAS with a 4GB Raspberry Pi 5 with 4 2.5″ drives attached via SATA HAT.

MD allows you not only to create an array from scratch, but also add new drives to existing arrays. In my case, a few days ago I extended my array from RAID5 3x 2TB Seagate Barracuda, to RAID5 4x of the same drives. If you will ever want to to expand your MD array and add more disks, here is a tutorial.

Backup and connect new disks

It’s not that backup of data from the array is strictly required, but you know, shit happens, and in the next steps you will rewrite every sector of all the drives. Better be safe and sorry. Connect new drive and identify it by running

lsblk
result of lsblk

What you see above is the result of lsblk after I extended it with the /dev/sdd. Sorry, but I figured out I will create this tutorial after doing so. Originally sdd would have a few partitions from a different setup.

Wipe, add to existing array and rebuild

As mentioned above, I used a drive from a different setup that was part of RAID array on my legacy Dell R620 with PERC H710 Mini. It already contained RAID partition and I decided it’s a good idea to wipe it.

sudo wipefs -a /dev/sdd

After disk is clean, it’s time to add it to the md0 array

mdadm --add /dev/md0 /dev/sdd

And rebuild the RAID array.

mdadm --grow /dev/md0 --raid-devices=4

This is the most time consuming part of the process. In my case, switching from 3 x 2TB to 4 x 2TB took around 20 hours! It really, really, really takes a long time to reshape the array and reallocate every block of data. So, give it time. The only good thing is that during this time drive is fully usable and process happens in the background.

You can monitor the progress by running

cat /proc/mdstat
example result of mdstat

One more time, I make a screenshot AFTER resizing the array, so you won’t see the progress output.

Resize the filesystem

When array rebuild will finish, you might notice that something is still wrong. Take a look at the screenshot

too small size of RAID array

lsblk still reports that the md0 has a size of 3.6TB while with four 2TB drives in RAID 5 it should be 5.4TB. It’s not a bug. Array has 5.4TB, but file system on it only 3.6TB. We have to resize the file system to take the whole array.

sudo resize2fs /dev/mdX

And done! Linux MD RAID 5 was extended with additional drive and it fully operational!


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *