MDADM, Raid 5 and shutting down (getting mdadm errors before power off)


I have a newbie question. I have been getting errors on reboot with my software raid 5 (i use 4x2 TB drives). I created it with MDADM, it takes 6 to 8 hours to set up the 4th drive with parity.

When I shutdown, i see errors that drives have failed (just before shutdown) from mdadm. Then after reboot, my raid 5 is in auto/read-only and says it needs to rebuild again.

I’ve been googling around but I have not been successful in finding a solution so far. Is there a safe way to shutdown the raid 5 I guess, before the machines shuts down or reboots?

Any tips, links or info would be very helpful. Thanks everyone!

What’s cool is that i did
sudo mdadm --readwrite /dev/md0

and it went right back into active. However, how do I prevent the problem from occuring in the first place? I have not yet mounted the raid.

The problem that you are seeing is probably due to the gpios that enable the two usb/sata chips
Your problem is that the sata hat service drops them as it is shut down.

This is done in /usr/bin/rockpi-sata/ in the routine “disk_turn_off”. The two GPIOs, 26 and25 are set low, which disables the chips and drops them out of the system before a sync could be completed on the filesystem.

If you comment out those two set_mode (xx, GPIO.LOW) statements the driver chips will remain enabled until the system drops power. It should have completed all file operations well before that.

Please confirm which sata hat you are using?

Pcie or usb?

I am using USB I believe (this is the quad sata hat for Raspberry PI which has the USB adapter that needs to be plugged in).

Thank you @oket I will definitely try that!

I think the issue is solved now. Still sometimes at boot, only 2 drives light up. I have to reboot at least one more time or shutdown and restart for it to detect all 4 again. Once detected, the RAID automatically goes back to active. Not sure why that is. I have also followed all the steps to get the hdd serial numbers, not from the hat.

Rather than stop the power-down. I think a better way would be to unmount the software raid first and then power it down. I have it automounting on boot (following a novaspirittech youtube video). I just need to figure out how to unmount it before it executes that shutdown script. Any ideas?

Just add “mdadm --stop /dev/md0” in script

Thanks! The shutoff script seems to be a python script if I’m not mistaken. I’m not that familiar with python, but I see we can execute normal commands. I will try something like this:

from subprocess import call
call(['echo', 'mdadm --stop /dev/md0'])

Sure, go for it