SD card lifetime, how to extend

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

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 and retro gaming systems to taking photos from space) 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 insteadx.
7 Awesome Uses for an Old SD Card
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.

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, actually). The result is that there is less writing to the SD card. A bonus is that tmpfs is fast and easy to setup.
What Is A RAM Disk, And How You Can Set One Up
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…


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

The 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).



sudo chmod +x log2ram*
sudo mv log2ram.service /lib/systemd/system/
sudo mv log2ram /usr/local/sbin/
sudo mv log2ram.hourly /etc/cron.hourly/
sudo systemctl daemon-reload
sudo systemctl enable log2ram.service
sudo systemctl start log2ram.service


The SD-card to read only:
$cat /etc/fstab
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat ro,noatime 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime,ro 0 1
tmpfs /tmp tmpfs nodev,nosuid,size=16M 0 0
tmpfs /var/log tmpfs nodev,nosuid,size=16M 0 0
tmpfs /var/lock tmpfs defaults,noatime,mode=0755 0

If you want a long life SD card mount it read only. If you want to store something do it on your internet server or on a local HD