A Brief But Accurate Documentation, BSD Linux And Programming

 Docker

Friday, March 10, 2017

How to Create zRam on Linux

Put these on the terminal

sudo modprobe zram

and then

sudo sh -c "echo 'lz4' > /sys/block/zram0/comp_algorithm"

You can change it what you want
2G or 4G

sudo sh -c "echo '2G' > /sys/block/zram0/disksize"

sudo mkswap --label zram0 /dev/zram0

sudo swapon --priority 100 /dev/zram0

Turne on Automatically zRam swap on the startup


sudo nano /etc/systemd/system/zram.service

put this scripts

[Unit]
Description=zRam block devices swapping

[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c "modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm | echo 2G > /sys/block/zram0/disksize && mkswap --label zram0 /dev/zram0 && swapon --priority 100 /dev/zram0"
ExecStop=/usr/bin/bash -c "swapoff /dev/zram0 && rmmod zram"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

and saved it


sudo systemctl enable zram


Disable zRam block devices

Disable the zRam block devices swapping

sudo swapoff /dev/zram0

Remove the zRam module from the kernel

sudo rmmod zram

 Disable the zram.service from automatically run at startup

sudo systemctl disable zram.service

No comments:

Post a Comment

Back to top