Manuel Bauer

Raspberry Pi: Disable swapfile

The default Raspberry Pi OS / Raspbian distribution for the Raspberry Pi ships with a default 100 MB swapfile which is stored on the SD card.

If the swap space is not needed this file can be removed to reduce the amount of writes to the SD card for a improved lifetime.

To disable the swap file only these two commands are required. The first one disables the automatic swapfile creation at reboot, the second one disables the swapfile itself. Please ensure that enough free memory is available, because the swapfile content will be moved to memory.

sudo systemctl disable dphys-swapfile

sudo systemctl stop dphys-swapfile