Extend your Pi's SD Card Life with Log2Ram!

Опубликовано: 07 Июль 2026
на канале: Print 'N Play
4,603
172

Here's the link to the Log2Ram Project
https://github.com/azlux/log2ram

Check out my Patreon! Early access to models, project updates, and more!
  / jcprintnplay  

Planning to buy something from Gearbest? Want to support my efforts? Use this link!
https://www.gearbest.com/3d-printers-...

Music - Screen Saver by Kevin MacLeod
https://incompetech.filmmusic.io/song...

Single board computers like the Raspberry Pi have made it super easy to place a computer wherever you need it. Need something to run OctoPrint
for your new 3D printer? Write the OctoPi image to an SD card, stick it in your Pi, and you're ready to go. Want to play some of your favourite
retro games? Write the latest version of RetroPie to an SD card, load it into your Pi, and you're up and running. But one of the limitations
of this setup comes from what it uses for storage. Micro SD cards are cheap and come in a variety of sizes, but weren't really designed with the
abuse an operating system can place on storage in mind. Today, we'll take a look at something that helps eliminate some of that abuse.

Log2Ram is a utility that can be installed on most Linux based operating systems. As its name suggests, it allows your operating system to log to
the RAM on your device instead of directly to the SD Card by creating a virtual disk in RAM. Rather than having to read and write from the card
every time a new line is added to a log, the changes are made in memory, and only pushed to the SD Card on a schedule, or when a controlled shut-down
is done.

Why would you want that? Well, your SD Card is divided up into sectors. Each sector can store a specific amount of information, say 512 bytes. When you write any amount of data,
be it 1 bytes or 512 bytes, it uses one of those sectors. Sometimes, this means taking whats in a sector, combining with what you're trying to write,
erasing the sector, and then re-writing your data. When you're logging multiple bytes of data per second during the regular operation of your device,
this can mean a lot of reading and writing, which can prematurely wear your SD card out

The advantages of this is that logging is faster, and far less abusive to your disk. The disadvantages are that you lose some of your RAM to create
this disk, 40 megabytes by default, and your logs will not be saved in the event of a power outage.

Installing log2ram is simple.

We start by adding the source for the new package to our machine
sudo echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list

Next, we need to add the key for the source
sudo wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -

Now, we can run an apt update to gather the list of software available for our install
sudo apt update

Finally, we run an apt install for log2ram
sudo apt install log2ram

And that should be it. You can take a look at the configuration files by editing the log2ram.conf file located in the /etc directory
Here we have options to change the size of the virtual disk, use an rsync command when moving logs from memory to storage, disable mail for
errors caused by insufficient space in the virtual drive to continue loggingm as well as enabling compatibility for zram.

Logs are written from ram to storage on a daily basis. This is done by using a cron job. If you'd like a different schedule, you can move the log2ram
cron job file from the /etc/cron.daily folder to one of the other ones, such as cron.hourly, cron.weekly, or cron.monthly. If you only want logging
to be done in memory, you can remove the file completely.

With your installation complete, and any configuration changes you want made done, simply issue a reboot to your device to enable log2ram.

Upon rebooting, you can verify that log2ram is working by issuing a
df -h | grep log2ram
and making sure you see the entry for it.
You can also issue the
mount
command and see if you see the log2ram virtual drive listed.

And that's it! Your SD card will now experience less abuse and hopefully live a longer life. If you found this tutorial helpful, please consider
giving me a thumbs up and subscribing to the channel for future videos. If you have a topic you'd like me to cover in the future, let me know in
the comments bellow. And, until next time, stay creative!