REDUCING SD CARD WRITES USING TMPFS

Screen shot of webpage I introduced a feature on my mains frequency website that calculates the average mains frequency over a 24-hour period. It maintains a file of the last 86400 readings and recalculates the average every second. It writes this file to the SD card and I was concerned about the impact this may have on the card's lifetime. I changed the way this feature worked so that the file was on placed on a tmpfs filesystem, essentially only ever in volatile memory, in order to spare the SD card. A tmpfs filesystem can be set up easily following the steps below.

Set up a new directory:

sudo mkdir /virtual

Edit /etc/fstab and add a record for /virtual, highlighted below. The 1M is the upper limit for the total size after which swap may occur and the noatime disables file access times from being updated.

proc/procprocdefaults0 0
/dev/mmcblk0p1/bootvfatdefaults0 2
/dev/mmcblk0p2/ext4defaults,noatime0 1
none/virtualtmpfssize=1M,noatime0 0
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that

Mount the new filesystem.

sudo mount -av

And you're ready to go!