Tue Nov 05, 2019 6:42 am
Memory cards do not work very long with operating systems that use active burning to disk. And of course, if you use programs with data caches to disk (Kodi, Chromium, GIMP and others). There are many common ways to extend the life of a card. And yes, you need to buy cards from well-known manufacturers. There are also so-called “industrial” memory cards with increased durability.
Here are some ways to extend the life of memory cards.
1. Immediately abandon the swap file and switch to Raspberry with 4 GB of memory. Unfortunately, 1 GB of memory is clearly not enough by modern standards to work with the Internet or to watch videos.
You either kill the memory card with swap and cache files, or you buy a computer with 2-4 GB of memory.
2. Install zram and organize work with a “compressed” virtual file system.
3. Disable unnecessary (for most) “garbage” Debian services such as logging (this is resetting data that is unnecessary for most users to the memory card every ten seconds, which reduces the card’s resource), creating “core” (dump) files and other “amenities” for programmers and debugs that you use once every hundred years for critical program errors (like in Kodi, which does a 2GB dump for every sneeze).
Be sure to change the settings in ulimit - disable the creation of large core files!
4. Be sure to transfer all directories where programs write the cache to tmpfs
This primarily concerns Chromium, which is capable of killing almost any memory card in a few months with its work. Chromium creates meaningless and unnecessary cache files in huge numbers every second! Firefox does the same, but almost doesn't litter Luakit
Are you using chromium actively? Your card has been killed, mutilated, destroyed!
5. Optimize fstab, specify options like defaults, noatime, nodiratime, errors = remount-ro, and more.
The journaled file system does not work well with memory cards, since it also writes data to the memory card every second at its discretion. Kill the log and your memory card will work better!
These directories need to be transferred to memory
tmpfs / var / log tmpfs nosuid, nodev 0 0
tmpfs / var / tmp tmpfs nosuid, nodev 0 0
6. Correct the errors of Debian. Buster is a buggy system, still raw and bad.
So, the / tmp directory cannot be transferred to tmpfs without dancing with tambourines. This is due to the fact that Buster first writes to tmp at boot, then mounts the disks. I don’t know if Buster has fixed this error, but they recommend a special method for creating tmp as a virtual file system.
7. If you want to further extend the life of the memory card, you can take the following effective steps.
Transfer the entire / home / pi directory to RAM, mount it as tmpfs. To save some important settings, you can write a boot script that will write data to / home / pi at boot time
I did so, as a result, I have Chromium’s cache in RAM and other programs do not write garbage to the memory card.
The second method is also effective - create a read-only overlay file system. But
This method has special properties and is not suitable for everyone.
8. Many programs write their unnecessary logs to disk. Disable logging of these programs or make links to recording directories in tmp
rm -rf / var / lib / dhcp / var / lib / dhcpcd5 / var / spool
ln -s / tmp / var / lib / dhcp
ln -s / tmp / var / lib / dhcpcd5
ln -s / tmp / var / spool
Add to this the following
rm -rf / var / cache / fontconfig
ln -s / tmp / var / cache / fontconfig
Do you need fontconfig cache? Are you sure you know why you need / var / lib / dhcpcd5? This is just rubbish that you will never need. Make a symbolic link.
Your card will not be attacked by poorly written programs.
There are many methods, I wrote only about the first steps that dramatically increase the standard of living of the memory card and the speed of work. For example, these settings will “accelerate” your Raspberry to high speeds, because Chromium “slows down” if it writes cache to a memory card (memory cards have a low write speed). If the cache is organized in RAM, Chromium is very fast.