Using a RAID 1 is a good idea to make your data redundant and to take a first step to securing your data against loss. It protects you from a hardware breakdown of single complonents. Even if one of your hard disks fail will you be able to keep on working without data loss.
The article shows you how to set-up a RAID 1 system on a Raspberry Pi with two hard drives.
- Raspberry Pi (the article uses a Raspberry Pi 4)
- Two hard drives. Ideally with USB 3. If you have SATA drives can you purchase adapters to USB for little money
- Power supply with sufficient power. I am using the official power supply from the Raspberry Pi
Set-up the RAID
The RAID system will be created using the software MDADM. This is how to install it.
sudo apt-get install mdadm
If your hard drives are not plugged in yet, do it now and reboot then.
After the reboot, let's check if the hard drives are recognized by the system and if they are proberly mounted
In my case that looks like this here
sda and sdb are the two 500GB hard drives. Under mmcblk0 is the SSD card of the Raspberry Pi, which is mounted while booting.
I am going to remove any existing partitions (sda1 and sdb1) on the two hard drives first. If you have more than one partition on the drive and you want to remove it, just repeat the steps shown here by counting up to rm2, rm3 etc.
sudo parted /dev/sda "rm 1"
sudo parted /dev/sdb "rm 1"
Once you have erased all partitions just call lsblk again and check the result
As a next step we will create new partition tables on the hard drives. Mine are relatively small. Therefore I am going to use the msdos version.
sudo parted /dev/sda "mklabel msdos"
sudo parted /dev/sdb "mklabel msdos"
After the creation of the partition tables can we create the actual partitions.
sudo parted /dev/sda "mkpart primary ext4 1M -1"
sudo parted /dev/sdb "mkpart primary ext4 1M -1"
To complete the set-up of the hard drives will we tell the system that these two drives are supposed to work as a RAID 1
sudo parted /dev/sda "set 1 raid on"
sudo parted /dev/sdb "set 1 raid on"
Let's check if it all worked out until now.
sudo parted -s /dev/sda print
sudo parted -s /dev/sdb print
Looks fine. The size is correct and the drive is flagged as raid.
Enough preparation. Now the RAID will be created. I am using the name md0 and it shall be RAID level 1 on the hard drives sda1 and sdb1.
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
Final check with lsblk.
md0 is created under both hard drives.
From here on can you handle the RAID as an ordinary hard drive. And as such it needs to be formatted before you can store data on it.
sudo mkfs -t ext4 /dev/md0
The formatting may take a while depending on the size of your hard drives. With the two commands below can you check the status of the RAID
sudo mdadm --detail /dev/md0
The last step we need to do is to tell the Raspberry Pi to mount the RAID always on start up of your system. To do so, create a directory to mount the drive to and mount the md0.
sudo mkdir /media/cloudraid
sudo mount /dev/md0 /media/cloudraid
To make sure that happens always during start-up do you need to edit the File System Tab
sudo nano /etc/fstab
Add the last line shown here at the bottom of the File System Tab. Take extreme caution to type everything correctly. If you mess it up here, your system might not work anymore.
Zum Überprüfen rebooten wir den Raspberry Pi nun und gehen dann nochmal in die Konsole in der wir mit lsblk überprüfen, was dort vor sich geht.
The RAID 1 does not give you total data safety. It will only protect you from loosing data if one of the drives dies. A situation where both drives are damaged e.g. in a fire or flood will lead to a total loss of data. Make sure to properly back-up your data regularly to a physically separate place.
We will create our own cloud using Nextcloud.