Avatar

Hey folks, I post some articles about technology and tricks & tips how to do some stuff in dev environment. 🚀
My CV page is here.

Protecting Your Orange Pi's SD Card: Installing log2ram on Debian Bookworm

2 minutes read

Table of Contents


As an automation and infrastructure engineer, I try to treat my local self-hosted environments with the same architectural rigor I apply to client deployments. Lately, I’ve been running several local servers and containerized services via Docker on an Orange Pi Zero 3. It’s a highly capable little ARM board, but running infrastructure off a microSD card—even a high-endurance one—introduces a classic hardware bottleneck: IOPS (Input/Output Operations Per Second).

When you are self-hosting, your /var/log directory gets hammered with constant, rapid, small-file writes. Left unchecked, this constant chatter will eventually degrade the flash memory and kill the drive, taking your services offline.

While it might be tempting to mount an SMB share from your router to offload these logs and save the disk, that introduces new architectural flaws. Live logging over SMB causes high CPU overhead on consumer routers. Worse, if the network drops even momentarily, logging daemons on your server will hang in an uninterruptible sleep state (D-state), potentially taking down the whole OS.

The standard solution for single-board computers is log2ram.

log2ram creates a small RAM disk (tmpfs) for your logs. All the rapid IOPS happen in memory (which is incredibly fast and has infinite write endurance). Once a day, or gracefully upon system shutdown, it syncs the logs from RAM back to the physical SD card.

Here is how to set it up on the official Orange Pi OS (Debian Bookworm).

Note: If you are running Armbian, stop here. Armbian includes log2ram natively. This guide is for the official Orange Pi OS images where it is missing by default.

Prerequisites #

Before we begin, ensure your system is up to date and that you have rsync installed. While log2ram can use standard copy commands, rsync is significantly faster and safer for syncing logs back to disk.

sudo apt update && sudo apt install rsync -y

curl -L https://github.com/azlux/log2ram/archive/master.tar.gz | tar zxf -

cd log2ram-master
chmod +x install.sh
sudo ./install.sh
cd ..
rm -r log2ram-master

Then:

sudo vi /etc/log2ram.conf

Find and modify these two lines:

  • Change SIZE=40M to SIZE=128M (or 256M)
  • Change USE_RSYNC=false to USE_RSYNC=true

After that need to reboot the host. I’ll show how to do it properly:

sudo shutdown -r

Verifying the Installation #

Once your Orange Pi Zero 3 comes back online, run this command to confirm your logs are now sitting in memory:

~ $ df -hT | grep log2ram

log2ram        tmpfs     128M   22M  107M  17% /var/log.hdd

all tags