From 26396f5b8c84784c1e59b71b29f1fb9639ee5e5d Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Tue, 9 Apr 2019 23:44:24 +0100 Subject: [PATCH 1/5] journal + mount tune --- log2ram | 29 +++++++++++++++++------------ log2ram.conf | 6 +++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/log2ram b/log2ram index 1f60ef3..c80f583 100755 --- a/log2ram +++ b/log2ram @@ -52,8 +52,7 @@ wait_for () { createZramLogDrive () { # Check Zram Class created - if [ ! -d "/sys/class/zram-control" ]; then - modprobe zram + if modprobe --first-time --verbose zram; then RAM_DEV='0' else 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 ${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} + 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 @@ -70,25 +70,30 @@ case "$1" in mount --bind $RAM_LOG/ $HDD_LOG/ mount --make-private $HDD_LOG/ wait_for $HDD_LOG - if [ "$ZL2R" = true ]; then + if [ "$ZL2R" = true ]; then 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/ - fi + 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 - ;; + 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) syncToDisk diff --git a/log2ram.conf b/log2ram.conf index d5fbd2c..3030bbf 100644 --- a/log2ram.conf +++ b/log2ram.conf @@ -5,7 +5,7 @@ # 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. # 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". # 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 ************************************************* # 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 # 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 @@ -29,5 +29,5 @@ COMP_ALG=lz4 # 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 +LOG_DISK_SIZE=60M From 8d2d03517f1522c06316b7404494b0053e5f3b11 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Tue, 9 Apr 2019 23:52:22 +0100 Subject: [PATCH 2/5] add olddir to persistant --- install.sh | 2 +- log2ram.logrotate | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 62e8742..cc1e24d 100755 --- a/install.sh +++ b/install.sh @@ -13,7 +13,7 @@ systemctl enable log2ram # cron install -m 755 log2ram.hourly /etc/cron.hourly/log2ram -install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram +install -m 644 log2ram.logrotate /etc/logrotate.d/00_log2ram # Remove a previous log2ram version rm -rf /var/log.hdd diff --git a/log2ram.logrotate b/log2ram.logrotate index dbe9914..3425f4d 100644 --- a/log2ram.logrotate +++ b/log2ram.logrotate @@ -1,3 +1,19 @@ +# These settings will save the rotated logfiles to a seperate location. +# This file needs to be located in /etc/logrotate.d. +# The "00" prefix in the file name is required to ensure this file is +# loaded before any program specific logrotate settings are loaded as +# contents of /etc/logrotate.d are read in alphabetical order. + +# The path & name for rotated logfiles folder. +olddir /var/log.old + +# Create the path if it doesn't exist +createolddir 755 root root + +# To allow the files to be "moved" (ie copied and original deleted) +# to another device/partition (eg out of RAM) +renamecopy + /var/log/log2ram.log { rotate 7 @@ -7,4 +23,3 @@ delaycompress compress } - From 658f5329efa6c3329bc640ac45ec2f351a9d0768 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Wed, 10 Apr 2019 00:13:31 +0100 Subject: [PATCH 3/5] rsyslog & journalctl examples --- log2ram | 3 +++ 1 file changed, 3 insertions(+) diff --git a/log2ram b/log2ram index c80f583..00031ef 100755 --- a/log2ram +++ b/log2ram @@ -82,6 +82,7 @@ case "$1" in stop) syncToDisk + invoke-rc.d rsyslog stop umount -l $RAM_LOG/ umount -l $HDD_LOG/ if [ "$ZL2R" = true ]; then @@ -93,6 +94,8 @@ case "$1" in echo "$RAM_DEV" > /sys/class/zram-control/hot_remove fi fi + invoke-rc.d rsyslog restart + journalctl --flush ;; write) From cb07cf6acab75bfa2e2c06a87cb063dc43c3fe6b Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Wed, 10 Apr 2019 00:33:41 +0100 Subject: [PATCH 4/5] logrotate change --- log2ram | 7 ++++--- uninstall.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/log2ram b/log2ram index 00031ef..344f4b2 100755 --- a/log2ram +++ b/log2ram @@ -83,15 +83,16 @@ case "$1" in stop) syncToDisk invoke-rc.d rsyslog stop + L2G_DEV=$(df /var/log | tail -1 | awk '{ print $1 }' | tr -dc '0-9') umount -l $RAM_LOG/ umount -l $HDD_LOG/ if [ "$ZL2R" = true ]; then RAM_DEV=$(cat /sys/class/zram-control/hot_add) if [ "$RAM_DEV" -eq "1" ];then + echo "$L2G_DEV" > /sys/class/zram-control/hot_remove 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 + else + echo "$L2G_DEV" > /sys/class/zram-control/hot_remove fi fi invoke-rc.d rsyslog restart diff --git a/uninstall.sh b/uninstall.sh index 7a82692..f21169e 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -8,7 +8,7 @@ then rm /usr/local/bin/log2ram rm /etc/log2ram.conf rm /etc/cron.hourly/log2ram - rm /etc/logrotate.d/log2ram + rm /etc/logrotate.d/00_log2ram if [ -d /var/hdd.log ]; then rm -r /var/hdd.log From bb1b54ec92a5c2f5809425361393bca7de5ae3c0 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Wed, 10 Apr 2019 00:35:14 +0100 Subject: [PATCH 5/5] logrotate change --- log2ram.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log2ram.conf b/log2ram.conf index 3030bbf..198c517 100644 --- a/log2ram.conf +++ b/log2ram.conf @@ -5,7 +5,7 @@ # 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. # You will need to increase it if you have a server and a lot of log for example. -SIZE=20M +SIZE=40M # 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. @@ -19,7 +19,7 @@ MAIL=true # **************** Zram backing conf ************************************************* # ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs -ZL2R=true +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