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.
The RAID5 is formatted with ext4 and available as md0.
- 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.
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.
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.
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.
After resize2fs completes (can take a while), the size available is now 30TB:
mount /dev/md0 /mnt/md0/