The Modern Way to Enable ZRAM on Raspberry Pi
ZRAM creates a compressed block device directly inside RAM and uses it as high-speed swap. Compared to writing swap pages to a slow microSD card, ZRAM is orders of magnitude faster and dramatically reduces flash wear.
In 2018, enabling ZRAM meant downloading custom shell scripts and writing manual systemd
units. In 2026, Debian and Raspberry Pi OS include systemd-zram-generator right
in the official repositories — no third-party scripts required.
1. Install systemd-zram-generator
2. Configure ZRAM with zstd Compression
Create or edit /etc/systemd/zram-generator.conf:
Add the following configuration (using 50% of RAM up to 4 GB with fast zstd
compression):
zram-size = min(ram / 2, 4096)
compression-algorithm = zstd
swap-priority = 100
3. Optional: Disable SD-Card Swap
If you want to avoid swap writes to your microSD card completely, disable
dphys-swapfile (if installed):
4. Activate and Verify
Reload systemd and start the generated ZRAM swap unit (or simply reboot):
You should now see /dev/zram0 listed with zstd compression and
priority 100. That's all it takes in 2026 — clean, maintainable, and fully
managed by systemd.

