Raspberry Pi: Extend the life of your SD with GNU / Linux

SSDs or solid disks as they are known, is not a completely new technology since it has been on the market for several years, however compared to HDDs (hard disks) it is still a baby in diapers. However, the Raspberry Pi It has neither HDD nor SSD, but rather an SD, which has been a memory card ... like a pendrive, according to Wikipedia:

Secure Digital (SD) is a memory card format for portable devices such as digital cameras, mobile phones, laptops, and even game consoles (both desktop and portable), among many others.

If you live in Spain and decide to buy your Raspberry Pi there in Spain, as if you live in another country and opt for eBay, Amazon or any local store, your Raspberry Pi will come with an SD, which has its pros and cons. First of all, in some cases it will work faster than an HDD, but it has a shorter useful life, that is, it will last less, so here are several tips to extend the life of the SD of your Raspberry Pi.

The main problem with SD cards is their limited writing capacity. That is, we can only write a maximum number of times or data in a given sector / space, it is not that we can write, erase, rewrite and so on indefinitely, we cannot do that forever, the time will come when it cannot be keep writing to the SD.

Therefore, here are some tips to extend the life of our SD on the Raspberry Pi:

  1. A higher capacity SD: It's simple, if we have an 8GB SD we have X space to write information, that space has a limited amount of reading and writing, but if the SD is (for example) 16GB then we will have more space, which translates into no it will be necessary to write so many times in the same area, that is, there is more space inside the SD where to put data.
  2. Buy from prestigious brands: It is not a secret, as it happens with the SD it happens with other hardware components. For example smartphones, we can buy a Chinese one that will cost us $ 30 and apparently according to the hardware specifications it can do almost the same as a $ 300 Nexus, however, in the long run the rare brand (Chinese) does not work. With the SD it is the same, there are many manufacturers but recognized as a good brand, with quality there are not so many. It is always good to Google for SD manufacturers with good quality, then see if any Raspberry Pi store in Spain or your locality has these SDs in stock. Draw your own conclusions regarding value for money.
  3. Set Linux to write more to RAM and less to SD: Similar to point 1, the less is written in the SD, the better. We can achieve writing more to RAM and less to SD using tmpfs

Table of Contents

Using tmpfs

To tell the system to write more to RAM and less to the storage device (in this case, SD) just add a line to / etc / fstab. In that line we indicate which folder we want to be mounted in RAM and not in SD, for example:

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

By the way, if you need more than 100mb for that partition, modify that value on the line, putting a maximum size we are making sure that it does not consume all the RAM. Then restart the computer and that's it.

Clarification, everything that is mounted with tmpfs (for example, / var / logs) will be lost when the computer is restarted, that is, when they restart they will not have the logs, they will be blank, and so on for each folder they mount.

The end!

These tips are optimal well for your Raspberry Pi as well as if they have a PiPad. I do not know for what other equipment would be useful because, I do not know other hardware that does not work with an HDD or SSD and yes with an SD card, come on, unless it is not a camera 🙂

I hope you have found it interesting, especially knowing the tip of how tmpfs works


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

9 comments, leave yours

Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Laegnur said

    Good

    Another option to extend the useful life of the SD, is to pass the system partition from the SD to a USB HD, and use the SD only as a boot ...

  2.   zagur said

    Man, I don't think it is a good solution to mount the logs in memory, since RPi only has 512 MB of RAM ... What Laegnur says has much more logic, use the SD as a boot and an external hard disk for / var and even / home.

  3.   Mr. Linux said

    It is good to inform that not all SDs are compatible with the Raspberry Pi, I leave a link where it is detailed which SDs are and are not compatible.
    http://elinux.org/RPi_SD_cards#SD_card_performance.

  4.   vidagnu said

    Excellent article, I think that each option has its pros and cons, putting a hard drive in your raspberry removes portability, increases its size, etc. I think the best thing is to leave it as is, anyway SD are cheap.

    Regards,

  5.   Vctrsnts said

    Good

    This is my 1st comment on this website that I follow. I have an RPI acting as a 24 × 7 server with amule and transmission connected to an HD, the way they are recommended in the case of using the RPI as a 24 × 7 server, is that in the SD only there is the / boot partition and that everything the rest of the partitions are inside the HD, being necessary, to have an HD connected (as Laegnur says)
    And so far, I have not had any problem ... And that lasts .... 😉

  6.   Nestor said

    I recently added an SSD and an HD to my desktop PC and this is perfect for me.

    To my SSD I have installed Wheezy in ext4 and added to the fstab

    UUID = xxx / ext4 default, noatime, nodiratime, discard 0 1
    tmpfs / tmp tmpfs defaults, noexec, nosuid 0 0
    tmpfs / var / run tmpfs size = 1024M, nr_inodes = 10k, mode = 777 0 0
    tmpfs / var / lock tmpfs size = 1024M, nr_inodes = 10k, mode = 777 0 0
    tmpfs / var / log tmpfs size = 1024M, nr_inodes = 10k, mode = 777 0 0

    and I had the misfortune to suffer a power outage that same day and as a result, the root was self-assembling as "read only". With a mount -o remount, rw would be solved but I don't think it's a good idea to walk around with a corrupted partition.

    From another system I did the fsck and also the check from gparted and it continued with the same problem.
    I have fixed it by reinstalling in btrfs.

    I ask. Is it safe to make / var / log volatile? There is nothing important there that the system needs to recover from a bad shutdown?

    I ask because it is very strange what has happened to me. I have been using Linux since 2011, I suffer from power outages but nothing like this has ever happened to me. The same day that I mounted with tmpfs to / var / log and the other directories, that happens to me.

  7.   Ainus Solheim said

    Ahem a long time ago I wrote a manual for Debian ARM to extend the life of an SD, in raspberry it is the same and it can be applied, this is much better, you are not bad but some more details were missing.

    http://kirbian.wordpress.com/2013/01/11/reduce-disk-write-sdcard/

  8.   mitcoes said

    Every day there are more SDD disks and mixed SDD + HDD configurations and this command would also extend their useful life.
    And since RAM is pretty cheap now, it wouldn't hurt to delve into various settings that might help improve desktop performance as well.

    PS: I would like someone to write articles about printers, especially multifunction b / w laser, the Brother have done well to date, but the last model I ordered has given me problems with the scanner's sheet feeder - I will to return - and I have gone to look for comparisons and opinions, and they are conspicuous by their absence, both in Spanish and in English -

    There is no "all or very or phoronix" for printers - in case someone wants to undertake it -, but in the meantime, if someone works selling these multifunction B / W laser models so used in small offices or simply selling inks, they could collect the satisfaction of their customers this type of models and share it here or where it seems most appropriate by communicating it.

  9.   Mariano said

    Thanks for the info. Very useful. Successes!