@@ -52,8 +52,7 @@ wait_for () { | |||||
createZramLogDrive () { | createZramLogDrive () { | ||||
# Check Zram Class created | # Check Zram Class created | ||||
if [ ! -d "/sys/class/zram-control" ]; then | |||||
modprobe zram | |||||
if modprobe --first-time --verbose zram; then | |||||
RAM_DEV='0' | RAM_DEV='0' | ||||
else | else | ||||
RAM_DEV=$(cat /sys/class/zram-control/hot_add) | RAM_DEV=$(cat /sys/class/zram-control/hot_add) | ||||
@@ -61,7 +60,8 @@ createZramLogDrive () { | |||||
echo ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm | echo ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm | ||||
echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize | echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize | ||||
echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit | echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit | ||||
mke2fs -t ext4 /dev/zram${RAM_DEV} | |||||
mke2fs -v -t ext4 -O ^has_journal -s 1024 -L log2ram$RAM_DEV /dev/zram${RAM_DEV} | |||||
tune2fs -o journal_data_writeback /dev/zram${RAM_DEV} | |||||
} | } | ||||
case "$1" in | case "$1" in | ||||
@@ -70,25 +70,30 @@ case "$1" in | |||||
mount --bind $RAM_LOG/ $HDD_LOG/ | mount --bind $RAM_LOG/ $HDD_LOG/ | ||||
mount --make-private $HDD_LOG/ | mount --make-private $HDD_LOG/ | ||||
wait_for $HDD_LOG | wait_for $HDD_LOG | ||||
if [ "$ZL2R" = true ]; then | |||||
if [ "$ZL2R" = true ]; then | |||||
createZramLogDrive | createZramLogDrive | ||||
mount -t ext4 -o nosuid,noexec,nodev,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ | |||||
else | |||||
mount -t ext4 -o nosuid,noexec,nodev,discard,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ | |||||
else | |||||
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/ | mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/ | ||||
fi | |||||
fi | |||||
wait_for $RAM_LOG | wait_for $RAM_LOG | ||||
syncFromDisk | syncFromDisk | ||||
;; | ;; | ||||
stop) | stop) | ||||
syncToDisk | 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 $RAM_LOG/ | ||||
umount -l $HDD_LOG/ | umount -l $HDD_LOG/ | ||||
# Unsure as even with Root permision denied | |||||
#echo ${ZRAM_LOG} > /sys/class/zram-control/hot_remove | |||||
;; | |||||
if [ "$ZL2R" = true ]; then | |||||
RAM_DEV=$(cat /sys/class/zram-control/hot_add) | |||||
if [ "$RAM_DEV" -eq "1" ];then | |||||
rmod zram | |||||
else | |||||
RAM_DEV=$(df /var/log | tail -1 | awk '{ print $1 }' | tr -dc '0-9') | |||||
echo "$RAM_DEV" > /sys/class/zram-control/hot_remove | |||||
fi | |||||
fi | |||||
;; | |||||
write) | write) | ||||
syncToDisk | syncToDisk | ||||
@@ -5,7 +5,7 @@ | |||||
# If it's not enough, log2ram will not be able to use ram. Check you /var/log size folder. | # If it's not enough, log2ram will not be able to use ram. Check you /var/log size folder. | ||||
# The default is 40M and is basically enough for a lot of applications. | # The default is 40M and is basically enough for a lot of applications. | ||||
# You will need to increase it if you have a server and a lot of log for example. | # You will need to increase it if you have a server and a lot of log for example. | ||||
SIZE=40M | |||||
SIZE=20M | |||||
# This variable can be set to true if you prefer "rsync" rather than "cp". | # This variable can be set to true if you prefer "rsync" rather than "cp". | ||||
# I use the command cp -u and rsync -X, so I don't copy the all folder every time for optimization. | # I use the command cp -u and rsync -X, so I don't copy the all folder every time for optimization. | ||||
@@ -19,7 +19,7 @@ MAIL=true | |||||
# **************** Zram backing conf ************************************************* | # **************** Zram backing conf ************************************************* | ||||
# ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs | # ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs | ||||
ZL2R=false | |||||
ZL2R=true | |||||
# COMP_ALG this is any compression algorithm listed in /proc/crypto | # 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 | # 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 | # lzo is very close to lz4 and may with some binaries have better optimisation | ||||
@@ -29,5 +29,5 @@ COMP_ALG=lz4 | |||||
# LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE | # 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 | # 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 | # Really a guestimate of a bit bigger than compression ratio whilst minimising 0.1% mem usage of disk size | ||||
LOG_DISK_SIZE=100M | |||||
LOG_DISK_SIZE=60M | |||||