How to reduce the wear on your SD card in your Raspberry Pi digital photo frame

Three years ago, I first wrote about the two things that often break after a few years in a digital picture frame. Besides the power supply, I mentioned the SD card as the key component with a limited shelf life.

Tested on a Raspberry Pi 4 with 4 GB, and OS Bookworm (Nov 2023).

I recently met with Dmytro in Wiesbaden, who discovered his love for digital picture frames through this blog and went on to set up a small business based on the DAK Board software.

One of my first questions to him was if he had seen many repair issues because of broken SD cards.

Dmytro is an electrical engineer and obviously knows far more about electronics than I do. He told me about Log2Ram, a piece of software that has been around for a number of years but I had never come across.

Log2Ram is an ingenious solution designed to extend your SD card’s life. It’s a simple yet effective tool that reduces the number of write operations to the SD card by utilizing the Raspberry Pi’s RAM for temporary storage of log files. This approach minimizes the wear on the SD card, ensuring a longer lifespan and stable operation.

One might argue that a digital picture frame would not have so many write operations compared to other applications like a web server. After all, it is mainly reading images and displaying them.

However, most of the frequent writing comes from system logs, where Raspberry Pi’s actions are recorded. This constant activity can significantly shorten the SD card’s lifespan, leading to failure and data loss – a frustrating and costly issue.

How Log2Ram Works

Log2Ram creates a virtual storage space in the RAM for log files, which are typically written to the SD card. A real game-changer.

It drastically cuts down the wear-intensive write operations to the SD card by storing these files in RAM. The logs are periodically written back to the SD card in a controlled manner, striking a balance between preserving memory and protecting the card.

Unless you are hunting for bugs and can filter and understand log data, you will never look at your logs in the context of a digital photo frame anyway.

Setting Up Log2Ram

Credit for this wonderful piece of software goes to Azlux, who describes it in detail on his GitHub page.

Here is a quick summary based on my findings when I installed the software. I didn’t manage to get it going right away, but I will share the issue with you and how you can get going in no time.

Connect to your Raspberry Pi via Terminal and enter

echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bookworm main" | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg  https://azlux.fr/repo.gpg
sudo apt update
sudo apt install log2ram

Before we proceed, reduce existing log information so that the maximum size doesn’t exceed the reserved space on the RAM drive.

I hadn’t done this and wondered why the service was not running. So, don’t skip this part.

Do this by entering

journalctl --vacuum-size=20M
sudo systemctl restart systemd-journald

No, it’s time to take a look at the configuration file.

sudo nano /etc/log2ram.conf

These are the settings that I found appropriate for use in conjunction with a digital picture frame:

  • SIZE defines the size the log folder will reserve into the RAM. The default is set to 40 MB. Given the fact that Pi3D PictureFrame is not very RAM-hungry and you probably have system reserves, I would suggest a value of 256 MB.
  • MAIL: Change to “false”

So, to summarize, your config file should look like this:

# Configuration file for Log2Ram (https://github.com/azlux/log2ram) under MIT license.
# This configuration file is read by the log2ram service

# Size for the ram folder, it defines the size the log folder will reserve into the RAM.
# If it's not enough, log2ram will not be able to use ram. Check you /var/log size folder.
# The default is 40M and is basically enough for a lot of applications.
# You will need to increase it if you have a server and a lot of log for example.
SIZE=256M

# If there are some errors with available RAM space, a system mail will be send
# Change it to false and you will have only a log if there is no place on RAM anymore.
MAIL=false

# Variable for folders to put in RAM. You need to specify the real folder `/path/folder` , the `/path/hdd.folder` will be $
# example : PATH_DISK="/var/log;/home/test/FolderInRam"
PATH_DISK="/var/log"

# **************** Zram backing conf  *************************************************

# ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs
ZL2R=false
# COMP_ALG this is any compression algorithm listed in /proc/crypto
# lz4 is fastest with lightest load but deflate (zlib) and Zstandard (zstd) give far better compression ratios
# lzo is very close to lz4 and may with some binaries have better optimisation
# COMP_ALG=lz4 for speed or Zstd for compression, lzo or zlib if optimisation or availabilty is a problem
COMP_ALG=lz4
# LOG_DISK_SIZE is the uncompressed disk size. Note zram uses about 0.1% of the size of the disk when not in use
# LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE
# lzo/lz4=2.1:1 compression ratio zlib=2.7:1 zstandard=2.9:1
# Really a guestimate of a bit bigger than compression ratio whilst minimising 0.1% mem usage of disk size
LOG_DISK_SIZE=100M

Save and close.

You can combine the logging to RAM with another app that compresses the log data stored in memory, but unless you are really low on memory in your setup, it’s probably not relevant for the picture frame use case.

Reboot your Pi and then enter

systemctl status log2ram

If you see something like

● log2ram.service - Log2Ram
     Loaded: loaded (/etc/systemd/system/log2ram.service; enabled; preset: enabled)
     Active: active (exited) since Sun 2023-11-19 18:57:34 CET; 1h 28min ago
    Process: 460 ExecStart=/usr/local/bin/log2ram start (code=exited, status=0/SUCCESS)
   Main PID: 460 (code=exited, status=0/SUCCESS)
        CPU: 1.287s

followed by a number of log entries, you are fine.

Exit with “q”.

You are all set!

The other way to a long SD card life

Dmytro mentioned another rule of thumb to stay clear of SD card troubles: The capacity should be about thirty times larger than your operating system image.

In the case of Raspberry Pi Lite and Pi3D Picture Frame, we are talking about roughly 1 GB. So make sure that you buy at least a 32 GB card. The price difference between a 16 GB and a 32 GB card is not significant, so if in doubt, choose the larger capacity.

For a selection of durable SD-cards look here.

Conclusion

With Log2Ram, your digital picture frame will enjoy a longer lifespan and see performance improvements. Frequent SD card write operations can slow down your Raspberry Pi, so reducing these could lead to smoother image transitions and faster loading times.

Moreover, the risk of data corruption and unexpected crashes diminishes, ensuring a more reliable display of your beloved photos.

Was this article helpful?


Thank you for your support and motivation.


Scroll to Top