Turn off

sudo dphys-swapfile swapoff

Change Size

First of all, tell the OS to not use the swap file anymore (see above).

Now open the following file to change the size of the swap file:

sudo nano /etc/dphys-swapfile

Find the following line and change the number (in MB):


Save the file.

Re-create the new swap file:

sudo dphys-swapfile setup

Let the OS know to use the swap file again and reboot the system (see below).

Turn on

sudo dphys-swapfile swapon
sudo reboot


To expand the lifespan of the SD card used by the Raspberry Pi, you can use Log2RAM to offload the Log files to a RAM disk, which will reduce the number of active writes to the SD card.


sudo apt install rsync
wget https://github.com/azlux/log2ram/archive/master.tar.gz -O log2ram.tar.gz
tar xf log2ram.tar.gz
cd /home/pi/log2ram-master
sudo ./install.sh


To make sure, that the RAM disk is large enough to contain all files in “/var/log”, you should check and configure the max. size of the RAM disk:

sudo nano /etc/log2ram.conf

Find the following line:


Change this number to e.g.:


Save the file.

Reboot the system:

sudo reboot