Skip to content

Instantly share code, notes, and snippets.

@sytone
Last active October 16, 2022 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sytone/0794443487ba18a46cbb to your computer and use it in GitHub Desktop.
Save sytone/0794443487ba18a46cbb to your computer and use it in GitHub Desktop.
Pi hacks
# http://raspberrypi.stackexchange.com/questions/169/how-can-i-extend-the-life-of-my-sd-card
# http://www.a-netz.de/2013/02/ramdisks-for-the-raspberry/
# http://web.archive.org/web/20140701023126/http://raspberry.pi.gw.gd/t50-Using-ZRAM.html
#zram
sudo modprobe zram zram_num_devices=1
lsmod | grep zram
Script Contents:
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: mkzswap
# Required-Start: checkfs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Compressed Ram Swap
# Description: swappapapap
### END INIT INFO
case "$1" in
start)
echo $(($(sed 's/MemTotal: *\([0-9]*\).*/\1/;q' /proc/meminfo) * 1024)) >/sys/block/zram0/disksize
mkswap /dev/zram0
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
:
/proc settings
Code:
vm.min_free_kbytes = 2048
vm.swappiness=100
vm.laptop_mode=3600
vm.overcommit_memory=1
vm.page-cluster=0
vm.vfs_cache_pressure=1
you need to add the swap on the fstab and add zram to /etc/modules
kernel modules :
Code:
# grep zram /etc/modules
zram num_devices=4
num_devices could be 1 as well .. i just like to have some spare for tests
fstab :
Code:
# grep zram /etc/fstab
/dev/zram0 none swap sw,pri=10 0 0
# Swap off
sudo dphys-swapfile swapoff
TEMP Files
1. edit /etc/default/tmpfs and set:
RAMLOCK=yes
RAMSHM=yes
RAMTMP=yes
I'd recommend the following sizes:
TMPFS_SIZE=10%VM
RUN_SIZE=10M
LOCK_SIZE=5M
SHM_SIZE=10M
TMP_SIZE=25M
2. enable additional directories using /etc/fstab
tmpfs /var/log tmpfs size=20M,defaults,noatime,mode=0755 0 0
tmpfs /var/cache/apt/archives tmpfs size=100M,defaults,noexec,nosuid,nodev,mode=0755 0 0
tmpfs /var/spool/cups tmpfs size=100M,defaults,noatime,mode=0755 0 0
tmpfs /var/spool/cups/tmp tmpfs defaults,noatime,mode=0755 0 0
3. use the script /etc/init.d/prepare-dirs to create missing directories in /var/log so that all daemons start
4. Make the script executable:
sudo chmod 755 /etc/init.d/prepare-dirs
5. Make sure that the script will be started first on boot before your daemons start:
sudo update-rc.d prepare-dirs defaults 01 99
contents of /etc/init.d/prepare-dir:
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: prepare-dirs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Required-Start:
# Required-Stop:
# Short-Description: Create needed directories on /var/log/ for tmpfs at startup
# Description: Create needed directories on /var/log/ for tmpfs at startup
### END INIT INFO
# needed Dirs
DIR[0]=/var/log/apt
DIR[1]=/var/log/fsck
DIR[2]=/var/log/lighttpd
PRM[2]="www-data.www-data"
DIR[3]=/var/log/cups
DIR[4]=/var/log/news
DIR[5]=/var/log/ntpstats
DIR[6]=/var/log/samba
DIR[7]=/var/log/lastlog
DIR[8]=/var/log/exim
DIR[9]=/var/log/watchdog
DIR[10]=/var/log/ConsoleKit
case "${1:-}" in
start)
typeset -i i=0 max=$(echo "${!DIR[*]}" | tr " " "\n" | sort -nr | head -n1)
while (( i <= max ));do
if [ -n "${DIR[$i]}" ];then
mkdir -p ${DIR[$i]}
chmod 755 ${DIR[$i]}
fi
i=i+1
done
# set rights
typeset -i i=0 max=$(echo "${!PRM[*]}" | tr " " "\n" | sort -nr | head -n1)
while (( i <= max ));do
if [ -n "${PRM[$i]}" ];then
chown -R ${PRM[$i]} ${DIR[$i]}
fi
i=i+1
done
;;
stop)
;;
restart)
;;
reload|force-reload)
;;
status)
;;
*)
echo "Usage: $SELF start"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment