Last active
July 14, 2016 21:32
-
-
Save mshuler/55ce48a349e2642151484ac30bb60b6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### BEGIN INIT INFO | |
# Provides: zram-disk | |
# Required-Start: $local_fs | |
# Required-Stop: $local_fs | |
# Default-Start: S | |
# Default-Stop: 0 1 6 | |
# Short-Description: Use compressed RAM as in-memory filesystem | |
# Description: Use compressed RAM as in-memory filesystem | |
### END INIT INFO | |
| |
# Author: Antonio Galea <[email protected]> | |
# Thanks to Przemysław Tomczyk for suggesting swapoff parallelization | |
| |
NAME=zram-disk | |
| |
FRACTION=50 | |
MOUNTPOINT=/ramdisk | |
PERMISSIONS=777 | |
| |
#READ from config file if exists | |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
| |
| |
| |
MEMORY=`grep ^MemTotal /proc/meminfo | awk '{print $2}'` | |
SIZE=$(( MEMORY * 1024 * FRACTION / 100 )) | |
| |
case "$1" in | |
"start") | |
modprobe zram | |
echo $SIZE > /sys/block/zram0/disksize | |
mkfs.ext3 /dev/zram0 | |
mkdir -p $MOUNTPOINT | |
mount /dev/zram0 $MOUNTPOINT | |
chmod $PERMISSIONS $MOUNTPOINT | |
;; | |
"stop") | |
umount $MOUNTPOINT | |
wait | |
sleep .5 | |
modprobe -r zram | |
;; | |
*) | |
echo "Usage: `basename $0` (start | stop)" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment