5

I've seen several posts about SD card lifespan, however I'm still a bit confused about it.

In my case, I have Raspberry Pi B+ running slideshow from image and HD video (~40MB) in OpenELEC/Kodi, all day long, reading from the SD card. The SD card is SanDisk 8GB class 10.

It is located on a shopping, so if it gets down I'm somewhat fired.

I have another RasPi for backup, and another SD image prepared for the worst.

Am I doing right?

8
  • Do you have pictures on hdd or on sd? Mar 20, 2015 at 5:14
  • pictures and videos on SD card. I tranfer them into it using Samba Mar 20, 2015 at 5:33
  • 2
    Well, why don't you move media contets to show to some more "risk-free" media, like, USB HDD that can be plugged into rPi B+? Mar 20, 2015 at 6:08
  • I'm not sure about mounting the USB HDD, or if it will be automounted after reboot. Also I should have to configure my samba media folder I guess. Mar 20, 2015 at 6:56
  • Is it really risky using the SD card, or you say that just in case? Mar 20, 2015 at 6:56

1 Answer 1

10

I've seen several posts about SD card lifespan

Then please be sure to read mine, which is the other side of the coin from all the "OMG! Your SD card is in danger! You need to protect it now by reading my blog!" stuff:

https://unix.stackexchange.com/questions/84902/pimp-rsyslogd-to-have-less-i-o-cron-pam-and-less-logging

And a sort of tangent to that which gets into methodology for stress testing SD cards to see just how long they will last:

https://unix.stackexchange.com/questions/96774/stress-testing-sd-cards-using-linux

I'll quote the first one:

If your system writes a MB of logs a day [...] and you have a 4 GB card, it will take 4000 days before such a cycle has written to the entire card just once. The actual lifespan of an SD card might be as much as 100,000 write cycles. So all that logging will wear the card out in 4000 * 100000 / 365 =

~ 1 million years

Note that unless your system is very busy, it won't be logging nearly that much anyway. Since pi oriented distros such as raspbian use tmpfs (i.e., RAM) for /tmp and /run, that pretty much covers what the system will do as a matter of course. Your own actual activity will be much more significant -- if you were actually averaging 100 MB of writes per day, this would be reduced to 10 000 years.

Of course, that's a bit of an exaggeration as it is based on the idealized lifetime of 100 000 write cycles for the card. That probably only applies to very high end cards. Let's assume a very low end of only 1000 write cycles -- now we are down to just 10 years at 100 MB a day for a cheap 4 GB SD card.1

Note this is about writes and not reads, which are much less expensive wear wise. What wears the card out is erasing (which it must always do before writing, a characteristic of some solid state storage is that all bits are set one way before data is written).

I have Raspberry Pi B+ running slideshow from image and HD video (~40MB) in OpenELEC/Kodi, all day long, reading from the SD card.

Here's a great feature of modern operating systems including linux: file caching. If you have 512 MB of RAM but only use 350 MB of it, the OS has 150 MB left over to use as a cache (you can see this with tools like free or top which may include that in their total, making it seem as if you are using all of it -- pay attention to the "buffers/cache" figure). It will use that to store frequently read data so it doesn't have to read from disk all the time. If you are constantly reading a 40 MB film over and over, there's a very good chance that all or most of that will be cached in RAM, i.e. most of the time it won't really be reading from the SD card.

In your case, you might want to guarantee this for yourself by mounting a small tmpfs partition at boot and copying your movie, etc. into there. Tmpfs is in RAM, so that means you are guaranteed no SD card reads, hooray.

This may all seem to go against the hundreds of people who have reported various places online (including here) that their brand new SD card keeps getting corrupted in the pi. I am not calling these people liars, but it is worth considering a few things.

  • There are millions of raspberry pis in the world.
  • There are tens or hundreds of millions of SD cards in use everyday, in phones, cameras, etc.

No one goes on line to announce, "Hey, guess what? My pi's been on for two years with the same SD card -- no problems so far!". It's true for me, and true for a lot of other people as well I am sure.

It seems to me looking around that complaints about SD card corruption are reported disproportionately by pi users (but this could also have to do with my search profile). It could well be that there are some pis out there that have some defect that is causing this problem, or because of the nature of the power system under certain circumstances.

But there's no point worrying about that until it happens, because it probably won't, and if it does, there's not much you can do about bad hardware except replace it.

A tip about filesystems in general that probably applies even more so to ones on SD cards because of the mechanism described below: Don't fill them to capacity. Stay below 75-80% and ideally, closer to 50%. So if you have an 8GB card, think about it as a 6GB card and don't fill it beyond that. If you know you need 8GB, buy a 16 GB card. This logic doesn't apply to things like cameras, BTW, just root filesystems for devices like the pi.


1. A somewhat tech savvy person might object that this is still very idealized since some physical blocks are prone to get used much more than others. That person is unaware of wear levelling <- read this to be even more tech savvy ;) SD cards have a logic chip in them and use virtual addressing to spread wear evenly, maximizing their lifespan.

11
  • What about if the logic chip managing the wear levelling is the bottleneck concerning lifespan? Edit: Otherwise fully d'accord with @goldilocks.
    – user236012
    Mar 20, 2015 at 10:39
  • @user236012 You mean that logic chip may wear out? Probably -- I don't really believe they're going to last a million or even a hundred years. Stuff inevitably breaks, which is why it is always important to maintain a backup. They are so cheap anyway, even if it only lasts a year or two and you have that backup, when it finally fritzes out you can just replace it.
    – goldilocks
    Mar 20, 2015 at 10:51
  • Really thanks for your answer. You've replied all new questions that emerged to me while I was reading it. Also, interesting links to check. Just one thing about cache I'm not sure about. Kodi has an advancedsettings.xml file in which you can set buffermode to 1. That means "Buffer all local and internet files". Default is 0 (only internet files), would it be still caching my playing media files stored in sdcard? It should be caching somewhere... Mar 20, 2015 at 17:59
  • I've read your post several times. I was really concerned about SD card risks. Mar 20, 2015 at 18:01
  • Looks to me that if you want Kodi to buffer local files you'd need to set buffermode to 1. However, I'm not too sure that means it is going to keep it cached unless it has a loop setting to play over and over and/or is smart enough. You might be able to tell by watching what happens with your free mem. But the surest bet IMO is still to use tmpfs -- although that's beyond the scope of this question, it is pretty simple: thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux You can set that up and copy stuff into it at boot via /etc/rc.local.
    – goldilocks
    Mar 20, 2015 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.