diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 diff --git a/log2ram b/log2ram index 127a703..46eacd6 100755 --- a/log2ram +++ b/log2ram @@ -50,21 +50,46 @@ wait_for () { done } +createZramLogDrive () { + # Check Zram Class created + if [ ! -d '/sys/class/zram-control' ]; then + modprobe zram + RAM_DEV='0' + else + RAM_DEV=$(cat /sys/class/zram-control/hot_add) + fi + echo ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm + echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize + echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit + mke2fs -t ext4 /dev/zram${RAM_DEV} +} + case "$1" in start) [ -d $HDD_LOG/ ] || mkdir $HDD_LOG/ mount --bind $RAM_LOG/ $HDD_LOG/ mount --make-private $HDD_LOG/ + if [ "$ZL2R" = true ]; then + createZramLogDrive + fi wait_for $HDD_LOG - mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size="$SIZE" log2ram $RAM_LOG/ + if [ "$ZL2R" = true ]; then + mount -t ext4 -o nosuid,noexec,nodev,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ + else + mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/ + fi wait_for $RAM_LOG syncFromDisk ;; stop) syncToDisk + #ZRAM_LOG=$(awk '$2 == "/var/log" {print $1}' /proc/mounts) + #ZRAM_LOG=$(echo ${ZRAM_LOG} | grep -o -E '[0-9]+') umount -l $RAM_LOG/ umount -l $HDD_LOG/ + # Unsure as even with Root permision denied + #echo ${ZRAM_LOG} > /sys/class/zram-control/hot_remove ;; write) diff --git a/log2ram.conf b/log2ram.conf index 2636075..d5fbd2c 100644 --- a/log2ram.conf +++ b/log2ram.conf @@ -14,4 +14,20 @@ USE_RSYNC=false # If there are some errors with available RAM space, a system mail will be send # Change it to false and you will have only a log if there is no place on RAM anymore. -MAIL=true \ No newline at end of file +MAIL=true + +# **************** Zram backing conf ************************************************* + +# ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs +ZL2R=false +# COMP_ALG this is any compression algorithm listed in /proc/crypto +# lz4 is fastest with lightest load but deflate (zlib) and Zstandard (zstd) give far better compression ratios +# lzo is very close to lz4 and may with some binaries have better optimisation +# COMP_ALG=lz4 for speed or Zstd for compression, lzo or zlib if optimisation or availabilty is a problem +COMP_ALG=lz4 +# LOG_DISK_SIZE is the uncompressed disk size. Note zram uses about 0.1% of the size of the disk when not in use +# LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE +# lzo/lz4=2.1:1 compression ratio zlib=2.7:1 zstandard=2.9:1 +# Really a guestimate of a bit bigger than compression ratio whilst minimising 0.1% mem usage of disk size +LOG_DISK_SIZE=100M + diff --git a/uninstall.sh b/uninstall.sh old mode 100644 new mode 100755