Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

EDIT: In precise there's now zram-config. It's an upstart job compressing up to half of your ram spread over $(number of CPU cores) swap devices. It didn't allways start at boot but issuing sudo service zram-config start works.

I enabled compcache="256 M" in /etc/initramfs-tools/initramfs.conf as described here (by me :P). This - I believe - creates /dev/ramzswap0 but it is never enabled as swap. It works only after mkswap && swapon.

Then there is the module zram that creates /dev/zram. Is it something else? It works the same way but /dev/ramzswap is created from the module ramzswap.

At the end of the day I wanna have a compressed swap in ram and use the better of the two and for that I need to know how to enable it permanently in a non hackish way. How is this done?

I wrote about ramzswap in Lucid here but things have changed in Natty. You can still enable ramzswap in initramfs.conf but it doesn't get activated.

P.S.:I scanned all udev rules in /lib and/etc but found nothing of interest.

share|improve this question
up vote 2 down vote accepted

There's now a PPA that installs a proper Upstart script for enabling zram at boot-time. It chooses the correct size and number of compressed swap devices for your system.

share|improve this answer
there's also zram-config in precise now. – turbo Mar 16 '12 at 13:48
Why was it removed from Raring 13.04? – NoBugs May 20 '13 at 0:54
The PPA probably hasn't been updated. – Ryan Thompson May 20 '13 at 18:55

I was struggling with the same problem.

Today I found an excellent blog post about it.

Although "sudo start zramswap" didn't work, when I restarted my PC it solved my problem perfectly.

Try it.

share|improve this answer
That's actually the first time I even noticed that there is /etc/init/. Normally I use /etc/init.d/ for starting stuff at boot. Fascinating... – turbo Sep 6 '11 at 8:10
/etc/init/ is where Upstart init scripts live. The ones in /etc/init.d are mostly just compatibility wrappers that call the ones in /etc/init. – Ryan Thompson Mar 16 '12 at 20:17

Here's the cheap solution. Add the following line to /etc/rc.local, before the exit 0:

find /dev/ -maxdepth 1 -name 'ramzswap*' | while read dev; do
    mkswap $dev
    swapon -p 1000 $dev
share|improve this answer
for i in /dev/ramzswap*;do ... would the better solution I think. Still a tad too hackish in my book. – turbo Aug 14 '11 at 19:49

Straight from the Debian wiki. For me, this is the easiest.

First, copy and paste this code into /etc/init.d/zram

# Provides:          zram
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:      0 1 6
# Short-Description: Use compressed RAM as in-memory swap
# Description:       Use compressed RAM as in-memory swap

# Author: Antonio Galea <>
# Thanks to Przemysław Tomczyk for suggesting swapoff parallelization


MEMORY=`perl -ne'/^MemTotal:\s+(\d+)/ && print $1*1024;' < /proc/meminfo`
CPUS=`grep -c processor /proc/cpuinfo`

case "$1" in
    param=`modinfo zram|grep num_devices|cut -f2 -d:|tr -d ' '`
    modprobe zram $param=$CPUS
    for n in `seq $CPUS`; do
      i=$((n - 1))
      echo $SIZE > /sys/block/zram$i/disksize
      mkswap /dev/zram$i
      swapon /dev/zram$i -p 10
    for n in `seq $CPUS`; do
      i=$((n - 1))
      swapoff /dev/zram$i && echo "disabled disk $n of $CPUS" &
    sleep .5
    modprobe -r zram
    echo "Usage: `basename $0` (start | stop)"
    exit 1

Next, execute these two commands:

sudo chmod +x /etc/init.d/zram
sudo /etc/init.d/zram start

Finally, to add zram at startup:

sudo update-rc.d zram defaults


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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