640
@crashloop_cara ·

Pi 4 keeps corrupting the SD card every few weeks running Pi-hole Storage

Third card in five months. It runs fine for two or three weeks, then DNS stops resolving and I find the root filesystem remounted read-only. Two of the dead cards were 32GB Samsung Evo Select, one was a no-name from a bargain bin, so it is not just cheap cards. Power is the official 5.1V 3A supply, nothing plugged in except ethernet, and the Pi lives on a shelf at room temperature. Is the Pi doing this to the cards or am I somehow buying bad ones every time?

10 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @logfile_lena · 7mo ago · 2 replies

    Before buying hardware, find out how much you are actually writing. Run iotop -ao for an hour and it will name the culprit. On a stock install the big writers are the FTL database, the FTL log, and whatever the default rsyslog config is still doing.

    I raised DBINTERVAL so the database flushes every 15 minutes instead of every minute and my daily write volume dropped by roughly a factor of ten. Same card, two years, no corruption since.

    286
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @null_pointer_ok · 7mo ago

      Also worth setting MAXDBDAYS to 7 and deleting the existing database if it has grown to a few hundred MB. Compacting a large sqlite file on a card that is already limping is not a fun way to find out how fragile it is.

      91
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @deadbug_wiring · 7mo ago · 3 replies

    Stop booting from the card. A Pi 4 with an updated bootloader EEPROM boots straight off USB, and a 120GB SATA SSD in a cheap USB3 enclosure costs about what two more decent cards cost. That one change ends this for almost everyone running an always-on service.

    If you want to keep the card for now, do two things. Move logging to RAM (log2ram, or just point rsyslog at a tmpfs) and turn Pi-hole's query logging down or off. A DNS sinkhole writes constantly, and consumer cards have tiny controllers doing very little wear levelling once the partition is mostly full.

    Also run vcgencmd get_throttled next time it goes read-only. If that comes back as anything other than throttled=0x0, the card is a victim rather than the cause.

    412
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @headless_hugo · 7mo ago

      One gotcha on USB boot: if the Pi has been sitting untouched since 2019 you need to update the EEPROM first with sudo rpi-eeprom-update -a while it can still boot from the card. Do that before you wipe anything, otherwise you get a green light and no HDMI output and spend an evening confused.

      128
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @trace_tilly · 7mo ago

      Enclosure chipset matters too. ASMedia units are generally fine, but a handful of older JMicron bridges need a UAS quirk in cmdline.txt or you get exactly the same read-only filesystem symptom, which is a very annoying way to spend a Saturday when you thought you had fixed the problem.

      44
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @reverse_proxy_ro · 7mo ago

    Undervoltage genuinely causes this. A supply sagging to 4.7V under load will make the card controller misbehave well before the Pi itself resets. Official supplies are usually fine, but counterfeits exist on marketplaces and any added extension cable makes it worse.

    47
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @little_endian_lu · 7mo ago · 2 replies

    Card choice does matter, just not the way the packaging suggests. You want a high endurance card, the ones marketed for dashcams, not a fast one. Read speed is irrelevant for this workload, sustained small random writes are what kills them. Bargain bin cards are also frequently counterfeit and will pass a quick test then fail in week three.

    104
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @swatch_sonia · 7mo ago

      Run f3probe or h2testw on any new card before you trust it with anything. Takes an hour and catches the fakes that report 32GB and actually hold 8.

      38
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @cache_invalidator · 7mo ago · 2 replies

    I just keep a spare imaged card in a drawer and swap it when one dies. Cards are cheap, tuning write volume is not how I want to spend a weekend.

    9
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @grit_greta · 7mo ago

      That works right up until it fails while you are away and the whole house has no DNS and nobody can tell you why the wifi is broken. Fixing the writes is a one afternoon job that you only do once.

      4
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report