Skip to content

Raspberry Pi 4 : USB3 SSD Connected via USB3 Hub : BOOT Files Corrupted Following Reboot #4844

Open

Description

@reraikes

Describe the bug

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:

  1. Raspbberry Pi 4B 4GB (revision 1.1 or 1.2)

  2. SSD: Samsung EVO 860 or Corsair Neutron

  3. 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]

  4. 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]

  5. Rapberry Pi OS Bullseye booted on the SSD (not running on an SD card)

The attached 'test' script performs the following actions:

  1. Copy the entire file structure from /boot to /SAVED-BOOT
  2. Copy the entire file structure from /SAVED-BOOT to /boot
  3. Run 'diff -r /SAVED-BOOT /boot' to ensure /boot is identical to /SAVED-BOOT
  4. 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

Device (s)

Raspberry Pi 4 Mod. B

System

Raspberry Pi reference 2021-10-30
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 288b21fc27e128ea6b330777aca68e0061ebf4fe, stage2

Jan 20 2022 13:56:48
Copyright (c) 2012 Broadcom
version bd88f66f8952d34e4e0613a85c7a6d3da49e13e2 (clean) (release) (start)

Linux raspberrypi 5.10.92-v7l+ #1514 SMP Mon Jan 17 17:38:03 GMT 2022 armv7l GNU/Linux

Logs

No response

Additional context

No response

Activity

  1. reraikes commented on Jan 27, 2022

    @reraikes
    Author

    This issue also occurs using a Seagate BarraCuda HD (ST4000LM024), but with less frequency than an SSD.

  2. pelwell commented on Jan 27, 2022

    @pelwell
    Contributor

    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.

  3. popcornmix commented on Jan 27, 2022

    @popcornmix
    Collaborator

    @pelwell was this comment intended for #4812

  4. pelwell commented on Jan 27, 2022

    @pelwell
    Contributor

    Yes.

  5. reraikes commented on Jan 27, 2022

    @reraikes
    Author

    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.

  6. pelwell commented on Jan 27, 2022

    @pelwell
    Contributor

    The point is to empty the cache before the verification, to ensure that the files are being read from the drive.

  7. reraikes commented on Jan 28, 2022

    @reraikes
    Author

    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

  8. XECDesign commented on Jan 28, 2022

    @XECDesign
    Contributor
  9. pelwell commented on Jan 28, 2022

    @pelwell
    Contributor

    As was asked on that thread:

    What does hdparm -W report? Do you get the same corruption if you disable the drive write cache with hdparm -W0?

  10. reraikes commented on Jan 28, 2022

    @reraikes
    Author

    What does hdparm -W report?

    write-caching = 1 (on)

    Do you get the same corruption if you disable the drive write cache with hdparm -W0?

    Yes. The problem is unchanged with 'write-caching = 0 (off)'.

  11. P33M commented on Feb 2, 2022

    @P33M
    Contributor

    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

    And reboot, then run your test.

  12. reraikes commented on Feb 2, 2022

    @reraikes
    Author

    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

  13. pelwell commented on Feb 2, 2022

    @pelwell
    Contributor

    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.

  14. reraikes commented on Feb 2, 2022

    @reraikes
    Author

    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

  15. pelwell commented on Feb 3, 2022

    @pelwell
    Contributor

    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?

  16. 70 remaining items

  17. reraikes commented on Mar 25, 2022

    @reraikes
    Author

    Changes or change? We've only reverted one of the patches.

    Whether singular or plural, the result is that the massive corruption of files on VFAT filesystems problem is back.

  18. popcornmix commented on Sep 13, 2022

    @popcornmix
    Collaborator

    rpi-update kernel contains #5173
    Would be useful if you can test @reraikes

  19. reraikes commented on Sep 13, 2022

    @reraikes
    Author

    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.

  20. reraikes commented on Sep 14, 2022

    @reraikes
    Author

    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?

  21. P33M commented on Sep 14, 2022

    @P33M
    Contributor

    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.

  22. jfpaccini commented on Dec 8, 2023

    @jfpaccini

    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 ;)

  23. satmandu commented on Dec 8, 2023

    @satmandu

    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=force to your boot partition cmdline.txt

  24. jfpaccini commented on Dec 10, 2023

    @jfpaccini

    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=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.

    Thanks for helping!

  25. satmandu commented on Dec 10, 2023

    @satmandu

    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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions