2

Two external hard drives (USB powered) are initially connected to a Raspberry Pi 4B via the two USB 3.0 ports and they have the following block ids: /dev/sda, /dev/sdb. I used mdadm to create a RADI0 configuration, however, at least once in a day, one of the drives get disconnected (probably). What results is a different id such as /dev/sdc or /dev/sdd.

For testing purposes, I removed the RAID0 configuration and timed how long the block name persists. While simply formatting the hard drive with mkfs.ext4, the /dev/sda device disappeared for some time and reappeared as /dev/sdc.

Restarting the Pi again restores the original ids to the drives.

Initially:

pi@naspi:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk 
└─sda1        8:1    0 465.8G  0 part 
sdb           8:16   0 465.8G  0 disk 
└─sdb1        8:17   0 465.8G  0 part

Changes to: (sdb changes to sdc)

pi@naspi:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk 
└─sda1        8:1    0 465.8G  0 part 
sdc           8:16   0 465.8G  0 disk 
└─sdc1        8:17   0 465.8G  0 part

How can I fix this without restarting the Pi every time this happens? I do not even know why this is occurring.

(owing to this problem, I can never set up a RAID0 configuration and then share that over my local network as a SAMBA server)

NovoBook
  • 21
  • 2

2 Answers2

1

Two USB-powered HDDs connected directly to the Pi 4 are ought to be underpowered, you can only get 1.2A from USB, which is 600 mA per HDDs. Most of external HDDs I've seen require 800-1000 mA to work properly.

HDD resets due to unvervoltage is what makes them cycle through device names, but I'll hazard a guess that even if you switch to persistent device names, RAID software will not be happy about devices being randomly reset.

You may want to power your disks separately, or use something similar to this to tweak the Pi USB power limits.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
0

I'm actually not a RAID user, but I was a little bit bothered by the way this issue is ignored in man mdadm, since it is sure to be a common one.

The base block device names in /dev are not persistent, as you have realized. There are, however, a number of ways of using a persistent label that should work in this context. I notice in this U&L post both UUIDs and disk by-id links should work.

UUIDs are associated with filesystem partitions and usually assigned when they are created; if not they can be easily added. In your case this is not so helpful if you need the actual block device.

Disk ids are symbolic link labels in the /dev/disk/by-id directory and they are based on the device serial number, so should be persistent. Here's a Pi with just an SD card in it:

16:21:42root@treehouse>ls -l /dev/disk/by-id
total 0
lrwxrwxrwx 1 root root 13 Aug  2 21:21 mmc-SC32G_0xa51e3b9e -> ../../mmcblk0
lrwxrwxrwx 1 root root 15 Aug  2 21:21 mmc-SC32G_0xa51e3b9e-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 15 Aug  2 21:21 mmc-SC32G_0xa51e3b9e-part2 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 15 Aug  2 21:21 mmc-SC32G_0xa51e3b9e-part3 -> ../../mmcblk0p3

Notice the first one (/dev/disk/by-id/mmc-SC32G_0xa51e3b9e) points to the device, /dev/mmcblk0, the others are partitions on it. Since these are symbolic links, they are identical to what they point to.

You can do this kind of thing manually with udev configurations, but there is no need here (it's actually done by udev already).

goldilocks
  • 60,325
  • 17
  • 117
  • 234