Simple Trick to protect your Raspberry SD card from Crashing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
sd cards in raspberry pi computers wear out and die after a while because they are not made for computer usage and many ride cycles in addition the sd cards can become corrupted if the pi loses power without the 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 crazy youtubers here is the guy with the swiss accent with a new episode and fresh ideas around sensors and microcontrollers remember if you subscribe you will always sit in the first row most it experts will tell you to create regular backups of your computer storage devices that is necessary but not sufficient for an engineer like me i want to build a reliable system that never needs to restore the backup reliability with sd cards can be achieved by avoiding extensive writing however because this needs quite some linux knowledge it is nothing for a noob like me so i had to find another way and replaced the sd card with a more reliable storage product the ssd they are made for reading and writing are much faster than sd cards have a vast capacity and should run for years with a raspberry pi fortunately standard raspbian supports usb boot out of the box and the raspberry pi 4 has two fast usb 3 connectors but unfortunately ssds have a few disadvantages the first is that they are mounted outside the standard cases i know you get specialized cases with built-in ssd or m2 capability but they are expensive external ssds often are less expensive but not as convenient also because of the cable the next disadvantage is that they cost money and the third is that they block one of the valuable usb 3 connectors so ssds are a perfect fit for my home automation server and i love this possibility but i have other lower end applications of a raspberry pi for example the ttn gateway on the roof the receiver for weather balloons or the dmr hotspot for amateur radio all those applications should be compact and cheap they do not need to be extremely fast and most of them do not need long time storage of data once they are configured they do not change for a long time but i would like that they lock important events for analysis photo frames and many other projects have the same needs by the way using an sd card would be perfect for such use cases but how can we make them reliable as said before we have to drastically reduce ride cycles on the sd card or avoid them entirely during operation older sd cards had a lock switch to make them read only the smaller microsd cards do no more have such a switch and it anyway would not work with standard raspbian because it would refuse to work fortunately we have a solution for that case bright people went through the whole operating system to find out where it writes to the sd card and in which directories because of the flexibility of linux they created a list of commands to either stop this writing or in the case of important logging for example create a memory disk and redirect their writing like that they were able to create viable solutions like this right up on adafruit's site unfortunately it is a lot of work to copy paste all these steps into the terminal and in the case of the adafruit way it does not work with a desktop version of raspbian fortunately the raspberry foundation elegantly solved the problem it creates a so-called overlay file system in ram and redirects the right traffic like that the sd card can be read only and raspbian still works in addition it is much easier to use and it also works for the desktop version of raspbian let's try it out we open raspberry pi configuration on the desktop go to performance and to overlay file system there we hit enable and get two choices we can create the overlay file system in memory set the boot partition as read only or both together it warns us that we have to reboot to get it working we select both after that we reboot and test we create a file in our home directory and add some text everything works as usual if we close the file and reopen it the text still is there only if we reboot the file is gone because it only resided in run so the feature seems to work it easily can be switched off again for example if you want to upgrade your system once in a while this behavior is perfect also for education where we often have several raspberries and very creative users if you know what i mean with a read-only sd card we can let them do whatever they want if they overdid it or after the lesson we just switch the raspberries off next time we switch them on we are sure the new user starts with a proper configuration maybe you use this feature also if you want to test something and be sure that you can revert to the old status here you have to pay attention to three things because the overlay file system resides in memory we have to have ram i suggest using at least a two gigabyte raspberry pi not all operations are possible in this state the upgrade of the eeprom was refused for example all operations requiring a restart cannot be performed because we would lose all our installation work before we are finished as the famous sisyphus who cheated and was punished to pushing an immense stone up a hill only for it to roll down every time it neared the top if we decide to use the light version we can also use the terminal window to select the feature just type sudo raspy config and you find it under performance as before with this knowledge you can install your lorawan gateway or any other simple project and customize it to your liking after that you hit the two switches and your sd card will survive much longer and you can still check the locks if needed just do it before the next reboot summarized we can avoid extensive writing by disabling unneeded logging redirecting writing to ram disks with a barefoot method like the one documented by adafruit or use the standard raspbian function to create an overlay file system in ram and set the sd card to read only if this is not possible we have to replace the sd cards with ssd drives that was all for today as always you find the relevant links in the description i hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence thank you bye
Info
Channel: Andreas Spiess
Views: 19,208
Rating: 4.9665895 out of 5
Keywords:
Id: LKDC-Wjukk0
Channel Id: undefined
Length: 8min 11sec (491 seconds)
Published: Sun Oct 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.