How do I enable zram and disable the swap partition?

How do I use zram instead of a swap partition to gain some speed and hard disk?

How do I configure zram to my needs?

Why do these things?

closed as too broad by David Foerster, Pilot6, muru, Eric Carvalho, Wilf Dec 26 '16 at 18:12

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


This is a guide to enable zram. Edit it the way you like it, and remove the swap partition to make Ubuntu faster.

You actually don't need to create a swap partition as Ubuntu suggests on installation. You only need a swap partition in case an application needs more physical RAM than the available.

  • For example, let's say I want to play WoW and the minimum requirement is 5 GB, but I have only 4 GB of physical RAM... not happening, not even in my dreams. That's where the system will need virtual RAM (swap) to think that you have more RAM.
  • Let's say I have 6 GB of physical RAM, 3 GB is used for active processes, and the game needs 5 GB of RAM... Will it play? Yeah, it will. Linux will cache the other processes and open WoW, but I will lose my ability to multitask smoothly and quickly. When I Alt + Tab to go to my desktop or to an other application, it will happen in a slow motion, because the system will cache WoW, retrieve the desktop or whatever application I requested from cache and move it to physical RAM which is just now free.

So we only need swap to use applications that need more physical RAM. Also we need swap when we want many active processes at the same time and the active RAM isn't enough. But swap is extremely slow; the hard disk is running 1 million times slower than RAM. What if we could swap in RAM? How? By compressing RAM. That's 1 million times faster than hard disk.

We sacrifice a very tiny amount of CPU load and a very tiny small amount of RAM to get more GB of RAM, but RAM is 1 million times faster than the hard disk, so trust me it's worth it (this is the easiest explanation for everyone to understand).


Don't create a swap partition on installation and if you already have, just boot a live session from USB stick and remove the swap partition using GParted or any other partition manager and do what you like with the extra hard disk space you just got. Then reboot (that will take time as it tries to mount a partition that's not there. Don't be scared; it will boot or I wouldn't be here writing it). When you boot open terminal and do:

sudo nano /etc/fstab 

delete the line referencing the swap partition from the file, save and reboot.

Now you boot again fast, even faster than before since you boot a partition less. So we just increased our disk size, and we gained boot time.

Enter image description here

Let's now install zram and customise it to our needs.

Open the terminal again and do:

sudo apt-get install zram-config


Open the terminal again and do:

sudo cat /etc/init/zram-config.conf

What does that file say? That zram is created on boot using the file

pre-start exec /usr/bin/init-zram-swapping

and that's exactly what we are going to edit:

sudo nano /usr/bin/init-zram-swapping

at line

totalmem=`LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/  *.*//'`
mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))

change 1024 to whatever you like. I put 512, but it can be any number, anything! It doesn't need to be in byte form 128, 512, 1024, etc. It can be anything!

Then edit the line

swapon -p 5 /dev/zram${DEVNUMBER}

and change 5 to whatever priority you want. That's your swappiness.

Enter image description here

Press Ctrl + O to save and Ctrl + X to exit.


Check your swap. Open the terminal and do

cat /proc/swaps

Enter image description here

Isn't your pc faster or what?

I came up with this idea when I made an old Android phone run fast as hell with Android 7.1.1 when the official last update it got was years ago Android 4.0 (Ice Cream Sandwich), and I needed more RAM to run newer apps, but I didn't want to lose speed. Well, OK we lose some speed , but that's nothing compared to the speed we lose when swapping to a slow hard disk, or a hard disk generally. Those with newer machines will not notice big difference, but they DO get more speed, and older machines will be happy faster again.

  • thank you very much Zanna for the corrections. i know , i'm kinda rude in general. i'm bad at formal talking. – Pavlos Theodorou Dec 26 '16 at 14:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.