Other Best practices running on inexpensive flash devices (e.g., USB flash drives, SD cards)?

What are some best practices for configuring a FreeBSD host to maximize media lifetimes when using inexpensive flash devices for the base system & pkgs?

Backstory: for about 4 years, I've run 2 Raspberry Pis and 1 amd64 machine using (at different times on different machines) UFS-formatted USB flash drives or SD cards for the base system & pkgs. The hosts don't do very much, and might be presumed not to do too much I/O to these media: the Pis are ssh "jump hosts" on a couple networks, the amd64 machine has a ZFS pool that it serves via NFS. all of them run postfix as "satelites" that forward to a smarthost. These hosts are online continously. My experience has been that all these flash devices typically wear out (as determined by onset of I/O errors) after about 6 months. The devices I've used are of different types, from different vendors, and bought at different times; so it's not just one bad manufacturing lot. So my hunch is that I'm allowing FreeBSD to do too many writes to these media, and I'm curious whether/how I might better configure these systems for improved media life.
 
In general: configure your system to run from memory (it boots from flash, copies stuff needed into RAM, then runs from there), do not write log files to the flash device (if you need logs, look into remote syslog).

Raspberry Pi 1's was / are notorious when it comes to eating SD / microSD cards. Newere Raspberry Pi's can be configured to boot from other devices, you might have better luck with them (but only if you don't buy the cheapest usb drives, for example).

If you want to run Raspberry Pi's off SD / microSD cards, get an industrial one (SwissBit is a brand we have been happy with) even if it costs 3 times as much as the cheap ones.
 
run filesystems with noatime when possible
see varmfs* setting in rc.conf (if you dont care of transient data)
use "high endurance cards" (meant for dashboard cameras and such)
i run a pi zero with such a card (mfg sandisk) for several years now but it does nothing (only sends periodic mails)
but i did build gcc on it and several other packeges which should count for something :)
 
Thanks, both. I did not know about varmfs (or tmpmfs, for that matter). That plus a read-only root file system seems to be a good place to start. Is there any support for customizing how /var gets populated during boot? I think I'll need to do something customized to support certain packages (e.g., postfix would need /var/spool/postfix to be suitably populated). I see how it works in /etc/rc.d/var but I don't know if it's feasible to put a customized file at /etc/mtree/BSD.var.dist.
 
Why use that junk? Optane 16 GB M.2 NVMEs cost $5, and you can re-use USB enclosures.

You can generally run FreeBSD completely read-only (with ro mounted filesystems), but I have a hunch that your cheap SD cards and USB sticks will still die. It's not that they exclusively die from write endurance excess.
 
I have been running Raspberry Pis as firewalls for 10 years. Older ones boot from SD. But they have all run from a USB stick. In 20 Pi years, I have had one USB stick die. Admittedly they run Raspbian, not FreeBSD.

I think the answer depends on the duty cycle and quality of the storage components. I don't log locally, or run applications frequently. I use quality USB sticks. I copy the USB stick with dd(1) for backup every few months. Recovery is via loopback mount of the file system images, as no two USB sticks ever seem to be exactly the same size.

I'd certainly endorse the M.2 option. That's now supported on the Pi 5 (I literally just got one to use as a spare). My Argon ONE V3 Case has an optional base with bootable M.2 NVME Expansion Board support.
 
dear tingo :
In general: configure your system to run from memory (it boots from flash, copies stuff needed into RAM, then runs from there), do not write log files to the flash device (if you need logs, look into remote syslog).
how to configure my system freebsd14.2 boot from hdd and running system in 32Gb ram ? thanks. that will make my system fast . thanks.
 
Why use that junk?...It's not that they exclusively die from write endurance excess.

Fair question, though because my (non-scientific, small-N) experience has been 6 month lifetimes invariant of machine, workload, media type, and brand, my hunch is that write wear has been the dominant factor.

(I suppose I should stipulate some considerations: these are "homelab" machines, uptime is desirable but not critical, and I've got backup/recovery/redundancy that works well enough to recover a host in about 15 minutes when I have physical access and spare parts.)

Right now I could get 16GB USB flash drives for between $2 (whitelabeled) and $9 (recognizable brands); an enclosure plus NVME would seem to start at $20 (though if I want recognizable brands, upwards of $30). So even if enclosures and NVME drives had infinite lifetimes and USB drives could only last 6 months, the low-end USB drives would last me 5 years before cost parity with the low-end enclosure plus NVME. If I can stretch the lifetime of the USB or SD card, that cost/time ratio gets better.

As it's unreasonable to expect the enclosure or NVME to have infinite lifetimes, so another way to look at things is that if I want to always have one of each spare part on hand, I would be looking at between $2 and $9 of sitting on a shelf vs. $20 to $30, and that "inventory" overhead would be invariant of media lifetimes.

But in fact I end up getting inexpensive flash media as vendor swag or retailer giveaways often enough that these cost analyses are effectively counterfactual. When people start giving away free USB NVME drives, I'll re-evaluate :)
 
I highly doubt that you will be able to wear out a USBed Optane on a Raspberry Pi even if you tried.

It really depends on what you are doing. A firewall can be run readonly trivially (in fact I ran one on write-protected a 1.44 MB floppy). A mailserver I would estimate is not a wise thing to put on non-SSD flash.
 
do you know how to load full system to RAM and active it to running ?
The trick is in /boot/loader.conf:
Code:
mfs_load="YES"
mfs_type="mfs_root"
mfs_name="/mfsroot"
vfs.root.mountfrom="ufs:/dev/md0"
That /mfsroot file contains a (compressed) filesystem image that gets loaded to ram, then it boots from that ram disk. This feature was originally developed for booting diskless clients but has since had many other uses.
 
The trick is in /boot/loader.conf:
Code:
mfs_load="YES"
mfs_type="mfs_root"
mfs_name="/mfsroot"
vfs.root.mountfrom="ufs:/dev/md0"
That /mfsroot file contains a (compressed) filesystem image that gets loaded to ram, then it boots from that ram disk. This feature was originally developed for booting diskless clients but has since had many other uses.
Dear SirDice :
thanks for your help. got it . your voice let me go ahead in freebsd. that was a great system. thanks.
 
Back
Top