Switch logic. logrotate is active at /var/log.hdd if we use it. Compression happens only there. Truncate script (if /var/log is over 75%) saves logs, run logrotate on log.hdd and truncate logs. ZRAM partition was switched back to EXT4 since there are many troubles with older kernels. Image size was reduced due to lack of swap creation.

This commit is contained in:
Igor Pečovnik 2018-06-17 11:52:15 +00:00
parent 09b313f860
commit 75e17b0e21
6 changed files with 26 additions and 33 deletions

View file

@ -344,13 +344,12 @@ prepare_partitions()
local sdsize=$(bc -l <<< "scale=0; (($imagesize * 0.8) / 4 + 1) * 4")
;;
*)
# Hardcoded overhead +40% and +128MB for ext4 is needed for desktop images,
# for CLI it could be lower. Also add extra 128 MiB for the emergency swap
# file creation and align the size up to 4MiB
# Hardcoded overhead +25% is needed for desktop images,
# for CLI it could be lower. Align the size up to 4MiB
if [[ $BUILD_DESKTOP == yes ]]; then
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.4) / 1 + 128) / 4 + 1) * 4")
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.25) / 1 + 0) / 4 + 1) * 4")
else
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.2) / 1 + 128) / 4 + 1) * 4")
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.15) / 1 + 0) / 4 + 1) * 4")
fi
;;
esac

View file

@ -4,5 +4,4 @@
ENABLED=true
#
# size of the partition for ramlog in megabytes
# 50 is minimum allowed size for BTRFS partition
SIZE=50

View file

@ -41,22 +41,19 @@ set_io_scheduler() {
prepare_board() {
# prevent logrotate from compressing rotated logs when /var/log lives on compressed fs
CheckDevice=$(for i in /var/log /var / ; do findmnt -n -o SOURCE $i && break ; done)
#[ -n "${CheckDevice}" ] && grep "^${CheckDevice}" /etc/mtab | grep -q compress && \
# need better implemenation, now fixed to our zram0
[[ "${CheckDevice}" == "/dev/zram0" ]] &&
for ConfigFile in /etc/logrotate.d/* ; do
sed -i -e "s/^\s\+compress/\t# compress/" \
-e "s/^\s\+delaycompress/\t# delaycompress/" "${ConfigFile}"
done
# adjust logrotate configs
if [[ "${CheckDevice}" == "/dev/zram0" || "${CheckDevice}" == "armbian-ramlog" ]]; then
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/log\//log.hdd\//" "${ConfigFile}"; done
sed -i "s/log\//log.hdd\//" /etc/logrotate.conf
else
for ConfigFile in /etc/logrotate.d/* ; do sed -i -e "s/log.hdd\//log\//" "${ConfigFile}"; done
sed -i "s/log.hdd\//log\//" /etc/logrotate.conf
fi
# remove compression from general config
sed -i 's/^compress/#compress/' /etc/logrotate.conf
# fix permissions in all logrotate configs
find /etc/logrotate.d/. -type f | xargs grep -H -c 'su root' | grep 0$ | cut -d':' -f1 | \
xargs -L1 sed -i '/{/ a su root syslog' 2> /dev/null
# enable compression where not exists
find /etc/logrotate.d/. -type f | xargs grep -H -c 'compress' | grep 0$ | cut -d':' -f1 | xargs -L1 sed -i '/{/ a compress'
sed -i "s/#compress/compress/" /etc/logrotate.conf
# tweak ondemand cpufreq governor settings to increase cpufreq with IO load
grep -q ondemand /etc/default/cpufrequtils

View file

@ -55,12 +55,9 @@ case "$1" in
mount --make-private $HDD_LOG
rm -f $LOG2RAM_LOG
# zram type
if [ "$(blkid -s TYPE /dev/zram0 | awk ' { print $2 } ' | grep btrfs)" ]; then
if [ "$(blkid -s TYPE /dev/zram0 | awk ' { print $2 } ' | grep ext4)" ]; then
mount /dev/zram0 $RAM_LOG | $LOG_OUTPUT
# workaround for older kernel/btrfs driver versions
if [ $? -eq 1 ]; then mkfs.btrfs -f -O ^extref -s 1024 -L armbian-ramlog /dev/zram0; mount /dev/zram0 $RAM_LOG | $LOG_OUTPUT; fi
else
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE armbian-ramlog $RAM_LOG | $LOG_OUTPUT
fi
syncFromDisk
@ -79,4 +76,4 @@ case "$1" in
echo "Usage: log2ram {start|stop|write}" >&2
exit 1
;;
esac
esac

View file

@ -12,14 +12,15 @@
treshold=75 # %
logusage=$(df /var/log/ --output=pcent | tail -1 |cut -d "%" -f 1)
if [ $logusage -ge $treshold ]; then
logrotate --force /etc/logrotate.d/
# write to SD
/usr/sbin/armbian/armbian-ram-logging write >/dev/null 2>&1
/usr/sbin/armbian/armbian-ramlog write >/dev/null 2>&1
# rotate logs on "disk"
chown root.root -R /var/log.hdd
logrotate --force /etc/logrotate.d/
# truncate
/usr/bin/find /var/log -name '*.log' -or -name '*.xz' -or -name 'lastlog' -or -name 'messages' -or -name 'debug' -or -name 'syslog' | xargs truncate --size 0
/usr/bin/find /var/log -name 'btmp' -or -name 'wtmp' | xargs truncate --size 0
/usr/bin/find /var/log -name '*.log' -or -name '*.xz' -or -name 'lastlog' -or -name 'messages' -or -name 'debug' -or -name 'syslog' | xargs truncate --size 0
/usr/bin/find /var/log -name 'btmp' -or -name 'wtmp' -or -name 'faillog' | xargs truncate --size 0
# remove
/usr/bin/find /var/log -name '*.[0-9]' -or -name '*.gz' | xargs rm
/usr/bin/find /var/log -name '*.[0-9]' -or -name '*.gz' | xargs rm >/dev/null 2>&1
fi
fi

View file

@ -50,7 +50,7 @@ activate_zram() {
echo ${algo} >/sys/block/zram0/comp_algorithm 2>/dev/null
done
echo -n $(($SIZE*1024*1024)) > /sys/block/zram0/disksize
mkfs.btrfs -s 1024 -L log2ram /dev/zram0
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/zram0
read algo </sys/block/zram0/comp_algorithm
echo -e "### Activated Armbian ramlog partition with ${algo} compression\n" >>${Log}
} # activate_zram