Migrating from single disk to RAID5.
Situation
I have 1 HDD with data on it, and two new, empty HDDs. All 3 disks have the same size (10TB).
- Data: SDC
- New: SDE
- New: SDF
I want to go for a RAID5 using all 3 HDDs, without losing data. For this to work, the idea is to:
- Create a 3 disk RAID5 with the two new HDD SDE and SDF. One drive will be marked as missing.
- Copy data from existing disk SDC to RAID5
- Add HDD SDC to RAID5 as the missing drive
- Have a RAID 5 with 3 disks: SDC, SDE, SDF and the old data from SDC on it
Pre-requisites
Install mdmadm
apt-get update apt-get install mdadm
Create RAID5
mdadm --create /dev/md0 --level=5 --raid-devices=3 missing /dev/sde1 /dev/sdf1
This starts the RAID5 creation process. To see the current status
cat /proc/mdstat
Two drives SDF and SDE are working, one (SDC) is missing: [_UU]. The RAID5 is now ready. To use it, format it. I am using ext4
mkfs.ext4 /dev/md0
Capacity of the MD0 Raid5 is 20 TB
Copy files
With the RAID5 available and a file system created, I can start to copy the files from my HDD SDC to md0. This will take a while.
rsync -av /mnt/sdc/ /mnt/md0
Add disk to RAID5
After copying the files from to md0, I can add the HDD SDC to the RAID5 as the missing disk. Currently, there is partition with an ext4 filesystem on the old HDD. This can be deleted, as the data is already on md0. Create the partition using parted /dev/sdc
parted -s -a optimal /dev/sdc mklabel gpt
Next step is to add the now empty SDC to the RAID5 md0. Reminder: currently the RAID5 is active with 3 HDDs and one missing: [_UU].
Add SDC as the missing one to md0:
mdadm --add /dev/md0 /dev/sdc1
To see the current progress, look at /proc/mdstat.
cat /proc/mdstat
The new disk is now added as the missing one in the 3 disk RAID5. Syncing all the data will take hours. The initial estimate is close to 22 hours.
After the sync is done, all three HDDs will be shown as [UUU]
Capacity of the RAID5 is 20 TB.
0 Comments