Skip to content

Instantly share code, notes, and snippets.

@mwleeds
Created March 21, 2018 01:55
Show Gist options
  • Save mwleeds/cd55366acade820faeb1b413e387bc3f to your computer and use it in GitHub Desktop.
Save mwleeds/cd55366acade820faeb1b413e387bc3f to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script enables zram on Endless OS systems with 4 GB of memory or less,
# and attempts to do it in a way that both persists across reboots and can be
# overwritten by an OS update.
if [[ -e /dev/zram0 ]]; then
echo "zram is already enabled"
exit 0
fi
sudo ostree admin unlock --hotfix >/dev/null 2>&1
if ! grep x86-64 /usr/lib/systemd/system/eos-enable-zram.service >/dev/null; then
sudo sed -i '/ConditionArchitecture=|arm64/a ConditionArchitecture=|x86-64' /usr/lib/systemd/system/eos-enable-zram.service
sudo sed -i 's/eos-enable-zram 200/eos-enable-zram 1/' /usr/lib/systemd/system/eos-enable-zram.service
fi
if grep 1GB /usr/sbin/eos-enable-zram >/dev/null; then
sudo sed -i 's/th_kb=\$((1\*1024\*1024)) # 1GB/th_kb=\$((4\*1024\*1024)) # 4GB/' /usr/sbin/eos-enable-zram
sudo sed -i 's/echo \$1M/echo \$((\$ram_size_kb * 2))K/' /usr/sbin/eos-enable-zram
fi
sudo systemctl daemon-reload
sudo systemctl restart eos-enable-zram
echo "zram was successfully enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment