SD Card Dies on a NixOS Raspberry Pi — A Write-Minimizing Rebuild
A homelab Raspberry Pi 4B running NixOS suddenly stopped serving torrents, SMB, and SSH, and refused to boot past the kernel. The culprit was the microSD root filesystem: an fsck kept turning up fresh errors after each pass, marking the card as effectively dead after years of near-continuous writes, with a recent building-wide power outage delivering the finishing blow. Because the important data lived on external HDDs and the entire machine was described declaratively in a NixOS config, actual losses were trivial — only regenerable caches and .torrent files that weren’t backed up.
The rebuild centers on cutting writes to the SD card so it lasts longer. The author moves swap into a compressed in-RAM zram device, keeps /tmp on tmpfs, sets journald to volatile in-memory logging, and mounts root with noatime. For storage redundancy, two mismatched old 2.5” drives (a 500GB ex-Windows disk and a 320GB Apple-branded Hitachi) are pooled into a btrfs raid1 mirror, chosen for its flexible, grow-anytime topology.
The more interesting piece is a custom NixOS “autosubvol” module that provisions one btrfs subvolume per service declaratively, generating systemd mount and oneshot “ensure” units so a subvolume is created if missing and mounted before its service starts — keeping each service module clean. The post also lands a pointed aside that 2026 is a bad year to buy drives, RAM, or GPUs, blaming AI datacenter demand and arguing for reusing junk-drawer hardware instead.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.