My LoRaWAN gateway (“Contributing an IoT LoRaWAN Raspberry Pi RAK831 Gateway to The Things Network” is running and working great now for more than a month and it already has transmitted more than 30k messages:

This creates a lot of log entries on the micro SD card of the Raspberry Pi. To avoid writing too many times log data, I have installed Log2Ram.

By default, the Raspberry Pi uses a micro SD card as storage device. The SD card as a FLASH device is subject of ‘wear-out’: each FLASH block can only be erased and written a limited number of time, and after that it fails. The ‘wear leveling’ of the disk device will allocate and use a new flash block in that case, but after some time there are no free blocks any more and the system will fail.

A running gateway will create lots of log messages stored on the card, and I have read reports that depending on the card and card size it might fail after 6-18 months.

As most of the data written as a gateway are the Linux log files, there is a solution to reduce the number of writes to the SD card using Log2Ram. It creates the mount point /var/log in RAM, so any writes to /var/log will be written to the RAM disk. Every hour, a cron job will write the RAM disk to FLASH, or at the time of a shutdown. So this greatly reduces the stress on the SD card.

Installation and setup is easy:

Go to the pi home directory:

cd /home/pi

Clone there the log2ram git repository:

git clone https://github.com/azlux/log2ram.git

Change directory to the downloaded repository folder:

cd log2ram

Make the installation script executable:

chmod +x install.sh

Install it:

sudo ./install.sh

Change the log size value to 128M:

sudo nano /etc/log2ram.conf

Save the file (CTRL-X, yes, ENTER), then reboot:

sudo reboot

To check if it was working, use

df -h

This should show the new disk:

In addition to this, check with

mount

which should show our mount point:

log2ram on /var/log type tmpfs (rw,nosuid,nodev,noexec,relatime,size=131072k,mode=755)

That’s it! With this, writing to FLASH should now be greatly reduced. Time for muffins!

Happy Logging 🙂

Links