How to add zRAM on Ubuntu 25.04
zRAM is a compressed block device in RAM, used for swap or cache, which can improve performance on systems with limited RAM.
Enable zRAM on Ubuntu 25.04 Ubuntu already includes a service for zRAM via the systemd package, typically systemd-zram-generator
Install the zram-generator package
sudo apt update
sudo apt install systemd-zram-generator
Output
root@vps:~# sudo apt update
sudo apt install systemd-zram-generator
Hit:1 http://archive.ubuntu.com/ubuntu plucky InRelease
Get:2 http://archive.ubuntu.com/ubuntu plucky-updates InRelease [126 kB]
Get:3 http://security.ubuntu.com/ubuntu plucky-security InRelease [126 kB]
Get:4 http://archive.ubuntu.com/ubuntu plucky-backports InRelease [126 kB]
Get:5 http://archive.ubuntu.com/ubuntu plucky-updates/main amd64 Packages [18.1 kB]
Get:6 http://security.ubuntu.com/ubuntu plucky-security/main amd64 Packages [17.2 kB]
Get:7 http://archive.ubuntu.com/ubuntu plucky-updates/main Translation-en [7,340 B]
Get:8 http://archive.ubuntu.com/ubuntu plucky-updates/main amd64 Components [14.7 kB]
Get:9 http://archive.ubuntu.com/ubuntu plucky-updates/restricted amd64 Packages [46.6 kB]
Get:10 http://archive.ubuntu.com/ubuntu plucky-updates/restricted Translation-en [11.8 kB]
Get:11 http://archive.ubuntu.com/ubuntu plucky-updates/restricted amd64 Components [212 B]
Get:12 http://archive.ubuntu.com/ubuntu plucky-updates/universe amd64 Packages [11.2 kB]
Get:13 http://archive.ubuntu.com/ubuntu plucky-updates/universe Translation-en [5,328 B]
Get:14 http://archive.ubuntu.com/ubuntu plucky-updates/universe amd64 Components [752 B]
Get:15 http://archive.ubuntu.com/ubuntu plucky-updates/multiverse amd64 Packages [14.0 kB]
Get:16 http://archive.ubuntu.com/ubuntu plucky-updates/multiverse Translation-en [2,836 B]
Get:17 http://security.ubuntu.com/ubuntu plucky-security/main Translation-en [6,932 B]
Get:18 http://security.ubuntu.com/ubuntu plucky-security/main amd64 Components [14.7 kB]
Get:19 http://security.ubuntu.com/ubuntu plucky-security/restricted amd64 Components [212 B]
Get:20 http://archive.ubuntu.com/ubuntu plucky-updates/multiverse amd64 Components [212 B]
Get:21 http://security.ubuntu.com/ubuntu plucky-security/universe amd64 Packages [10.4 kB]
Get:22 http://security.ubuntu.com/ubuntu plucky-security/universe Translation-en [5,088 B]
Get:23 http://security.ubuntu.com/ubuntu plucky-security/universe amd64 Components [748 B]
Get:24 http://security.ubuntu.com/ubuntu plucky-security/multiverse amd64 Components [212 B]
Get:25 http://archive.ubuntu.com/ubuntu plucky-backports/main amd64 Components [212 B]
Get:26 http://archive.ubuntu.com/ubuntu plucky-backports/restricted amd64 Components [216 B]
Get:27 http://archive.ubuntu.com/ubuntu plucky-backports/universe amd64 Components [216 B]
Get:28 http://archive.ubuntu.com/ubuntu plucky-backports/multiverse amd64 Components [216 B]
Fetched 568 kB in 1s (923 kB/s)
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
The following packages were automatically installed and are no longer required:
cloud-init-base python3-jsonpatch
eatmydata python3-jsonschema
libeatmydata1 python3-jsonschema-specifications
python-babel-localedata python3-markupsafe
python3-babel python3-passlib
python3-jinja2 python3-referencing
python3-json-pointer python3-rpds-py
Use 'sudo apt autoremove' to remove them.
Installing:
systemd-zram-generator
Create configuration file
Create a config file at /etc/systemd/zram-generator.conf
sudo nano /etc/systemd/zram-generator.conf
Paste this:
[zram0]
zram-size = ram * 0.5
compression-algorithm = zstd
This sets zRAM to 50% of your total RAM.
You can also use compression-algorithm = lz4 for faster compression.
Reload and start zRAM
sudo systemctl daemon-reexec
sudo systemctl start systemd-zram-setup@zram0.service
Check if it's active
swapon --show
You should see /dev/zram0 as an active swap device.
Output:
root@vps:~# swapon --show
NAME TYPE SIZE USED PRIO
/dev/vda2 partition 512M 0B -2
/dev/zram0 partition 1.7G 0B 100
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS