X
    Categories: Guides

Increasing Ram on Raspberry Pi

This is a quick little walk through what I have been doing to my raspberry pi laptop, using conky to display my computer stats, and wbar for doc, also increased the ram by using zram which compresses memory, many devices like chrome os and androids use this same method. thanks for the view!

Equipment List

Raspberry Pi 3 ► Amazon | Ebay

Software List

Raspbian Pixel ► https://www.raspberrypi.org/downloads/

Script to enable zRam for Raspberry Pi

I have created a script to enable zram on raspberry pi and will calculate the optimal amount for your raspberry pi. While it is possible to modify the script to increase the amount of ram being compressed, I would not suggest it as it will take more CPU cycles thus slowing the performance.

Download the script and copy to /usr/bin/ folder

$ sudo wget -O /usr/bin/zram.sh https://raw.githubusercontent.com/novaspirit/rpi_zram/master/zram.sh

once the script is downloaded we will need to change the permissions so it can be an executable

$ sudo chmod +x /usr/bin/zram.sh

edit /etc/rc.local file to run script on boot

$ sudo nano /etc/rc.local

add line before exit 0

$ /usr/bin/zram.sh &

 

novaspirit: Avid Thinker, Computer Programmer, Web evangelist, Hacking / Breaking expert, Problem Solver, Technology Obsessed, Gamer, 3D printing, Coffee lover!

View Comments (14)

  • Hey Nova - This does work but I have to run zram.sh ... I have checked the rc.local for typos. It just doesnt run on boot. Any ideas? Thank you sir.

    • Kyle you get this working? can you paste the script and your rc.local here? If you run "dmesg | grep zram" does it return zram: Created 4 device(s) ?

      I'm testing this on a acer aspire netbook with linux mint, raspberry pi 3 is next.

      • Same here check the script.

        #!/bin/sh -e
        #
        # rc.local
        #
        # This script is executed at the end of each multiuser runlevel.
        # Make sure that the script will "exit 0" on success or any other
        # value on error.
        #
        # In order to enable or disable this script just change the execution
        # bits.
        #
        # By default this script does nothing.

        # Print the IP address
        /usr/bin/zram.sh &
        _IP=$(hostname -I) || true
        if [ "$_IP" ]; then
        printf "My IP address is %s\n" "$_IP"
        fi

        exit 0

  • This is great! Just got a Pi myself and am in dire need for more RAM.
    However I have Arch installed on my Raspberry Pi and this tutorial is for Raspbian.
    Could you update it for us Arch users please? Thanks!

    • zram reduces rapidly performance of weak processor. So it is better to use sd card Samsung Evo plus 64 GB and swap

  • Dude, thank you. New to rpi and was desperate to increase swap/zram. This worked exactly as instructed and I can actually open multiple tabs in Chromium without an absolute meltdown. Thanks again.

  • Everything worked great until the other day. I started getting a syntax error in the .sh file.
    File "/usr/bin/zram.sh", line 2
    cores=$(nproc --all)
    ^
    SyntaxError: invalid syntax

    Any dispensable advice would be received warmly.

  • Whe I use NANO to look at /usr/bin/zram.sh, the file is blank. There's no config in there. Does anyone no the full/complete syntax so I can get zram running correctly on my PI?

  • /usr/bin/zram.sh produces this instead of what your YouTube video displays. Also, I can't seem to save your version after manually entering it and trying to save. It then says "Error writing ?usr/bin/zram.sh Permission denied" Can you help me?

    #!/bin/bash
    cores=$(nproc --all)
    modprobe zram num_devices=$cores

    swapoff -a

    totalmem=`free | grep -e "^Mem:" | awk '{print $2}'`
    mem=$(( ($totalmem / $cores)* 1024 ))

    core=0
    while [ $core -lt $cores ]; do
    echo $mem > /sys/block/zram$core/disksize
    mkswap /dev/zram$core
    swapon -p 5 /dev/zram$core
    let core=core+1
    done

    • Hi Steve,

      Sorry about the late reply. I am sure you've got it fixed by now, but if you haven't:

      You have to run this as root, alas with elevated privileges (see: sudo).

      That's it.

      Faithfully,
      -k0nsl

  • Hi. Thanks for the info on ZRAM. I have it running on various models (different memory sizes) of the new Pi4. It shows up (the Swap) in HTOP and Cronky as being double. It's working on my 1, 2 and 4mg models of my Pi4. But I followed the same instructions for my Pi3B+ and it (Swap) shows exactly the same as Memory size, 905.
    Actually it shows up as Mem and Swap as 905MB in Cronky and in htop Mem and Swp both show as 905M.

    Is there a known problem for the 3b+? The example being used here is for the 3b+ so I would think the Swap would be a different number than the Memory size.

    Any help would be appreciated.

Related Post