Skip to content

Instantly share code, notes, and snippets.

@bwDraco
Created March 13, 2019 21:25
Show Gist options
  • Save bwDraco/a033ee5935bdcbfb57a5f64dacc6196c to your computer and use it in GitHub Desktop.
Save bwDraco/a033ee5935bdcbfb57a5f64dacc6196c to your computer and use it in GitHub Desktop.
Simple systemd service to automate turning zram swap on and off
#!/bin/sh
set -e
swapoff /dev/zram0
echo 1 > /sys/block/zram0/reset
#!/bin/sh
set -e
modprobe -v zram
echo 1G > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -d /dev/zram0
[Unit]
Description=Compressed Memory Swap
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/zramswap-on.sh
ExecStop=/usr/local/sbin/zramswap-off.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment