Wednesday, February 27, 2013

Reducing disk writes by putting /var/log in RAM (tmpfs)

**UPDATED 2013-03-01

I've recently grown quite fond of my old Toshiba Satellite* that currently exists in the form of a digital picture frame. I'm still not sure what to do with it but I've started exploring the possibilities of removing xorg completely and focusing solely on a command line interface.

First thing is that I want to make it more robust, i.e. protect the CF-card from excessive disk writes and possible power failure. I could go with a dedicated dist such as Slitaz, Puppy or Tiny Core but I kind of like my own debian system. So I decided to go with reducing disk writes.

I've taken a few steps to reduce disk writes already. But then there is the never ending logging. So I took some of my precious RAM and put /var/log in it. I found some instructions on that here.

To accomplish this I added the following line in /etc/fstab
tmpfs  /var/log  tmpfs  size=4M,defaults,noatime,mode=0755  0  0

So far I'm only using 4 MB but I could probably lower this. I just need to keep it running for a while and see how logrotate works.

To prevent the 4 MB of log space to fill up uncontrollably I've configured logrotate from the default weekly rotation of logs to daily rotation and keeping only 1 day of backlog. I also added a size limit to each log file to 100k. But as far as "man logrotate" tells me this won't affect the logs more than once daily as the logrotate cron job only runs once each day.

As of now I've edited /etc/logrotate.conf accordingly.

# rotate log files daily


# keep 2 days worth of backlogs
rotate 2


The above had little effect on my running system. Turns out many of the logs had separate instructions in:/etc/logrotate.d
Update them accordingly and you should be in business.

* Toshiba Satellite 320CDS
CPU: 233 Mhz Pentium MMX
RAM: 96 MB
HDD: SandDisk Compact Flash 8 GB Extreme IV via Lycom CF 2 IDE Bridge
OS: Debian Gnu/Linux Squeeze