Skip to content

Instantly share code, notes, and snippets.

@viljoviitanen
Last active December 11, 2015 05:08
Show Gist options
  • Save viljoviitanen/4550218 to your computer and use it in GitHub Desktop.
Save viljoviitanen/4550218 to your computer and use it in GitHub Desktop.
Puts a "zram" (compressed memory based) swap on a machine. Works at least in some recent debian based distros, maybe others too. Script was made for debian (raspbian) wheezy. Stuff that gets put in the zram swap usually compresses quite well
#!/bin/sh
FILE=/etc/rc.local
grep -q enable_zram $FILE && echo Zram already enabled && exit 1
#remove the exit 0 line. Hopefully it's the last line.
sed -i -e "/^exit 0/ d" $FILE
cat >>$FILE <<END
#enable_zram
modprobe zram
#a good size is about 10-20% of physical ram.
echo 52428800 > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0 -p 10
exit 0
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment