Home Raspberry Pi OS How to install and use Log2Ram on a Raspberry Pi

How to install and use Log2Ram on a Raspberry Pi

by Pulkit Chandak
sd card increase life

Log2Ram is a program beneficial for the Raspberry Pi to resolve a problem that most of us don’t know about, but eventually, most of us will suffer from. Log2Ram is a program that writes all the logs in the RAM instead of the SD card. We need to dissect this sentence:

What are Logs?

Logs are files in an operating system containing a comprehensive history of all the critical processes. For example, on Raspberry Pi OS, the software manager used to install, remove, and generally manage programs is apt. Since this is an important part of the OS, every action used with apt is recorded and stored on the system. You can view the apt log using:

less /var/log/apt/history.log
APT Log File

APT Log File

Similarly, there are log files like boot.log, which contains information of services required while booting the system; kern.log, which contains information of the changes made to the kernel; btmp, which contains information of failed login attempts (beneficial) and many more like these. You can check the different logs at:

ls /var/log
Log Files on Raspberry Pi OS

Log Files on Raspberry Pi OS

So what is the issue?

Logs are being written to the system constantly because these processes frequently occur while the system is up and running. This is no issue on a good hard disk drive or a solid-state drive, but as we know, the Raspberry Pi runs on a micro SD card. Files being constantly written in the background wear the SD card out and reduce its longevity. So how do we solve this problem? This is where Log2Ram comes into play.

Log2Ram

Instead of writing logs constantly to the SD card, Log2Ram makes the system write the logs to the RAM, which is then transferred to the SD card finally before shutdown (or at a specific time, once every day, if you keep the Raspberry Pi running without downtime). This way, your SD card is safe from abuse, while your logs are preserved just as well.

Installing Log2Ram

To install Log2Ram on the Raspberry Pi OS, enter the following commands in order:

echo "deb http://packages.azlux.fr/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/azlux.list
wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -
sudo apt update
sudo apt install log2ram
Log2Ram Installation

Log2Ram Installation

Finally, you will need to reboot, and Log2Ram will become active on the next boot.

sudo reboot

Check if it is Working.

To check if Log2Ram is active after reboot, enter:

systemctl status log2ram
Log2Ram Status

Log2Ram Status

Suppose this shows a green color-coded active message. As a result, that indicates that Log2Ram is active. Press Q to exit.

Customization

Customize Size

You can change the maximum RAM space that Log2Ram can use. The default value is 40MB, which should be more than enough in most cases. To change the size, open up the config file using:

sudo nano /etc/log2ram.conf
Log2Ram Size Configruration

Log2Ram Size Configuration

Next to ‘SIZE’, you will find 40M written there, which denotes 40 MB. Please change it to whatever value you want. Please do not make it too large, though, because that might create a deficiency of space in the RAM for other valuable things.

Refresh Time

As mentioned before, if you don’t shut down your Raspberry Pi, Log2Ram updates the logs to the SD card once every day. You can change this rate to a lower frequency rate using the command:

sudo systemctl edit log2ram-daily.timer

Now, if you add the line:

[Timer]
OnCalendar=Mon *-*-* 23:55:00
Log2Ram Refresh Rate

Log2Ram Refresh Rate

This will make it refresh once a week, every Monday, at 23:55. Replace Monday with any other day that you want, or the time with what you feel is a better option. You can even make it a monthly process with the line:

OnCalendar=* 1-*-* 23:55:00

This will make it refresh on the first of every month. Alternatively, you can turn it off altogether so that it only refreshes on power off with the command:

systemctl disable log2ram-daily.timer

Potential Issues

There are some considerations to keep in mind while using Log2Ram, which you should know about.

RAM Size

Log2Ram directly takes space on the RAM of the Raspberry Pi. While this should rarely be a problem, there is a chance that you might not even have the tiny amount of space that Log2Ram requires. For example, the 2GB RAM variation of the Raspberry Pi 4 or older 1GB RAM Raspberry Pi 3 will already have a low amount of RAM available to work with. On top of that, if you open up such heavy programs on the RAM, the available space will keep on getting smaller.

It is improbable that you will run into such a problem, but knowing about it will help.

Power Failure

As I mentioned before, Log2Ram updates the logs to the SD card at power down or at the same time every day (if not turned off). If the system is not correctly shut down and there is a power outage without warning, Log2Ram will not update the logs. Therefore, those logs will not exist on the system. Whether using Log2Ram or not, it is always recommended to use a power supply that is unlikely to fail for the sake of your single-board computer.

Uninstall

To uninstall Log2Ram, enter:

sudo apt remove log2ram

This command will take care of the un-installation of the program.

Conclusion

Log2Ram is a very creative solution to a significant problem, which will keep the quality of the SD card as intact as possible and will keep the system quite snappy. It is very much recommended to all the users because it is an issue that every user of the Raspberry Pi will face while using it. You can find all the information that you need about Log2Ram here, on the official Github page. We hope this article was helpful to you. Cheers!

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.