Skip to main content
Topic: zram-service a zram setup script - alternative to zramswap (Read 302 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

zram-service a zram setup script - alternative to zramswap

very fresh release, it only depends on the linux kernel and every thing from the shell interpreter to awk can work with busybox.

if someone was to write openrc and runit files to use this i would be glad to upstream them.


https://github.com/eylles/zram-service

Re: zram-service a zram setup script - alternative to zramswap

Reply #1
Don't use it, but it should be as simple as
Code: [Select]
#!/usr/bin/openrc-run
# Copyright 2024 Artix Linux developers

description="zram service"
command="/usr/sbin/zram.sh"
command_args="activate"

stop() {
ebegin "Stopping zram"
/usr/sbin/zram.sh deactivate
eend $?
}

Re: zram-service a zram setup script - alternative to zramswap

Reply #2
I'm building my zRAM-Swap in /etc/rc.local (Xfce-Runit):
Code: [Select]
#!/bin/sh
modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm && echo $(($(grep 'MemTotal:' /proc/meminfo|awk '{print $2}')*1/1))K > /sys/block/zram0/disksize && mkswap -qU clear /dev/zram0 && swapon -p100 /dev/zram0
exit 0

For zRAM-Disk I wrote two Scripts and put them in the path:
"mkzram":
Code: [Select]
#!/bin/bash
if [ $# == 0 ];then echo "mkzram [Size in G] [zstd] (standard: lz4)";exit;fi
al=lz4
if [ $2 == "zstd" ] 2>/dev/null;then al=zstd;fi
if [ ! -e /dev/zram* ] 2>/dev/null
then sudo modprobe zram;id=0
else id=$(sudo cat /sys/class/zram-control/hot_add)
fi
echo $al|sudo tee /sys/block/zram$id/comp_algorithm >/dev/null
echo $1"G"|sudo tee /sys/block/zram$id/disksize >/dev/null
sudo mkfs.xfs -Kqmcrc=0 /dev/zram$id >/dev/null && mkdir /tmp/zram$id
sudo mount -o discard /dev/zram$id /tmp/zram$id/ && sudo chmod 777 /tmp/zram$id/
zramctl -o name,algorithm,disksize,data,compr,mountpoint
"rmzram":
Code: [Select]
#!/bin/bash
if [ $# == 0 ];then echo -e "rmzram [ID]:\n";zramctl -o name,algorithm,disksize,data,compr,mountpoint;exit;fi
sudo umount -l /tmp/zram$1/ && rm -rf /tmp/zram$1
echo $1|sudo tee /sys/class/zram-control/hot_remove > /dev/null
if [ ! -e /dev/zram* ] 2>/dev/null;then sudo modprobe -r zram;fi
zramctl -o name,algorithm,disksize,data,compr,mountpoint

Example:
Code: [Select]
$ mkzram 12
[sudo] Passwort für user:
NAME       ALGORITHM DISKSIZE  DATA COMPR MOUNTPOINT
/dev/zram0 lz4          31,3G    4K   44B [SWAP]
/dev/zram1 lz4            12G  2,3M 53,4K /tmp/zram1

$ mkzram 8 zstd
NAME       ALGORITHM DISKSIZE  DATA COMPR MOUNTPOINT
/dev/zram0 lz4          31,3G    4K   44B [SWAP]
/dev/zram1 lz4            12G  2,3M 53,4K /tmp/zram1
/dev/zram2 zstd            8G  2,3M 45,2K /tmp/zram2

$ rmzram
rmzram [ID]:

NAME       ALGORITHM DISKSIZE  DATA COMPR MOUNTPOINT
/dev/zram0 lz4          31,3G    4K   44B [SWAP]
/dev/zram1 lz4            12G  2,3M 53,4K /tmp/zram1
/dev/zram2 zstd            8G  2,3M 45,2K /tmp/zram2

$ rmzram 1
NAME       ALGORITHM DISKSIZE  DATA COMPR MOUNTPOINT
/dev/zram0 lz4          31,3G    4K   44B [SWAP]
/dev/zram2 zstd            8G  2,3M 45,2K /tmp/zram2

$ rmzram 2
NAME       ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4          31,3G   4K   44B [SWAP]

Re: zram-service a zram setup script - alternative to zramswap

Reply #3
nice, i want to keep developing my zram script to do at least 80% or so of what the rust-zram-generator does, as in have the ability to set multiple zram devices for swap and disk, also specify writeback devices, but is not so easy to achieve that in a fully init agonistic way and limited to just a posix shell interpreter and core utils that can be provided by busybox, it takes time and doesn't help that i got no idea how to do stuff for runit, openrc and s6 as for about the last 10 or so years i committed sysvinit to heart...