MicroSD cards are the default storage for most Raspberry Pi setups, and they are also one of the most common failure points in a homelab. The card that ships with a kit or sits in a junk drawer is not necessarily the right card for running a 24/7 service. Picking the wrong one costs you uptime and, potentially, data.
This post covers what to look for when choosing a card, how to reduce wear once it is running, and what to do when things go sideways.
π‘ Why MicroSD Reliability Is a Real Problem
A Raspberry Pi running a home server, a DNS resolver, or an automation hub writes to storage constantly. Log files, databases, container state, and swap all generate write activity. MicroSD flash memory has a finite number of program/erase cycles per cell, and cheap cards hit that limit faster than you might expect.
The failure mode is usually not a dramatic crash. Cards tend to go read-only first, then start throwing filesystem errors, then stop mounting entirely. By the time you notice, you may have lost days of config changes.
π§° Prerequisites
- A Raspberry Pi (any model with a microSD slot)
- A spare microSD card for testing or migration
- A Linux host or the Pi itself for benchmarking
-
f3orh2testwfor capacity verification -
fioorddfor basic performance checks
π Choosing the Right Card
Speed class matters, but it is not the whole story. For homelab use, prioritize these attributes in roughly this order.
Endurance rating. Look for cards explicitly marketed as "high endurance" or "endurance" variants. These are designed for dashcams and security cameras, which means continuous writes, which is exactly the workload a Pi homelab produces. Samsung PRO Endurance, SanDisk High Endurance, and Kingston High Endurance are commonly cited options in this category. These cards are usually rated in hours of continuous video recording rather than TBW (terabytes written), so compare the hours figure on the datasheet for the capacity you are buying.
Capacity sweet spot. For most Pi services, 32 GB to 128 GB is the practical range. Smaller cards fill up faster and leave no room for logs. Within the same product line, larger cards usually carry a higher endurance rating: Samsung rates the PRO Endurance at 17,520 hours for 32 GB and 140,160 hours for 256 GB. Pick a size that fits your OS plus your data with at least 20 percent headroom.
Fake capacity is still a thing. Counterfeit cards that report a false capacity are common on discount marketplaces. Always verify a new card before trusting it with real data.
Step 1: Install f3 on your Pi or Linux machine.
sudo apt update && sudo apt install f3 -y
Step 2: Mount the card, then write test files to it (replace /mnt/sdcard with the card's mount point). f3write fills the free space on the mounted filesystem.
sudo f3write /mnt/sdcard
Step 3: Read it back and verify.
sudo f3read /mnt/sdcard
If f3read reports Data LOST: 0.00 Byte and the Data OK figure matches the free space that was written, the card holds what it claims. If it reports lost or corrupted data, return it.
β‘ Benchmarking Before You Commit
A quick sequential read/write test tells you whether the card is going to feel sluggish under load. Use dd for a rough check, or fio for a more realistic workload simulation. The number that matters most for a Pi running services is random 4K write IOPS, because small random writes are what databases and container runtimes generate. The SD Association's Application Performance Class (A1 or A2 on the label) is the rating that guarantees minimum random IOPS, and Raspberry Pi's own microSD cards are rated A2.
Step 1: Test sequential write speed with dd.
dd if=/dev/zero of=/mnt/sdcard/testfile bs=4M count=256 conv=fdatasync status=progress
Step 2: Drop the page cache with sync; echo 3 | sudo tee /proc/sys/vm/drop_caches, then test sequential read speed. Otherwise Linux serves the file you just wrote from RAM and the result is far higher than the card can really do.
dd if=/mnt/sdcard/testfile of=/dev/null bs=4M status=progress
Step 3: Clean up.
rm /mnt/sdcard/testfile
For random I/O testing with fio, refer to the fio documentation for job file syntax, as the flags vary depending on the test profile you want. A UHS-I Speed Class 3 (U3) or Video Speed Class 30 (V30) card should sustain at least 30 MB/s sequential writes. Endurance cards sometimes trade peak sequential speed for better sustained performance over time, so do not disqualify a card solely because it is slower on burst benchmarks.
π οΈ Reducing Wear While the Pi Is Running
Even a good card lives longer if you reduce unnecessary writes. These changes are practical on Raspberry Pi OS and most Debian-based Pi distributions.
Move logs to RAM. The log2ram tool writes system logs to a RAM-based filesystem and syncs them to the card once a day and at shutdown rather than on every log line, so a power cut can lose the most recent logs. Install it from its GitHub repository and follow the project instructions for your OS version, since the recommended install method has changed over its release history.
Reduce swap pressure. Swap on an SD card is brutal. Either disable swap entirely if your workload fits in RAM, or move swap to a USB-attached drive. The commands below apply to Raspberry Pi OS Bookworm and earlier. Raspberry Pi OS Trixie replaced dphys-swapfile with rpi-swap, which defaults to compressed swap in RAM (zram) and only occasionally writes idle pages to storage. It is configured through /etc/rpi/swap.conf or drop-in files in /etc/rpi/swap.conf.d/, and changes need a reboot.
sudo dphys-swapfile swapoff
sudo systemctl disable dphys-swapfile
Use tmpfs for volatile directories. On Raspberry Pi OS Trixie, /tmp is already a tmpfs by default, following Debian 13, so check with findmnt /tmp first. On older releases, add entries to /etc/fstab to mount /tmp and optionally /var/tmp in RAM.
tmpfs /tmp tmpfs defaults,noatime,nosuid,size=64m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=32m 0 0
Add noatime to your root mount. Access time updates turn file reads into small writes, although the kernel's default relatime behaviour already limits them. Raspberry Pi OS images already mount the root partition with defaults,noatime, so check /etc/fstab before editing. On other distributions, add noatime to the options for your root partition. Be careful editing fstab: a syntax error can prevent boot. Keep a backup or a second card you can boot from to recover.
π Boot from USB Instead
If your Pi model supports USB boot (the Raspberry Pi 3B+ and Zero 2 W do out of the box, and the Raspberry Pi 4 and 5 do once USB is in the bootloader's BOOT_ORDER, although early Raspberry Pi 4 boards may need a bootloader update first), consider moving your root filesystem to a USB SSD or flash drive. You can still use a microSD for the boot partition while running the OS and all writes from USB storage. An SSD tolerates random writes far better than any microSD card.
The Raspberry Pi documentation covers the USB boot setup process in detail, including the raspi-config option and the bootloader EEPROM update steps. Check the official docs at raspberrypi.com/documentation for your specific model.
π‘οΈ Monitoring and Backup
You cannot prevent all card failures, so detect them early and make recovery fast.
Watch filesystem errors. Check dmesg periodically for I/O errors or EXT4 warnings. These often appear before the card fails completely.
dmesg | grep -i "error\|i/o\|ext4"
Keep a current image backup. Tools like rpi-clone can clone a running Pi to a second card in a USB reader with minimal disruption. The original billw2/rpi-clone repository has not been updated since March 2024, so look at a maintained fork such as geerlingguy/rpi-clone. A weekly clone to a spare card means your recovery time after a failure is the time it takes to swap cards, not the time it takes to rebuild from scratch.
Store config in version control. Any config that lives in /etc or your home directory should be committed to a git repo and pushed offsite. This is a safety net that survives even a total card loss.
π§ Troubleshooting
-
Filesystem goes read-only: The kernel mounted it read-only after detecting errors. Put the card in a USB reader on another Linux machine (or a Pi booted from a different drive) and run
sudo fsck -f /dev/sdX2against the unmounted root partition, replacingsdX2with the real device. If errors keep coming back after a repair, the card is failing. -
Pi will not boot after fstab edit: Boot from a second card or use a USB recovery image, mount the original card, and fix
/etc/fstabmanually. -
Slow I/O under load: Check whether swap is active with
free -h. Heavy swap on a microSD tanks performance. Disable or relocate swap first. - Card not recognized: Try a different USB adapter when flashing. Some cheap adapters limit bus speed and cause flashing errors that look like card errors.
β Wrap Up
MicroSD cards are not all the same, and the homelab workload is harder on them than most consumer use cases. Start with a genuine high-endurance card, verify its capacity before you trust it, reduce write amplification through tmpfs and log2ram, and keep a current backup so recovery is fast when a card eventually dies.
If your Pi model supports USB boot, moving the root filesystem to an SSD is the single biggest reliability upgrade you can make. The microSD slot becomes a low-stress boot loader and the rest of your stack runs on storage that was built for it.
Related from the lab
- Why You Shouldn't Power a Raspberry Pi Through Its GPIO Pins
- Pironman 5 Max Case Setup
- Self-Host Apache Guacamole on a Raspberry Pi 5: Browser Remote Access for Your Homelab
Originally published at codewithromi.com.
Top comments (4)
The
dmesgcheck in the monitoring section is useful for an immediate failure, but the kernel ring buffer is finite and older messages can be overwritten. On systemd-based Raspberry Pi OS, this is a useful companion check:-blimits the query to the current boot. On a system with a persistent journal, dropping-bcan help when the errors happened before a reboot. Journal availability is the caveat: with volatile or RAM-backed logging, a power cut can remove exactly the messages you need. That makes journal collection useful for diagnosis, but not a substitute for the config backups you recommend.Thanks for the addition. I covered the risk of losing RAM-backed logs in the log2ram section, but adding journalctl alongside dmesg would make the monitoring section more complete. For errors from a previous boot, journalctl -k -b -1 would also be useful if persistent logging is enabled.
The
-b -1qualifier matters. Iβd checkjournalctl --list-bootsfirst: with volatile journaling there may be no previous boot to select, and switching to persistent logging only preserves subsequent boots. So βno entriesβ fromjournalctl -k -b -1is not evidence that the earlier boot had no kernel errors.Good clarification! Appreciate the extra detail.