How To Extend The Life Of Your Raspberry Pi’s SD Card

Christian Cawley 09-06-2014

First appearing as extended storage for PDAs, smartphones and digital cameras around 10 years ago, SD cards are now a popular addition to tablet and mini computers such as the Raspberry Pi. Offering high capacity and fast write speeds, SD cards are particularly important to the Raspberry Pi, which uses this type of storage as a system disk.


If you know anything about SD cards, then you’ll see how this might prove to be a problem. SD cards have a finite life, with limits on how often data can be written and rewritten before the card gives in to entropy.

Given the wide number of projects available to Raspberry Pi users (anything from media centers The Hardware You Will Need To Build A Raspberry Pi Media Center With so many ways of using it, you shouldn't be surprised to find that the Raspberry Pi has sold over 1 million units. Although designed for one key purpose (programming) this small credit card-sized computer... Read More and retro gaming systems Retro Gaming on Raspberry Pi: Understanding ROMs, RetroPie, Recalbox, and More The Raspberry Pi is ideal for playing classic video games. Here's how to get started with retro gaming on your Raspberry Pi. Read More to taking photos from space Raspberry Pi Projects: A Car With Night Vision, Google Glass-like Translation, And More We’ve previously looked at some excellent uses for this British minicomputer, but the fact is that it is just so versatile that there is always something amazing to talk about. Who would have thought that... Read More ) it seems sensible to investigate just how SD cards can have their usable lifespan extended.

Make Your SD Card More Reliable

Finding solid evidence of SD card failures is difficult. The format is so cheap that in the majority of cases, the owners might have just discarded them in favour of a replacement. On the other hand, this format has become more resilient in the past few years, thanks to advances in card design (something we’ll return to later).


To enjoy trouble-free SD card-based computing, you should choose the largest card for your budget. The thinking behind this is simple: with a limit on the number of times data can be written to SD cards, and the fact that data written to the device should be spread out into untouched areas before going back to the beginning, there is less change of writing to the same area of the card. Choosing 16 GB over 8 GB will cut by half the number of rewrites. In theory this will double the life expectancy of your storage.


It’s also worth shopping for only the big name brands. Yes, it might be tempting to grab a 32 GB card for $10 on eBay or Amazon, but you’re not guaranteed to get a reliable device – or even a working one. If you had some old SD cards you were hoping use, check out all the other ways they can be used instead 7 Awesome Uses for an Old SD Card Whether your old SD card is a meager 64 MB or a massive 64 GB, various projects exist for you to make use of these storage cards. Read More x.

Using Raspberry Pi? Write To RAM, Not The Card

Increasing the lifespan of your SD card is possible by making better use of your device RAM. The following trick can be used on any Linux device, although we’ve tested it on the Raspberry Pi.

Using the tmpfs feature you instruct the device to write to system RAM just like it would to a storage device (you can make a RAMdisk in Windows too What Is A RAM Disk, And How You Can Set One Up Solid state hard drives aren’t the first non-mechanical storage to appear in consumer PCs. RAM has been used for decades, but primarily as a short-term storage solution. The fast access times of RAM makes it... Read More , actually). The result is that there is less writing to the SD card. A bonus is that tmpfs is fast and easy to setup.



To use this, open /etc/fstab in the Raspbian file system (using nano in the command line) and add:

tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0

After saving, restart your Raspberry Pi. This will mount the virtual file system, ready for use. Upon rebooting, /var/log will be mounted as a RAM disk; files written to the directory will be in RAM, for as long as they are needed.

Several other locations can also be used:

tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
tmpfs /var/run tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0
tmpfs /var/spool/mqueue tmpfs defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0

These lines can all be added to /etc/fstab. Note the use of the size= condition, which limits how much space each temporary folder should take up. Remember that the RAM will also be used by the operating system, so setting size limits will avoid Raspbian locking up. Also, take care to only add locations with temporary data to /var/log. These files are all deleted when your Raspberry PI restarts, so anything you need to keep or persist across reboots shouldn’t be stored in RAM.


By moving these locations to RAM, the amount of data written to your Raspberry Pi’s SD card can be reduced, thereby extending its life.

Better Still, Bypass The SD Card Completely!

Most Raspberry Pi users rely on some form of Linux, and as such have in their hands an even better way of both improving performance and reducing the rewrite volume to the SD card.


The solution is by using a USB 2.0 device, which might be a standard thumb drive, perhaps a powered USB HDD or even an SSD. Although the Raspberry Pi is hardwired to boot from the SD card, you can reconfigure the OS so that only the boot partition is found on the SD card, while the root partition is moved to another device.


While you might find the process a little complicated, once the boot partition has been edited to look for the root partition on the USB device, you’ll see that the result is impressive.

Conclusion: SD Cards Are Amazing, So Treat Them Well

muo-oldsdcard-adaptorThe most important thing you can do with SD cards to ensure they last is to buy the named brands and where possible use them for tasks that don’t require constant rewriting (like an always-on torrent downloading megalith How To Turn Your Raspberry Pi Into An Always-On Downloading Megalith Do your part for the global "Linux distribution network" by building a dedicated, secure, torrent-downloading megalith that barely uses 10W of power. It will, of course, be based on a Raspberry Pi. Read More ).

What is perhaps most fascinating is that SD cards are habitual liars, backed up by some very clever software. As revealed by hardware hacker Bunnie Huang at the Chaos Compute Club Congress, SD cards are made with very cheap, defect-riddled flash memory. Creating an illusion of a robust piece of storage media is sophisticated error correction, meaning that the cards are able to display a completely different capacity to the one actually available (you can check your actual capacity with the H2testw tool).

As for Raspberry Pi owners, take advantage of the tips above concerning buying larger storage and using tmpfs to reduce the volume of rewriting on your SD card.

Treat your SD cards well, and they’ll invariably last!


Whatsapp Pinterest

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Peter Scargill
    April 6, 2017 at 7:17 pm

    In your example with several lines putting stuff into RAM..... in /etc/fstab

    With all of those lines in - a Raspberry Pi will not start up... except in debug mode (thankfully).

    If I leave in only the LOG directory line - everything works perfectly but Apache 2 will not start up - if I then remove that line from /etc/fstab and reboot - Apache starts up..

    Thoughts (latest Raspbian on a Pi2) - I see others have done worse - might be a good idea to scrap this until more is known.

  2. Michael
    April 1, 2017 at 10:40 pm

    Hi Christian,

    when using "tmpfs /var/run" I cannot reboot, poweroff, shutdown (only with -f), the message is "Failed to talk to init daemon."

    Keep up the good work and thx a lot!

  3. Sven
    October 21, 2016 at 7:08 pm

    Thanks for bricking my raspberry!!!!

    DON`T DO THAT!!!!

  4. Lukas
    January 7, 2016 at 12:20 pm

    Except : tmpfs /var/run tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0

    is working fine, so just don't map /var/run in tmpfs and after reboot looks fine, otherwise you must unplug raspi from power and plug back, then boot up fine. After reboot the same issue not able to login remotely.

  5. Anonymous
    August 30, 2015 at 4:09 pm

    Thanks for your advice on writing to RAM. You assisted me to start up my Pi in Emergency Mode, with no password login and automatically going to Root User, whereby only reverting the file back to its original self could I restart the Pi as normal.

    Thanks a lot!

  6. Linuxhippy
    December 26, 2014 at 11:38 am

    > plus USB devices are considered more reliable

    Same flash, same reliability.

  7. Simon
    October 23, 2014 at 12:07 pm

    Nice article, thanks.

    I don't understand the recommendation to move to a USB flash drive, surely a USB flash drive is based on the same technology as an SD card and so will also fail after a set number of writes

    What am I missing?

    • Christian C
      October 23, 2014 at 8:27 pm

      The aim as I understand it the root filesystem isn't rewritten as much as other files, plus USB devices are considered more reliable.

      However I suspect that with a good quality SD card, the difference would be difficult to tell except in exceptional cases.