Log2Ram on Raspberry Pi’s

Well what is log2ram?

log2ram is a tool that moves your system’s log directory [/var/log] into RAM by using a tmpfs mount, then periodically syncs the logs to your SD card. This dramatically reduces writes to the SD card, extending its lifespan.

It’s a common concern for Raspberry Pi setups that run 24/7.

I do run a few 24/7 and that’s why i wanted to write this post, to inform and educate others : P

Prerequisites

  • Raspberry Pi running Raspberry Pi OS (or any Debian-based distro)
  • Internet connection
  • Terminal access (SSH or direct)

Step 1: Update your system:

Always start with a fresh update:

sudo apt update && sudo apt upgrade -y

Step 2: Install log2ram

Option A: Install via APT (Recommended)

echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ stable 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 log2ramCode language: PHP (php)

Add the repository and install

Option B: Install from GitHub

curl -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz
tar xf log2ram.tar.gz
cd log2ram-master
sudo ./install.shCode language: JavaScript (javascript)

Now that we’re done installing, let’s configure it.

Step 3: Configure log2ram

Open the configuration file:

sudo nano /etc/log2ram.conf

P.S. settings to review:

SettingDefaultDescription
SIZE40MRAM allocated for logs. Increase if logs fill up.
USE_RSYNCtrueses rsync for syncing. Recommended.
MAILtrueSends email alerts if RAM log fills up.
PATH_DISK/var/logThe directory moved to RAM.
ZL2RfalseEnables zram compression (advanced).

Example: Increase RAM size to 128MB

SIZE=128M

Save and exit: CTRL+X, then Y, then hit Enter.

Step 4: Reboot

log2ram takes effect after a reboot:

sudo reboot

Step 5: Verify it’s working

After rebooting, check that log2ram is active:

sudo systemctl status log2ram

You should see active (running).

Also verify the mount:

df -h | grep log2ram

You should see a tmpfs entry mounted at /var/log.

Useful commands

CommandDescription
sudo systemctl status log2ramCheck service status
sudo systemctl restart log2ramRestart the service
sudo log2ram writeManually sync logs to disk
sudo journalctl -u log2ramView log2ram logs

Uninstalling log2ram

If installed via APT:

sudo apt remove log2ram

If installed from GitHub:

cd log2ram-master
sudo ./uninstall.sh

Then reboot to restore normal log behavior.


Tips and troubleshooting

Logs not persisting after reboot?
This is totally expected for in RAM logs between sync intervals.

log2ram syncs on a schedule and on shutdown.

Ensure your Pi shuts down cleanly (avoid hard power cuts) -> possibly, get a UPS (link)

“Not enough space” errors
Increase the SIZE value in /etc/log2ram.conf and reboot.

Want logs to sync more frequently?
You can trigger a manual sync anytime with sudo log2ram write.

Although exhaustive, please refer to the official documentation by azlux on Github

Peace out ✌︎㋡


Comments

Leave a Reply

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