You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Raspberry Pi 4 : USB3 SSD Connected via USB3 Hub : BOOT Files Corrupted Following Reboot #4844
Files written to the FAT32 BOOT filesystem of a USB3 SSD connected via a USB3 hub sporadically get corrupted when followed immediately by a reboot. This issue does not occur when the SSD is connected directly to one of the Raspberry Pi 4 USB3 ports. This issue only occurs on the FAT32 BOOT filesystem, never on the EXT4 ROOT filesystem. A 'sync' command prior to the reboot does not eliminate the issue. This issue does not occur if the hub is connected to one of the Raspberry Pi 4 USB2 ports.
Steps to reproduce the behaviour
Test environment:
Raspbberry Pi 4B 4GB (revision 1.1 or 1.2)
SSD: Samsung EVO 860 or Corsair Neutron
SATA to USB3 adapter:
Asmedia-based (from 5 different manufacturers) [Bus 002 Device 003: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ASM1153 SATA 3Gb/s bridge, ASM1153E SATA 6Gb/s bridge]
or
Seagate [Bus 002 Device 003: ID 0bc2:50a0 Seagate RSS LLC FA GoFlex Desk]
Powered USB3 Hub:
Realtek-based [Bus 002 Device 003: ID 0bda:0411 Realtek Semiconductor Corp. Hub / Bus 001 Device 004: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub]
or
VIA Labs-based [Bus 002 Device 004: ID 2109:0817 VIA Labs, Inc. USB3.0 Hub / Bus 001 Device 005: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub]
Rapberry Pi OS Bullseye booted on the SSD (not running on an SD card)
The attached 'test' script performs the following actions:
Copy the entire file structure from /boot to /SAVED-BOOT
Copy the entire file structure from /SAVED-BOOT to /boot
Run 'diff -r /SAVED-BOOT /boot' to ensure /boot is identical to /SAVED-BOOT
Reboot
Following the reboot, executing a 'diff -r /SAVED-BOOT /boot' sporadically reveals that one or more /boot files are corrupt (frequency and degree of corruption varies). test.zip
The firmware isn't writing to the boot partition, and the hardware doesn't know the difference between the boot partition and the rest of the drive, so the problem is likely to be in the kernel or higher.
I would start by putting an explicit sync in your test script after the copy. You can also use sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" to cause any cached files to be invalidated, meaning that your diff will actually be checking the drive contents.
The point is to empty the cache before the verification, to ensure that the files are being read from the drive.
Adding the 'drop_caches' allows the problem to be observed without the need for a reboot and eliminates reboots as the source of the problem. The problem appears to simply be intermittent disk write failures to the FAT32 filesystem when a USB3 hub is used.
The problem occurs when a USB3 SSD or HD is connected via a powered USB3 hub (Realtek- or VIA Labs-based) but never occurs when it's connected directly to one of the Raspberry Pi 4 USB ports.
The updated 'test' script attached to this comment contains the added 'drop_caches' and reliably displays the intermittent failures without the need for a reboot and manual 'diff' afterward. test.zip
Does disabling LPM on the device make a difference?
From lsusb find the vid:pid pair for the device, for example:
$ lsusb
Bus 002 Device 003: ID 05e3:0743 Genesys Logic, Inc. SDXC and microSDXC CardReader
Bus 002 Device 004: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
Bus 002 Device 002: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
The mass-storage device in question is 05e3:0743
Add the following parameter to /boot/cmdline.txt: usbcore.quirks=05e3:0743:k
Can you put a sample of those corrupted files and the originals in one or two zip files and attach them? I'm curious to see the nature of the corruption.
Interesting - the corrupted files appear to contain valid chunks of overlays in a scrambled order. Running md5sum on individual sectors shows some whole sectors migrating between files. For example, the first sector of the BAD spi5-2cs.dtbo is identical to the third sector of the GOOD spi5-2cs.dtbo and spi6-2cs.dtbo. There would probably be more evidence of duplication if not for the fact that the short files mean a large percentage of the sectors are not used in their entirety.
The fact that the ext4 partition never shows this problem suggests this is the result of an interaction between the FAT filesystem and the SSD. Does sudo fsck.vfat /dev/sda1 (or whatever the device name is) show any problems after the copy?
Newer images use a FAT32 cluster size of 2K which obviates the need to use the -o flush mount option, and avoids the VL805 bug. Older images will still be vulnerable as they use a cluster size of 512B.
From this thread I am not sure if the problem is supposed to be solved or not, but my immediate experience is that I reproduce the ext4 fs corruption with 100% occurence rate, using a PI4 and an SSD disk directly connected to an internal USB port.
I create the SSD setup using Raspberry Pi Imager then boot. Everything is fine until I modify a configuration file (/etc/ssh/sshd_config in my case) and then reboot. After that, boot is terribly slow until some timeout occur and then reveal the ext4 corrupted filesystem messages.
I have tried different Raspbian variants (with desktop or not), all with builds from Dec 2023, same result..
Also I would suggest adding fsck.repair=yes fsck.mode=force to your boot partition cmdline.txt
thanks for the tips ! I first thought that that solved the problem. But second reboot and then fsck goes wild... Maybe a power problem with my SSD. I give up on SSD for this time in favor of good old sd card, too much time lost on this.
Activity
reraikes commentedon Jan 27, 2022
This issue also occurs using a Seagate BarraCuda HD (ST4000LM024), but with less frequency than an SSD.
pelwell commentedon Jan 27, 2022
The firmware isn't writing to the boot partition, and the hardware doesn't know the difference between the boot partition and the rest of the drive, so the problem is likely to be in the kernel or higher.
I would start by putting an explicit
syncin your test script after the copy. You can also usesudo sh -c "echo 3 > /proc/sys/vm/drop_caches"to cause any cached files to be invalidated, meaning that your diff will actually be checking the drive contents.popcornmix commentedon Jan 27, 2022
@pelwell was this comment intended for #4812
pelwell commentedon Jan 27, 2022
Yes.
reraikes commentedon Jan 27, 2022
The problem occurs when a user writes files to the FAT32 filesystem in the BOOT partition (/boot) and then immediately reboots.
As originally stated, 'sync' commands have no effect on the problem (a reboot should implicitly flush all buffers).
I will try:
sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
prior to the reboot and report whether it eliminates the file corruption that shows up following the reboot.
pelwell commentedon Jan 27, 2022
The point is to empty the cache before the verification, to ensure that the files are being read from the drive.
reraikes commentedon Jan 28, 2022
Adding the 'drop_caches' allows the problem to be observed without the need for a reboot and eliminates reboots as the source of the problem. The problem appears to simply be intermittent disk write failures to the FAT32 filesystem when a USB3 hub is used.
The problem occurs when a USB3 SSD or HD is connected via a powered USB3 hub (Realtek- or VIA Labs-based) but never occurs when it's connected directly to one of the Raspberry Pi 4 USB ports.
The updated 'test' script attached to this comment contains the added 'drop_caches' and reliably displays the intermittent failures without the need for a reboot and manual 'diff' afterward.
test.zip
XECDesign commentedon Jan 28, 2022
May or may not be relevant: https://forums.raspberrypi.com/viewtopic.php?t=244948
pelwell commentedon Jan 28, 2022
As was asked on that thread:
reraikes commentedon Jan 28, 2022
write-caching = 1 (on)
Yes. The problem is unchanged with 'write-caching = 0 (off)'.
P33M commentedon Feb 2, 2022
Does disabling LPM on the device make a difference?
From lsusb find the vid:pid pair for the device, for example:
The mass-storage device in question is
05e3:0743Add the following parameter to
/boot/cmdline.txt:usbcore.quirks=05e3:0743:kAnd reboot, then run your test.
reraikes commentedon Feb 2, 2022
Bus 002 Device 002: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ...
Adding 'usbcore.quirks=174c:55aa:k' to /boot/cmdline.txt has no effect on the problem using the attached 'test' script:
Ok to run test (y/n)? y
Saving BOOT partition
Restoring BOOT partition
Syncing + Dropping Caches
Comparing BOOT partition
Binary files /SAVED-BOOT/overlays/spi5-1cs.dtbo and /boot/overlays/spi5-1cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi5-2cs.dtbo and /boot/overlays/spi5-2cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi6-1cs.dtbo and /boot/overlays/spi6-1cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi6-2cs.dtbo and /boot/overlays/spi6-2cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-gpio35-39.dtbo and /boot/overlays/spi-gpio35-39.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-gpio40-45.dtbo and /boot/overlays/spi-gpio40-45.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-rtc.dtbo and /boot/overlays/spi-rtc.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1306.dtbo and /boot/overlays/ssd1306.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1306-spi.dtbo and /boot/overlays/ssd1306-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1331-spi.dtbo and /boot/overlays/ssd1331-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1351-spi.dtbo and /boot/overlays/ssd1351-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/superaudioboard.dtbo and /boot/overlays/superaudioboard.dtbo differ
Binary files /SAVED-BOOT/overlays/sx150x.dtbo and /boot/overlays/sx150x.dtbo differ
Restored BOOT partition is corrupt
test.zip
pelwell commentedon Feb 2, 2022
Can you put a sample of those corrupted files and the originals in one or two zip files and attach them? I'm curious to see the nature of the corruption.
reraikes commentedon Feb 2, 2022
Ok to run test (y/n)? y
Saving BOOT partition
Restoring BOOT partition
Syncing + Dropping Caches
Comparing BOOT partition
Binary files /SAVED-BOOT/overlays/spi5-1cs.dtbo and /boot/overlays/spi5-1cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi5-2cs.dtbo and /boot/overlays/spi5-2cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi6-1cs.dtbo and /boot/overlays/spi6-1cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi6-2cs.dtbo and /boot/overlays/spi6-2cs.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-gpio35-39.dtbo and /boot/overlays/spi-gpio35-39.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-gpio40-45.dtbo and /boot/overlays/spi-gpio40-45.dtbo differ
Binary files /SAVED-BOOT/overlays/spi-rtc.dtbo and /boot/overlays/spi-rtc.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1306.dtbo and /boot/overlays/ssd1306.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1306-spi.dtbo and /boot/overlays/ssd1306-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1331-spi.dtbo and /boot/overlays/ssd1331-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/ssd1351-spi.dtbo and /boot/overlays/ssd1351-spi.dtbo differ
Binary files /SAVED-BOOT/overlays/superaudioboard.dtbo and /boot/overlays/superaudioboard.dtbo differ
Restored BOOT partition is corrupt
files.zip
pelwell commentedon Feb 3, 2022
Interesting - the corrupted files appear to contain valid chunks of overlays in a scrambled order. Running
md5sumon individual sectors shows some whole sectors migrating between files. For example, the first sector of the BAD spi5-2cs.dtbo is identical to the third sector of the GOOD spi5-2cs.dtbo and spi6-2cs.dtbo. There would probably be more evidence of duplication if not for the fact that the short files mean a large percentage of the sectors are not used in their entirety.The fact that the ext4 partition never shows this problem suggests this is the result of an interaction between the FAT filesystem and the SSD. Does
sudo fsck.vfat /dev/sda1(or whatever the device name is) show any problems after the copy?70 remaining items
reraikes commentedon Mar 25, 2022
Whether singular or plural, the result is that the massive corruption of files on VFAT filesystems problem is back.
Add flush option to boot partition
Fix fstab flush option
popcornmix commentedon Sep 13, 2022
rpi-update kernel contains #5173
Would be useful if you can test @reraikes
reraikes commentedon Sep 13, 2022
The latest public image (2022-09-06-raspios-bullseye-arm64-lite.img.xz):
Linux raspberrypi 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64
does not have 'flush' on the boot entry of fstab but doesn't appear to exhibit any of the previous corruption problems.
I'll do an rpi-update and test it again.
reraikes commentedon Sep 14, 2022
I'm not getting any errors using 5.15.67, but since I also don't get any errors with 5.15.61, I'm not sure how meaningful it is.
I've seen this before where the problem would go away with a particular kernel release, only to come back with a vengeance in the next release.
Was the removal of 'flush' from 5.15.61 intentional or an oversight?
P33M commentedon Sep 14, 2022
Newer images use a FAT32 cluster size of 2K which obviates the need to use the
-o flushmount option, and avoids the VL805 bug. Older images will still be vulnerable as they use a cluster size of 512B.Add flush option to boot partition
Fix fstab flush option
Add flush option to boot partition
Fix fstab flush option
jfpaccini commentedon Dec 8, 2023
From this thread I am not sure if the problem is supposed to be solved or not, but my immediate experience is that I reproduce the ext4 fs corruption with 100% occurence rate, using a PI4 and an SSD disk directly connected to an internal USB port.
I create the SSD setup using Raspberry Pi Imager then boot. Everything is fine until I modify a configuration file (/etc/ssh/sshd_config in my case) and then reboot. After that, boot is terribly slow until some timeout occur and then reveal the ext4 corrupted filesystem messages.
I have tried different Raspbian variants (with desktop or not), all with builds from Dec 2023, same result..
I will give Ubuntu a try.
any help/idea welcome ;)
satmandu commentedon Dec 8, 2023
Try the safe_spindown script here in case the issue is the drive not getting power long enough at shutdown to sync everything to disk before reboot:
https://forums.raspberrypi.com/viewtopic.php?t=360871#p2164986
Also I would suggest adding
fsck.repair=yes fsck.mode=forceto your boot partition cmdline.txtjfpaccini commentedon Dec 10, 2023
thanks for the tips ! I first thought that that solved the problem. But second reboot and then fsck goes wild... Maybe a power problem with my SSD. I give up on SSD for this time in favor of good old sd card, too much time lost on this.
Thanks for helping!
satmandu commentedon Dec 10, 2023
You can also just put a powered USB hub between the device and the drive.
The Xcellon 4-Port Powered USB 3.0 Slim Aluminum Hub with 1 Dual Data/Charging Port is working for me with a USB NVME SSD and a RPI5...