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:
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:
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.
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.
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
Finally, you will need to reboot, and Log2Ram will become active on the next boot.
Check if it is Working.
To check if Log2Ram is active after reboot, enter:
systemctl status log2ram
Suppose this shows a green color-coded active message. As a result, that indicates that Log2Ram is active. Press Q to exit.
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
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.
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
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
There are some considerations to keep in mind while using Log2Ram, which you should know about.
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.
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.
To uninstall Log2Ram, enter:
sudo apt remove log2ram
This command will take care of the un-installation of the program.
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!