How to add a new disk to RAID5
I have a RAID5 consisting of three 10TB HDDs. This RAID5 has a total capacity of 20 TB.
I bought a new 10 TB HDD that I want to use to extend the RAID5: 4 HDDs with a total capacity of 30 TB. The file system on md0 is ext4. Currently, the RAID5 disks are sdc1, sdf1 and sde1. The additional disk is sdd1.
cat /proc/mdstat
The RAID5 is formatted with ext4 and available as md0.
mount
Steps
- Prepare new disk
- Add disk to RAID
- Grow RAID
- Extend ext4 files system.
Prepare new disk
First start with the preparation of the new disk. The disk is /dev/sdd and needs to have a partition. I use parted for this. First, create a label of type gpt.
parted -s -a optimal /dev/sdd mklabel gpt
Next is to create the partition using parted. This time, I am using the interface.
parted /dev/sdd
Add disk to RAID
The RAID is a software RAID on Linux, therefore mdadm is used to control the raid. To add a new disk, option –add is used and the raid and new disk are passed as parameters.
mdadm --add /dev/md0 /dev/sdd1
The result of the operation can be seen in mdstat.
cat /poc/mdstat
The new disk is added as a spare device. The (S) behind sdd1 means spare device. In case a device would fail, the spare device will take over automatically and a RAID rebuild will be triggered. This gives me less trouble in case a device fails, as I won’t have to do anything, but it won’t give me more space. The RAID5 is still at 20 TB.
Grow RAID
To make the RAID5 aware of the new disk and that it should be used for data storage, the RAID must be informed to use the new HDD using the grow command.
mdadm --grow --raid-devices=4 /dev/md0
The command informs the RAID that there are now 4 HDDs to be used, instead of 3. This command will trigger a RAID rebuild, as the information must be distributed to the HDDs.
This process will take some time. To learn how to increase the speed the sync, see my other blog about this topic.
The RAID5 consists now of 4 HDD, all working [UUUU]. The size of the RAID is still 20 TB. This is because the md0 has capacity of 30 TB, but the ext4 filesystem is still configured to make use of 20 TB.
Resize ext4 filesystem
To be able to use the 30TB available on the RAID5, you need to resize the file system. First, run an integrity check.
e2fsck -f /dev/md0
After the e2fsck ended without errors, the file system can be extended. This is done by using the tool resize2fs.
resize2fs /dev/md0
After resize2fs completes (can take a while), the size available is now 30TB:
mount /dev/md0 /mnt/md0/
12 Comments
Terrance · September 30, 2020 at 16:19
Woke up this morning to one of my 5 drives in my RAID 5 offline. I really need to get around to making sure all cables have locks on them and don’t slide out. Well, the drive is fine but for the life of me I was having a slight issue getting it back. I made the mistake of adding /dev/sdg and not /dev/sdg1 back to the array. Your instructions with the parted part is what I was missing. Thank you for great instructions!
waheed · October 27, 2020 at 10:59
by extending the RAID5 drive is the data safe in the main drive
Tobias Hofmann · October 27, 2020 at 21:44
When you extend the RAID, the data won’t be lost. The parity information is reallocated, this is a safe operation (as long as a HDD is not failing or power is lost)
Miroslav Kravec · December 10, 2021 at 19:09
What happens if power is lost during growing?
Tobias Hofmann · December 13, 2021 at 11:47
If a power lost occurs while growing the RAID, chances are very good that you have a severe problem (data lost).
https://raid.wiki.kernel.org/index.php/Growing
“To allow recovery after unexpected power failure, an additional option –backup-file= can be specified”
Yaniv · December 6, 2020 at 17:21
can i use different drive sizes when creating an array?
Tobias Hofmann · December 8, 2020 at 20:35
Hi Yaniv,
depends on the RAID type. RAID0: yes. For a RAID5 the disks/partitions need to have the same size.
Hikari · January 8, 2021 at 00:25
Nice tutorial, tnx!
I’m planning to build an array and considering buying 4 HDs now and 2 more later. This is what I needed to know.
This is also the 1st tutorial I see teaching how to create raid partitions using parted! All I’ve read use fdisk, which is limited to MBR, which is limited to 2TB!
MrG · March 20, 2022 at 19:24
I followed the nstructions, but when i get to the mount line I get an error of mount point doesnt exist. any suggestions? trying to find info on that error hasnt been easy or helpful. thanks in advance.
Tobias Hofmann · March 22, 2022 at 15:15
The command mount /dev/md0 /mnt/md0/ means to mount device md0 to directory /mnt/md0. The directory / location /mnt/md0 must exist. It is up to you to create a directroy and define where to mount your raid to.
jsd · April 14, 2022 at 18:34
just followed this guide to add a new disk to my ancient RAID5 and it worked like a charm. cheers!
David · December 28, 2022 at 03:14
Out of curiosity, I just tried running e2fsck on my RAID-5 array mounted as md0. It came back with the following messages:
====================================
$ e2fsck -f /dev/md0
e2fsck 1.46.5 (30-Dec-2021)
/dev/md0 is mounted.
WARNING!!! The filesystem is mounted. If you continue you ***WILL*** cause ***SEVERE*** filesystem damage.
Do you really want to continue?
====================================
Obviously I chose “NO”. But it raises the question: in your tutorial you don’t mention unmounting the RAID before running e2fsck. Is it necessary to unmount at some point before proceeding?