Limit SD Card writes on Rasberry Pi using Ramlog

Home/Computer How-To, Tech/Limit SD Card writes on Rasberry Pi using Ramlog

Limit SD Card writes on Rasberry Pi using Ramlog

A SD card has a limited amount of writes it can handle. The Raspberry Pi will write to log files a lot and reduce the lifetime of your SD Card.

Update 3-2-2016: RamLog seems not to be compatible with Debian Jessie. I haven’t tried it yet but I have found a blog that might offer a solution for Jessie.

A simple solution is to use Ramlog which creates a temporary disk in memory where the logfiles are stored and updated. At boot the log files are loaded in memory. At shutdown they are saved to SD Card. During runtime writes are done in memory and not to disk!

How to install:
sudo apt-get install rsync
sudo apt-get install lsof
wget http://www.tremende.com/ramlog/download/ramlog_2.0.0_all.deb
sudo dpkg -i ramlog_2.0.0_all.deb

Now you need to modify some config files:
sudo nano /etc/init.d/ramlog

Add the next two lines in the init part of the config (the part that starts with: #BEGIN INIT INFO). Include the # character!!
# X-Start-Before: rsyslog
# X-Stop-After: rsyslog

Now edit /etc/init.d/rsyslog
sudo nano /etc/init.d/rsyslog

add ‘ramlog’ to the following two existing lines
# Required-Start: $remote_fs $time ramlog
# Required-Stop: umountnfs $time ramlog

sudo insserv
sudo reboot

Reboot twice!!

After the second reboot check the ramlog log file for errors:

sudo cat /var/log/ramlog
You’ll probably see messages saying that you need to stop other daemons before being able to load/start ramlog. For example Samba or Cups. In that case find the appropriate file in /etc/init.d

For example Samba:

sudo nano /etc/init.d/samba

Add ‘ramlog’ to the following two existing lines
# Required-Start: $network $local_fs $remote_fs ramlog
# Required-Stop: $network $local_fs $remote_fs ramlog

For Cups:
sudo nano /etc/init.d/cups

add ‘ramlog’ to the following two existing lines:
# Required-Start: $syslog $remote_fs ramlog
# Required-Stop: $syslog $remote_fs ramlog

Those lines makes sure ramlog is started before the other daemon (like cups or samba) is started.

After changing those config files, do a sudo insserv again and reboot.

By | 2016-10-30T21:20:15+00:00 January 17th, 2015|Computer How-To, Tech|5 Comments

About the Author:

5 Comments

  1. Peter Scargill June 4, 2015 at 11:17 - Reply

    HI

    I installed RAMLOG – followed the instructions but I\’m unclear about the last bit – here is my ramlog file after rebooting twice – can you suggest what to go next?

    Jun 04 10:04:14 Enabling ramlog… [ OK ]
    Jun 04 10:10:02 Stopping ramlog: Error: ramlog is not running [fail]
    Jun 04 10:10:03 Starting ramlog-tmpfs 2.0.0: Error: /var/log is in use… [fail]
    Jun 04 10:10:04 The list of open files: (You need to close below daemons if you want to start/stop ramlog manually)

    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    node 2020 root 1w REG 179,6 10512747 652817 /var/log/node-red.log
    node 2020 root 2w REG 179,6 10512747 652817 /var/log/node-red.log
    Jun 04 10:10:04 Test result: ramlog cannot be started or stopped at the moment.
    Jun 04 10:11:24 ramlog: Cannot find shutdown flag file. [warning]
    Jun 04 10:11:24 Stopping ramlog: Error: ramlog is not running [fail]
    Jun 04 10:11:25 Starting ramlog-tmpfs 2.0.0: Error: /var/log is in use… [fail]
    Jun 04 10:11:27 The list of open files: (You need to close below daemons if you want to start/stop ramlog manually)

    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    node 2028 root 1w REG 179,6 10513541 652817 /var/log/node-red.log
    node 2028 root 2w REG 179,6 10513541 652817 /var/log/node-red.log
    Jun 04 10:11:27 Test result: ramlog cannot be started or stopped at the moment.

    • Alexander June 4, 2015 at 23:50 - Reply

      Hi,
      Your log file says /var/log/node-red.log is open which causes the start of ramlog to fail.
      check your /etc/init.d folder if there is some file: node-red
      If this file exits, continu reading my article.
      sudo nano /etc/init.d/node-red (if this one exists)

      Add ‘ramlog’ to the following two existing lines
      # Required-Start: $network $local_fs $remote_fs ramlog (something which looks like this)
      # Required-Stop: $network $local_fs $remote_fs ramlog (something which looks like this)

      Hope this helps, else send me the content of that node-red file when it exists.

      best regards,
      Alexander

  2. David Aldrich January 30, 2016 at 21:55 - Reply

    Hi

    I have tried installing Ramlog on my Pi 2 to reduce disk access (my system partition is on a USB HDD and I want the drive to sleep).

    Having installed Ramlog, I see the following warnings in /var/log/ramlog after rebooting the Pi (twice):

    Jan 28 20:40:51 Enabling ramlog… [ OK ]
    Jan 28 20:45:34 ramlog: Previous shutdown/restart was unclean, some logs may be lost. [warning]
    Jan 28 20:45:34 Starting ramlog-tmpfs 2.0.0: [fail]
    Jan 28 20:46:35 ramlog: Previous shutdown/restart was unclean, some logs may be lost. [warning]
    Jan 28 20:46:35 Starting ramlog-tmpfs 2.0.0: [fail]

    Do you know how I can fix these warnings please?

    (I am running Raspbian Jessie on a Pi 2).

    Best regards

    David

Leave A Comment