#!/bin/bash # # zram-config Start zram-config # # chkconfig: 2345 08 92 # description: Starts, stops and saves zram-config # # ### BEGIN INIT INFO # Provides: zram-config # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop zram-config # Description: Start, stop and save zram-config ### END INIT INFO # http://askubuntu.com/questions/130374/ramdisk-compressed-writeable-no-swap # https://kernel.org/doc/Documentation/blockdev/zram.txt #NRDEVICES=$[$(grep ^physical\ id /proc/cpuinfo | sort -u | wc -l)*$(grep ^core\ id /proc/cpuinfo | sort -u | wc -l)] #if [ $NRDEVICES -eq 0 ]; then # NRDEVICES=$(grep -c '^processor\s*:' /proc/cpuinfo) #fi #NRDEVICES=1 case "$1" in start) if [ $(grep -c /dev/zram /proc/swaps) -gt 1 ]; then echo "Already running" >&2 exit 2 fi if [ $(lsmod | grep -c zram) -eq 0 ]; then modprobe zram ZRAMID=0 else ZRAMID=$(cat /sys/class/zram-control/hot_add) fi # echo 1 > /sys/block/zram${ZRAMID}/reset if [ -e /sys/block/zram${ZRAMID}/comp_algorithm ]; then if [ $(grep -c lz4 /sys/block/zram${ZRAMID}/comp_algorithm) -eq 1 ]; then echo lz4 > /sys/block/zram${ZRAMID}/comp_algorithm fi fi if [ -e /sys/block/zram${ZRAMID}/backing_dev ]; then if [ $(grep -v zram /proc/swaps | wc -l) -gt 1 ]; then egrep -v '(zram|Filename)' /proc/swaps | cut -d\ -f1 > /sys/block/zram${ZRAMID}/backing_dev fi fi echo $(free -k | grep -e "^Mem:" | awk '{printf("%d\n",$2*2.0)}')k > /sys/block/zram${ZRAMID}/disksize if [ -e /sys/block/zram${ZRAMID}/mem_limit ]; then echo $(free -k | grep -e "^Mem:" | awk '{printf("%d\n",$2*0.9)}')k > /sys/block/zram${ZRAMID}/mem_limit fi mkswap /dev/zram${ZRAMID} swapon -p 10 /dev/zram${ZRAMID} ;; stop) # Suppression zram # echo X > /sys/class/zram-control/hot_remove ou X=0 pour zram0 for ZRAMID in $(grep /dev/zram /proc/swaps | awk '{print $1}' | cut -c10-); do swapoff /dev/zram${ZRAMID} echo 1 > /sys/block/zram${ZRAMID}/reset echo ${ZRAMID} > /sys/class/zram-control/hot_remove done modprobe -r zram ;; esac #mke2fs -q -m 0 -b 4096 -O sparse_super -L zram /dev/zram0 #mount -o relatime,noexec,nosuid /dev/zram0 /mnt/zram #chmod 1777 /mnt/zram/ # cat /sys/block/zram0/mem_used_total # https://www.google.fr/search?q=sysem+to+ram+pivot_root&ie=utf-8&oe=utf-8&rls=org.mozilla:fr:unofficial&client=seamonkey-a&gws_rd=cr&ei=ThHLVs3WA4H9acbUtNAH#q=system+to+ram+pivot_root #http://dreamlayers.blogspot.fr/2012/10/running-linux-from-ram.html #http://unix.stackexchange.com/questions/126217/when-would-you-use-pivot-root-over-switch-root #https://wiki.gentoo.org/wiki/Zram