Raspberry Pi 4 RAM disk

Frequent writing or overwriting of data negatively affects the lifespan of an SD card.

For applications that often use temporary data (e.g., sensor values for comparative calculations) that are no longer required after a restart, it is therefore advisable to write these to a RAM disk.

Another advantage of a RAM disk is that access (write and read) is much faster than with the SD card.

When equipping the Raspberry Pi 4 with RAM of 1 GB and upwards, it is not a problem to channel off 50 or 100 MB of this for a RAM disk.

To create a RAM disk, proceed as follows:

  • Create a mount point:
sudo mkdir /mnt/ramdisk

-Enter it in /etc/fstab, so that a RAM disk is automatically generated upon startup:

sudo nano /etc/fstab
tmpfs /mnt/ramdisk tmpfs nodev,nosuid,size=50M 0 0

This allows you to save 50 MB of data to /mnt/ramdisk. After a restart, you can use

sudo df -h

to display whether the RAM disk was created successfully.