patschi

Raspberry Pi Raspbian zram compression init.d-Script

Mar 19th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.06 KB | None | 0 0
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. #Provides: zram
  4. #Required-Start:
  5. #Required-Stop:
  6. #Default-Start: 2 3 4 5
  7. #Default-Stop: 0 1 6
  8. #Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
  9. #Description: Adapted for Raspian (Rasberry pi) by eXtremeSHOK.com using https://raw.github.com/gionn/etc/master/init.d/zram
  10. ### END INIT INFO
  11.  
  12. start() {
  13.     mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
  14.  
  15.     modprobe zram
  16.  
  17.     sleep 1
  18.     #only using 50% of system memory, comment the line below to use 100% of system memory
  19.     mem_total_kb=$((mem_total_kb/2))
  20.  
  21.     echo $((mem_total_kb * 1024)) > /sys/block/zram0/disksize
  22.  
  23.     mkswap /dev/zram0
  24.  
  25.     swapon -p 100 /dev/zram0
  26. }
  27.  
  28. stop() {
  29.     swapoff /dev/zram0
  30.     sleep 1
  31.     rmmod zram
  32. }
  33.  
  34. case "$1" in
  35.     start)
  36.         start
  37.         ;;
  38.     stop)
  39.         stop
  40.         ;;
  41.     restart)
  42.         stop
  43.         sleep 3
  44.         start
  45.         ;;
  46.     *)
  47.         echo "Usage: $0 {start|stop|restart}"
  48.         RETVAL=1
  49. esac
Advertisement
Add Comment
Please, Sign In to add comment