Set up Raid data storage

Now configure the two USB sticks as Raid1.

See for explanation.
We will all actions in a terminal window on the Raspberry Pi.
Additional software is needed for the intended Raid1 drive.
Run the following command: sudo apt-get install mdadm
N.b. This installs a large number of additional software packages; no idea why.

Connect both USB sticks to the Raspberry Pi and type of command: lsblk. Depending on where you have connected the USBs, you get sda, sdb, sdc or sdd as device name and a mountpoint in /media/pi.
(For the continuation I assume devices sda ​​and sdb.)
Now install new partitions on both USBs:

  • sudo fdisk /dev/sda
  • o
  • n
  • 4x Enter
  • w

Repeat this for /dev/sdb.

Perhaps the USBs are busy and the w (rite) does not work.
With command sudo reboot you can restart the Raspberry pi.
If you type command lsblk then you will see the just created sda1 and sdb1 partitions.
Now run the following command:
sudo mdadm –create –verbose /dev/md0 –level=mirror –raid-devices=2 /dev/sda1 /dev/sdb1
Check with the following command whether the raid is correctly created: cat /proc/mdstat
You will see for example: md0: active raid1 sdb1 [1] sda1 [0]

Run the following commands:

  • sudo -i
  • mdadm –detail –scan >> /etc/mdadm/mdadm.conf
  • exit
  • sudo mkfs.ext4 /dev/md0
  • sudo mkdir /mnt/raiddrive
  • sudo mount /dev/md0 /mnt/raiddrive

You can now check in WinSCP whether you can access the raid and possibly create a file. This is also a good time to make a backup of your SD card. In the next step, we will configure the mount of the raids at startup. If this configuration is incorrect, the Raspberry pi will no longer start.
Now run an umount command explicitly before you close the Raspberry pi: sudo umount /mnt/raiddrive. (This is only necessary after a manual mount.)

After the backup you open another terminal on the Raspberry Pi.

  • type command sudo blkid
  • Copy the UUID of /dev/md0
  • Type sudo nano/etc/fstab (or use Notepad++ from WinSCP)
  • Add at the end of the following line:
    UUID = /mnt/raiddrive ext4 defaults 0 0
  • Ctrl o + Ctrl X to save and exit nano.
  • Type: sudo reboot (to perform a restart)

If the Raspberry pi reboots successfully then the Raid drive will work.

Congratulations and on to the next chapter.

Previous pageNext page