Simple Trick to protect your Raspberry SD card from Crashing

27,106
0
Published 2024-07-28
This is a replay of the video 403 (during my summer break)
SD cards in Raspberry Pi computers wear out and die after a while because they are not made for computer usage, and many write cycles. In addition, the SD cards can become corrupted if the Pi loses power without a proper shutdown. We have several possibilities to avoid this disaster. Only one is simple and cheap. But, unfortunately, it has its caveats. So, let’s get an overview and use a nearly unknown Raspbian feature to help us solve the problem.

My second channel: youtube.com/HB9BLAWireless

Links:
Raspberry Pi 4: amzn.to/4ckpLUF
Raspberry Pi 5: amzn.to/4cD8rKp
Barefoot method 1: medium.com/swlh/make-your-raspberry-pi-file-system…
Barefoot Method 2: www.raspberry-pi-geek.de/ausgaben/rpg/2018/08/rasp…
Adafruit's writeup: learn.adafruit.com/read-only-raspberry-pi/overview

Patreon supporter companies:
www.welectron.com/

The links above are usually affiliate links that support the channel (at no additional cost to you).
Supporting Material and Blog Page: www.sensorsiot.org/
GitHub: www.github.com/sensorsiot
My Patreon Page: www.patreon.com/AndreasSpiess
Discord: discord.gg/JfgDSa8
If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission on your purchases to buy new stuff for the channel
My Amazon.com shop: www.amazon.com/shop/andreasspiess
For Banggood bit.ly/2jAQEf4
For AliExpress: For AliExpress: bit.ly/3MtXUY8 (just go on from here to your product)
For Amazon US: www.amazon.com/shop/andreasspiess
For Amazon.de: amzn.to/2r0ZCYI
For Amazon UK: amzn.to/2mxBaJf
For ebay.com: ebay.to/2DuYXBp

twitter.com/spiessa
Please do not try to email me. This communication channel is reserved for my primary job
As an Amazon Associate, I earn from qualifying purchases
#no#midroll#ads

All Comments (21)
  • @joels7605
    In /etc/fstab: add commit=300 to the mounts options for the SD card. Linux will normally write out changes to the filesystem every 5 seconds. That's a lot of writes. commit=300 caches writes for 5 minutes (when possible) and does one write. Very easy change, greatly increases SD card life. ...and the whole operating system works like normal.
  • @rGunti
    I built a (now wallmounted) LED clock display, which cycles through various different displays (like weather, sunrise/sunset, etc.). After I noticed that things broke due to an SD failure, I went to search for a solution and found one which was like No. 2. (That was before OverlayFS was a thing I think). It boots the OS and then switched the root to Read Only. With a simple command, I can remount it as writable to run updates. Either by running a command or rebooting, I can switch it back to read only mode. This thing is running for what I believe are 3-4 years on the same SD card at this point and survived multiple power outages without issue.
  • Another benefit of overlay fs is that you don't need to shut down the raspberry pi, you can simply unplug it without loosing any data.
  • This is why I lean towards Orange Pi - the EMMC option means that I can run the whole show without the need for an SD card (after installation). Plus - cheap! Another advantage - I don't have to partition any RAM to avoid log files etc. Currently I have an Orange Pi 3 LTS doing "Pi-hole" and NAS duties. The OPi 3B has removable EMMC plus it also has a port for an NVME solid state drive.
  • @ericks1979
    Awesome! I did a bunch of writing and was worried about this. I started with just using a separate sacrificial SD card, then using a RAM disk, but never changed all the OS writing to it. This makes it so easy.
  • With a bit more knowledge on Linux, you can also mount your logs folder in a remote filesystem (like a NAS or similar) and then even your logs are permanent after a reboot.
  • @PhG1961
    Indeed a nice recap and wonderful summer Sundays entertainment. These days there's a lot of work that needs to be done in the garden/back yard. Can't wait for the fall... long evenings in the workshop!
  • @bartjsmit
    Hi Andreas, I solved the issue with a half-way house between external SSD and SD card - the RaspiKey, which is a EMMC module with an SD card interface. I used it for PiKVM, which uses Arch Linux and admittedly is read-only out of the box. To use its ISO storage though would involve writes and I have just been scarred too many times by SD failures. You can make your own with an adapter and modules from your favourite middle kingdom electronics bazaar, but I did not have time for that. BTW PiKVM is an awesome project, well worth a look and perhaps a video ;-)
  • @zvpunry1971
    This is actually implemented using the debian package overlayroot. After it is installed, it adds a few scripts to the initramfs and is controlled using a boot parameter.
  • @asiw
    So useful. I wondered what the overlay file system was for. Now I know I can use this method with confidence. Thank you.
  • @c128stuff
    Do all your logging to some 'centralized' syslog server instead of to your local filesystem, this solves more than just avoiding writes to sd cards. I do this for all the RPIs I use, which all run from a read-only filesystem with just a ram overlay for tmp files. The only 'issue' with that is having to make the filesystem writable temporarily when wanting to save persistent config changes.
  • @greg4367
    Always educational, this week very appreciated. Thank you.
  • @Bus2000
    Thanks was looking for this a long time. Had a lot of SD card crashes.
  • @avejst
    Great walk-through video of the process ❤
  • Whoa - thank you for this. This is a great tool, and will help a lot. I had no idea this was an option until your video.
  • On my last project, I used an RPi5 with an NVME drive attached to the PCIe flat flex slot. Even running at the standard gen 2 speed, the OS is so fast and responsive that I wouldn't go back even to a USB drive. I had a few issues using the USB method, I think there was some power delivery issues which caused the drive to disconnect occasionally, which obviously causes everything in the OS to crash. The NVME way works without any special setup needed, I then also set swappiness to 0 persistent on reboots.