log2ram on raspberry pi banner of data being sent to memory chips

Save Your SD Card: Install Log2Ram on Raspberry Pi

Linux distributions make it easy to keep system logs, and a paper trail helps me understand where things went wrong and how to fix them. As great as logging is, it can lead to an unexpected problem on a Raspberry Pi: constant disk writes degrade SD cards and cause them to fail. In this guide, I’ll show you how to fix this problem once and for all.

Log2Ram can be run on a Raspberry Pi to extend the lifespan of an SD card. Log2Ram works by reducing the number of disk writes used by system logging.

Read on to learn why you need Log2Ram and how to install it on your Pi. Let’s go!

If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!

Introduction to Log2Ram: Why You Might Need It

Raspberry Pi OS will keep logs as a normal part of operation. When a new event needs to be recorded, a disk write will occur. This constant process leads to wear and tear on your SD card. That’s where Log2Ram comes in.

Log2Ram is a program that stores log updates in memory, and then once a day, writes these changes to the disk all at once.

What Is the Benefit of Using Log2Ram?

You may already know that storage devices have limited read/write cycles. Once you exceed this limit, the drive can wear down until it stops functioning entirely. The write limit was rarely a concern for home users when we used hard disks.

However, write limits matter for modern solid-state devices, e.g., SSDs and SD cards. This limit can vary dramatically for SD cards—as low as 3,000 or as high as 100,000, depending on the quality and storage size. And manufacturers don’t always make this specification clear.

hand holding sd card up with question mark

I’ve read user complaints about their Raspberry Pi chewing through SD cards or corrupting them with heavy writing. Therefore, the benefit of using Log2Ram is that it extends the life of your SD card.

Who Is Log2Ram Best For?

If you have a newer Raspberry Pi model (like the Pi 5 or Pi 4), have an excellent SD card, and run only basic programs, you’ll probably never run into this problem.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

However, I recommend running Log2Ram if:

  • You’re using a not-so-great SD card brand, which often has a lower write endurance.
  • You have an older SD card, as older designs had lower write limits.
  • Your SD card storage is 32GB or less, especially if you keep your drive close to full capacity.
  • You host LAMP, email, cryptomining, Minecraft, or other servers on your Pi, as these programs log heavily.

But if you’re unsure, why not protect your SD card if you can? After all, Log2Ram is easy to install and maintain. I’ve been running it for years without issue on a Raspberry Pi 4 with only 2 GB of memory.

How Does Log2Ram Work?

Log2Ram will create a mount point at /var/log that exists on your RAM. Every time a log file is updated, instead of writing to disk, the changes will be stored in memory. Once a day, Log2Ram will transfer these changes from memory to the SD card.

df command showing log2ram ramdisk mounted

There’s one downside you should know about. Because log changes are stored in memory, if your Pi loses power, then any log updates since the last write will be lost.

To give you peace of mind, Log2Ram stores a daily backup of log files in the folder /var/hdd.log and also saves a backup when the Raspberry Pi is shut down properly.

I haven’t had to worry about this issue because my Pi is rock-solid, which is also why so many ground-breaking projects have used the Pi in surprising ways. If you love to tweak your Pi to its maximum potential, I highly recommend Log2Ram.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Log2Ram Installation Process

Now that you know how it works, let’s install Log2Ram. Open a terminal and put your typing gloves on—or copy/paste the commands below, I won’t judge.

Prerequisites for Log2Ram

First, make sure you have the most recent system packages:

  • Update your system:
    sudo apt update
    sudo apt upgrade
  • Install rsync, which you probably already have:
    sudo apt install rsync

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

Download Log2Ram

Next, download and extract the Log2Ram package from its official GitHub repository:

  • Download using wget:
    wget https://github.com/azlux/log2ram/archive/master.tar.gz -O log2ram.tar.gz
  • Extract the archive using tar:
    tar xzf log2ram.tar.gz
terminal showing download and extraction of log2ram

Install Log2Ram

Finally, install Log2Ram with the script provided:

  • Run the installation script, which will copy files and enable autostart:
    cd log2ram-master
    sudo ./install.sh
  • Reboot to activate:
    sudo reboot
  • Check if Log2Ram is running properly:
    systemctl status log2ram

    terminal showing status of log2ram activeIf you see “active,” it’s working.

That’s it—you’re done! For most people, Log2Ram will work right out of the box. It’s a set-it-and-forget-it way of saving your SD card.

If you’re curious about Log2Ram’s other features—especially if you’re running multiple servers on your Pi—then keep reading to learn how to modify its configuration.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now
Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Log2Ram Configuration

Now that you’ve installed Log2Ram, let’s view its basic settings. Log2Ram’s configuration can be found in the /etc/log2ram.conf file. Open it using a text editor like Nano and take a look around.

Increasing Cache Size

In the config file, the “SIZE” parameter is the most important. The cache size tells Log2Ram how much physical memory to reserve for logs.

In the past, most issues with Log2Ram were caused by the default being too low. Thankfully, the newest version has increased the default cache size to 128 MB. If you’re only running a basic setup with SSH, this limit should be good enough.

However, if like me you’re running multiple servers that log extensively, such as Pi-Hole or UniFi Network Server, you’ll encounter issues if the cache runs out. For example, Log2Ram might give you an “out of memory” error, or the service won’t launch on startup for some reason.

The easiest solution to these problems is to increase your cache size. Here’s how:

  • Open Log2Ram’s config file:
    sudo nano /etc/log2ram.conf
  • Change SIZE to 256M (or whatever amount you think you need):
    log2ram config showing increased cache size setting
  • Change LOG_DISK_SIZE to double your SIZE setting:
    log2ram config showing log_disk_size setting
  • Reboot for changes to take effect:
    sudo reboot
  • Check if everything is still working:
    df -hT
    systemctl status log2ram

Other Configuration Options

Log2Ram has other features you can change, such as enabling notifications, adding custom log directories, and changing the time interval between disk writes. Most users won’t need to tinker with these settings, so I won’t cover them here.

But if you’re wondering how they work, you can read more about these features on the official GitHub. This page also has a useful troubleshooting section if you run into issues other than the ones mentioned above.

That was pretty easy, right? Log2Ram is a neat little program for protecting your SD card, and I hope it serves you well as it has for me.

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

How would you rate this article?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Spread the word!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Similar Posts