3

I have available a single USB 2.0 port and a single USB 3.0 port and would like to set up two HDDs (both USB 3.0) in RAID1.

Not entirely sure how mirroring works, but was wondering if there was some way I could configure the drive connected to the USB 3.0 port to serve as a 'primary' drive of sorts that would be prioritized for 'initial' writes/reads in order to maximize performance, with any data being copied to the drive connected to the USB 2.0 interface.

Any ideas or suggestions are welcome. Ideally the solution would work for an OS compatible with the raspberry pi 4, however, I would be interested to learn of any other solutions as well.

  • The reading speed limit imposed by USB 2 caps out at about 8 MB/sec for USB2, and 20 MB/sec for USB3; writes will be worse. – K7AAY Aug 6 at 23:53
5

As you have a hardware limitation with 2 separate USB technologies:

  • USB2.0 has a maximum signalling rate of 480Mbps
  • USB3.x has a maximum signalling rate of 5120Mbps (5.0 Gbps)

setting up the RAID-1 using mdadm (multi device administrator) will have some draw-backs.

Option 1: Add hardware.

Add a USB 3.x port splitter / USB 3.x HUB and connect both HDDs to the HUB and the HUB to the USB 3.x port of the Pi therefore lowering their individual maximum theoretical transfer rate to 2560 Mbps (5120/2) instead of hooking one up to the USB2 port and the other to the USB3 as that would lower the maximum theoretical transfer rate of both to just 480Mbps.¹

Option 2: Live with some difference in speed.²

OK, so you don't have the time, money nor physical space to put a USB HUB and a Pi and 2 HDDs in this solution:
As there is no such thing as "Primary" and "Secondary" in RAID (any version) but only JBOD combined into one, you could use the write-mostly option of mdadm to circumvent some of the disparities.

This option will designate one of the HDDs as "slow" and all reads will come from the fast one but all writes will still wait for the slow one. (so only half of the benefits of the USB 3.0 disk)

Setting up the RAID:

All following commands need to be executed as root or with sudo.

Let's suppose that the first HDD comes up as /dev/sdc and the second one as /dev/sdd execute the following command to create a software RAID called md0 with RAID Level 1 using 2 HDDs:

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdc /dev/sdd

Only if you use option #2, you should add --write-mostly before the slow drive (sdd taken as example) and use the following command instead of the one above (hover over it with your mouse to unhide it to avoid any confusing which to use):

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdc --write-mostly /dev/sdd

Now we have to create a file system on the newly created /dev/md0 software RAID:

mkfs.ext4 -F /dev/md0

Now we're going to mount this space in /mnt (substitute this if you need to mount this somewhere else)

mkdir --parents /mnt/md0

And edit your fstab to include this mount at every boot (add the second line at the end of your fstab):

nano /etc/fstab
/dev/md0  /mnt/md0 ext4 defaults 0 2

Ctrl+X Y Enter to save and exit.

Now reboot to make it active or type to following command without rebooting:

mount /dev/md0 /mnt/md0

Note 1: The weakest link in the chain dictates the overall speed as 2 HDDs become one. :-(
Note 2: Thanks to fra-san and Stephen Kitt for pointing me in the right direction for the second option!
Note 3: For more info on mdadm type man mdadm on the pi itself and read it (all of it even the stuff you think you'll never need like re-assembling RAIDs after a fail...) ;-)
Note 4: A RAID is not a substiture for backups! ;-P

  • (hi! Fabby) Using USB for hard disks or even wifi is never as stable or comparable to having them via other SATA/PCI/whatever. USB does not scale and does not sustain high speeds for long. The point of doing RAID over USB is...strange. I got myself a ARM board with a SATA interface in the SoC, when had the need for doing some backups in a cheap medium. – Rui F Ribeiro Aug 8 at 12:13
  • I agree @RuiFRibeiro but it's what OP wants, so let's give him the best we can do. – Fabby Aug 8 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.